import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useMemo } from 'react';
import { SortDownFillSm } from '../../../icons/SortDownFillSm';
import { SortFillSm } from '../../../icons/SortFillSm';
import { SortUpFillSm } from '../../../icons/SortUpFillSm';
import { OverflowTypography } from '../../OverflowTypography';
import { classNames } from '../../utils/classNames';
import { cva } from '../../utils/cva';
import { headCellClassnames } from './constants';
import { Wrapper } from './styles';
import { useLogic } from './useLogic';
const headCellCva = cva(headCellClassnames.root, {
    variants: {
        isSortable: {
            true: headCellClassnames.sortable,
        },
        align: {
            left: headCellClassnames.alignLeft,
            center: headCellClassnames.alignCenter,
            right: headCellClassnames.alignRight,
        },
        hasStartAdornment: {
            true: headCellClassnames.hasStartAdornment,
        },
    },
});
export const HeadCell = (props) => {
    const { hasStartAdornment, handleSortClick, headCellCssVars } = useLogic(props);
    const { startAdornment, field, isSortable, align, label, sorting, className, } = props;
    const sortIcon = useMemo(() => {
        if (!isSortable) {
            return null;
        }
        if (sorting?.fieldId !== field) {
            return _jsx(SortFillSm, {});
        }
        switch (sorting?.sort) {
            case 'asc':
                return _jsx(SortUpFillSm, { color: "primary" });
            case 'desc':
                return _jsx(SortDownFillSm, { color: "primary" });
            default:
                return _jsx(SortFillSm, {});
        }
    }, [sorting, isSortable, field]);
    return (_jsxs(Wrapper, { onClick: handleSortClick, className: classNames(className, headCellCva({ isSortable, align, hasStartAdornment })), style: headCellCssVars, children: [startAdornment && startAdornment, _jsx(OverflowTypography, { rowsCount: 2, variant: "pointer", component: "p", children: label }), sortIcon] }));
};
