"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "TheadCol", {
    enumerable: true,
    get: function() {
        return TheadCol;
    }
});
const _jsxruntime = require("react/jsx-runtime");
const _react = require("react");
const _colHOC = require("./colHOC");
const _tooltip = require("../tooltip/tooltip");
const _ = require("..");
const _hoverCard = require("../hoverCard");
const _tableContext = require("./tableContext");
const _arrow = require("../icon/icons/arrow");
const TheadColItem = (props)=>{
    const { col: column, index } = props;
    const { sortKey, sortOrder, onSort } = (0, _react.useContext)(_tableContext.TableContext);
    let content = column.title;
    if (!!column.hint || !!column.onSort) {
        content = /*#__PURE__*/ (0, _jsxruntime.jsxs)("button", {
            className: (0, _.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__*/ (0, _jsxruntime.jsx)("span", {
                    children: column.title
                }),
                /*#__PURE__*/ (0, _jsxruntime.jsx)(_arrow.ArrowIcon, {
                    className: (0, _.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__*/ (0, _jsxruntime.jsx)(_tooltip.Tooltip, {
                content: column.hint,
                className: (0, _.cn)("orderly-max-w-[270px] orderly-text-4xs", column.hintClassName && column.hintClassName),
                children: content
            });
        } else {
            content = /*#__PURE__*/ (0, _jsxruntime.jsx)(_hoverCard.HoverCard, {
                // @ts-ignore
                content: column.hint,
                side: "top",
                align: "center",
                className: (0, _.cn)("orderly-max-w-[270px] orderly-text-4xs", column.hintClassName && column.hintClassName),
                children: content
            });
        }
    }
    return /*#__PURE__*/ (0, _jsxruntime.jsx)("td", {
        className: (0, _.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);
};
const TheadCol = (0, _colHOC.withFixedStyle)(TheadColItem);

//# sourceMappingURL=theadCol.js.map