import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useContext } from "react";
import { withFixedStyle } from "./colHOC";
import { Tooltip } from "../tooltip/tooltip";
import { cn } from "..";
import { HoverCard } from "../hoverCard";
import { TableContext } from "./tableContext";
import { ArrowIcon } from "../icon/icons/arrow";
const TheadColItem = (props)=>{
    const { col: column, index } = props;
    const { sortKey, sortOrder, onSort } = useContext(TableContext);
    let content = column.title;
    if (!!column.hint || !!column.onSort) {
        content = /*#__PURE__*/ _jsxs("button", {
            className: cn("hover:orderly-text-base-contrast orderly-flex orderly-gap-1 orderly-items-center", sortKey === column.dataIndex && "orderly-text-base-contrast"),
            onClick: (e)=>{
                e.stopPropagation();
                if (!column.onSort) {
                    return;
                }
                onSort(column.dataIndex);
            },
            children: [
                /*#__PURE__*/ _jsx("span", {
                    children: column.title
                }),
                /*#__PURE__*/ _jsx(ArrowIcon, {
                    className: cn("orderly-transition-all orderly-duration-200 orderly-hidden", sortKey === column.dataIndex && "orderly-block", sortOrder === "asc" && "orderly-rotate-180", sortOrder === "desc" && "orderly-rotate-0"),
                    size: 10
                })
            ]
        });
    }
    if (!!column.hint) {
        if (typeof column.hint === "string") {
            content = /*#__PURE__*/ _jsx(Tooltip, {
                content: column.hint,
                className: cn("orderly-max-w-[270px] orderly-text-4xs", column.hintClassName && column.hintClassName),
                children: content
            });
        } else {
            content = /*#__PURE__*/ _jsx(HoverCard, {
                // @ts-ignore
                content: column.hint,
                side: "top",
                align: "center",
                className: cn("orderly-max-w-[270px] orderly-text-4xs", column.hintClassName && column.hintClassName),
                children: content
            });
        }
    }
    return /*#__PURE__*/ _jsx("td", {
        className: cn("orderly-px-1 orderly-py-[3px] ", column.align === "right" && "orderly-text-right", props.justified && "first:orderly-pl-0 last:orderly-pr-0", props.bordered && "orderly-border-b orderly-border-divider", column.fixed && "orderly-sticky orderly-bg-base-900", props.className),
        style: props.style,
        children: content
    }, column.dataIndex);
};
export const TheadCol = withFixedStyle(TheadColItem);

//# sourceMappingURL=theadCol.js.map