import { jsx as C } from "react/jsx-runtime";
import { useCallback as c, useMemo as u } from "react";
import { ASCENDING as S, DESCENDING as d } from "../../constants/tableState.js";
import A from "../../hooks/useDataTableStaticContext.js";
import w from "../../hooks/useDataTableDynamicContext.js";
import a from "../../../jtl-dropdown/types/DropdownItem.js";
import i from "../../enums/ColumnActionEnum.js";
import E from "../../../jtl-dropdown/JTLDropdown.js";
import T from "../../../button/Button.js";
const K = ({ column: e }) => {
  const { columnAction: o } = A(), { setSorting: n, sorting: t, handleAutoResize: l, handleAutoResizeAll: p } = w(), r = c(
    (y) => {
      var b;
      e != null && e.key && ((b = o == null ? void 0 : o.onClick) == null || b.call(o, { key: e.key, action: y }));
    },
    [e == null ? void 0 : e.key, o]
  ), k = c(
    (y) => {
      e != null && e.key && (y === (t == null ? void 0 : t.direction) && e.key === (t == null ? void 0 : t.columnKey) ? n == null || n(void 0) : n == null || n({ columnKey: e.key, direction: y }));
    },
    [e, n, t]
  ), D = (t == null ? void 0 : t.columnKey) === (e == null ? void 0 : e.key), f = D && (t == null ? void 0 : t.direction) === S, s = D && (t == null ? void 0 : t.direction) === d, h = u(
    () => [
      {
        type: a.Default,
        label: f ? "Sortierung aufheben" : "Sortiere aufsteigend",
        icon: f ? "ArrowUpDown" : "ArrowUpAZ",
        onClick: () => {
          k(S), r(f ? i.ClearSort : i.SortAsc);
        }
      },
      {
        type: a.Default,
        label: s ? "Sortierung aufheben" : "Sortiere absteigend",
        icon: s ? "ArrowUpDown" : "ArrowDownZA",
        onClick: () => {
          k(d), r(s ? i.ClearSort : i.SortDes);
        }
      },
      {
        type: a.Default,
        label: "Filter hinzufügen",
        icon: "Filter",
        onClick: () => r(i.Filter)
      },
      {
        type: a.Separator
      },
      {
        type: a.SubMenuTrigger,
        label: "Spalte anheften",
        icon: "Pin",
        children: [
          {
            type: a.Default,
            label: "Links anheften",
            onClick: () => r(i.PinLeft)
          },
          {
            type: a.Default,
            label: "Rechts anheften",
            onClick: () => r(i.PinRight)
          }
        ]
      },
      {
        type: a.Default,
        label: "Spalte umbenennen",
        icon: "Edit3",
        onClick: () => r(i.Rename)
      },
      {
        type: a.Default,
        label: "Spalte ausblenden",
        icon: "EyeOff",
        onClick: () => r(i.Hide)
      },
      {
        type: a.Default,
        label: "Farbschema definieren",
        icon: "PaintBucket",
        onClick: () => r(i.SetColor)
      },
      {
        type: a.Separator
      },
      {
        type: a.Default,
        label: "Automatisch skalieren",
        icon: "MoveHorizontal",
        onClick: () => {
          l == null || l(e.key), r(i.AutoResize);
        }
      },
      {
        type: a.Default,
        label: "Alle Spalten skalieren",
        icon: "StretchVertical",
        onClick: () => {
          p == null || p(), r(i.AutoResizeAll);
        }
      }
    ],
    [r, k, f, s, e, l, p]
  );
  return o != null && o.enabled ? /* @__PURE__ */ C(E, { menuItems: h, position: "right", children: /* @__PURE__ */ C(T, { variant: "ghost", icon: "EllipsisVertical", size: "iconXs" }) }) : null;
};
export {
  K as default
};
//# sourceMappingURL=DataTableHeadAction.js.map
