"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
function _export(target, all) {
    for(var name in all)Object.defineProperty(target, name, {
        enumerable: true,
        get: Object.getOwnPropertyDescriptor(all, name).get
    });
}
_export(exports, {
    get HeadCell () {
        return HeadCell;
    },
    get getIconSize () {
        return getIconSize;
    }
});
const _reacttable = require("@tanstack/react-table");
const _react = /*#__PURE__*/ _interop_require_default(require("react"));
const _Tablestyles = require("../../Table.styles");
const _Icon = require("../../../_Icon");
const _utils = require("../../utils");
const _Tabletokens = require("../../Table.tokens");
const _HeadCellstyles = require("./HeadCell.styles");
const _Filter = require("./ui/Filter/Filter");
function _interop_require_default(obj) {
    return obj && obj.__esModule ? obj : {
        default: obj
    };
}
const getIconSize = (size)=>{
    return size === 's' ? 'xs' : 's';
};
const HeadCell = ({ header, size, borderVariant, outerFiltered, tableContainerRef, className })=>{
    const { filters } = header?.column?.columnDef?.meta || {};
    return /*#__PURE__*/ _react.default.createElement(_Tablestyles.Th, {
        key: header.id,
        colSpan: header.colSpan,
        borderVariant: borderVariant,
        selectionCell: header.column.id === _utils.SELECT_COLUMN_ID,
        style: header.column.id !== _utils.SELECT_COLUMN_ID ? {
            width: header.getSize()
        } : undefined,
        className: className
    }, header.isPlaceholder ? null : /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/ _react.default.createElement(_HeadCellstyles.ThWrapper, null, (0, _reacttable.flexRender)(header.column.columnDef.header, header.getContext()), header.column.id !== _utils.SELECT_COLUMN_ID && /*#__PURE__*/ _react.default.createElement(_HeadCellstyles.ControlButtons, null, filters && /*#__PURE__*/ _react.default.createElement(_Filter.Filter, {
        header: header,
        size: size,
        outerFiltered: outerFiltered,
        tableContainerRef: tableContainerRef
    }), header.column.getCanSort() && /*#__PURE__*/ _react.default.createElement(_HeadCellstyles.IconWrapper, {
        onClick: header.column.getToggleSortingHandler()
    }, {
        asc: /*#__PURE__*/ _react.default.createElement(_Icon.IconArrowUp, {
            size: getIconSize(size),
            className: _Tabletokens.classes.sortingAscIcon
        }),
        desc: /*#__PURE__*/ _react.default.createElement(_Icon.IconArrowDown, {
            size: getIconSize(size),
            className: _Tabletokens.classes.sortingDescIcon
        })
    }[header.column.getIsSorted()] ?? /*#__PURE__*/ _react.default.createElement(_Icon.IconSwapVert, {
        size: getIconSize(size),
        className: _Tabletokens.classes.sortingDefaultIcon
    }))))), header.column.getCanResize() && /*#__PURE__*/ _react.default.createElement(_Tablestyles.Resizer, {
        className: _Tabletokens.classes.resizeDivider,
        onMouseDown: header.getResizeHandler(),
        onTouchStart: header.getResizeHandler(),
        isResizing: header.column.getIsResizing()
    }));
};
