import { flexRender } from "@tanstack/react-table";
import React from "react";
import { Th, Resizer } from "../../Table.styles";
import { IconSwapVert, IconArrowDown, IconArrowUp } from "../../../_Icon";
import { SELECT_COLUMN_ID } from "../../utils";
import { classes } from "../../Table.tokens";
import { ControlButtons, ThWrapper, IconWrapper } from "./HeadCell.styles";
import { Filter } from "./ui/Filter/Filter";
export var getIconSize = function getIconSize(size) {
    return size === 's' ? 'xs' : 's';
};
export var HeadCell = function HeadCell(param) {
    var header = param.header, size = param.size, borderVariant = param.borderVariant, outerFiltered = param.outerFiltered, tableContainerRef = param.tableContainerRef, className = param.className;
    var _header_column_getIsSorted;
    var _header_column_columnDef, _header_column;
    var filters = ((header === null || header === void 0 ? void 0 : (_header_column = header.column) === null || _header_column === void 0 ? void 0 : (_header_column_columnDef = _header_column.columnDef) === null || _header_column_columnDef === void 0 ? void 0 : _header_column_columnDef.meta) || {}).filters;
    return /*#__PURE__*/ React.createElement(Th, {
        key: header.id,
        colSpan: header.colSpan,
        borderVariant: borderVariant,
        selectionCell: header.column.id === SELECT_COLUMN_ID,
        style: header.column.id !== SELECT_COLUMN_ID ? {
            width: header.getSize()
        } : undefined,
        className: className
    }, header.isPlaceholder ? null : /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(ThWrapper, null, flexRender(header.column.columnDef.header, header.getContext()), header.column.id !== SELECT_COLUMN_ID && /*#__PURE__*/ React.createElement(ControlButtons, null, filters && /*#__PURE__*/ React.createElement(Filter, {
        header: header,
        size: size,
        outerFiltered: outerFiltered,
        tableContainerRef: tableContainerRef
    }), header.column.getCanSort() && /*#__PURE__*/ React.createElement(IconWrapper, {
        onClick: header.column.getToggleSortingHandler()
    }, (_header_column_getIsSorted = ({
        asc: /*#__PURE__*/ React.createElement(IconArrowUp, {
            size: getIconSize(size),
            className: classes.sortingAscIcon
        }),
        desc: /*#__PURE__*/ React.createElement(IconArrowDown, {
            size: getIconSize(size),
            className: classes.sortingDescIcon
        })
    })[header.column.getIsSorted()]) !== null && _header_column_getIsSorted !== void 0 ? _header_column_getIsSorted : /*#__PURE__*/ React.createElement(IconSwapVert, {
        size: getIconSize(size),
        className: classes.sortingDefaultIcon
    }))))), header.column.getCanResize() && /*#__PURE__*/ React.createElement(Resizer, {
        className: classes.resizeDivider,
        onMouseDown: header.getResizeHandler(),
        onTouchStart: header.getResizeHandler(),
        isResizing: header.column.getIsResizing()
    }));
};
