import { useMemo as r, useRef as j, useCallback as S } from "react";
import { useSortable as q } from "@dnd-kit/sortable";
import { CSS as F } from "@dnd-kit/utilities";
import { ACTION_COLUMN_ID as J, SELECTION_COLUMN_ID as Q, SELECTION_COLUMN_SIZE as X, ACTION_COLUMN_SIZE as Y, COLUMN_MIN_SIZE as $ } from "../../../constants/tableDefaults.js";
import ee from "../../../hooks/useDataTableStaticContext.js";
import te from "../../../hooks/useDataTableDynamicContext.js";
function le(N) {
  const { header: x, columnSizingId: d, columnSizingDeltaOffset: b, hasColumnSeparator: I, onHeaderClick: s, cellsLength: z, selectedColumns: i } = N, { columnAction: u, draggable: m } = ee(), { sorting: l } = te(), {
    id: e,
    index: a,
    colSpan: O,
    column: {
      columnDef: { header: T },
      getCanResize: f,
      getSize: g
    },
    getContext: _,
    getResizeHandler: D
  } = x, t = r(
    () => i.find((n) => n.key === e) || i[a],
    [i, e, a]
  ), { columnAlign: v, sortable: E, isSelectionColumn: o, isActionColumn: C } = r(
    () => ({
      columnAlign: t == null ? void 0 : t.align,
      sortable: !!(t != null && t.sorter),
      isSelectionColumn: e === Q,
      isActionColumn: e === J
    }),
    [t, e]
  ), M = r(() => (E || !!s) && !o, [E, s, o]), L = r(() => d === e ? g() + (b || 0) : g(), [d, e, g, b]), R = r(
    () => I && !f() && a !== i.length,
    [I, f, a, i.length]
  ), {
    attributes: k,
    isDragging: h,
    listeners: A,
    setNodeRef: U,
    transform: w
  } = q({
    id: e
  }), y = _(), H = f() && a !== z - 1, P = (l == null ? void 0 : l.columnKey) === e, p = j(!1), Z = d === e, B = r(() => o ? X : C ? Y : Math.max(L || 0, $), [o, L, C]), G = S(() => {
    if (!p.current && s && t && !o) {
      const n = t.title || e;
      s(n, t);
    }
  }, [e, t, s, o]), K = S(
    (n) => {
      n.preventDefault(), n.stopPropagation(), p.current = !0;
      const c = () => {
        setTimeout(() => {
          p.current = !1;
        }, 100), document.removeEventListener("mouseup", c), document.removeEventListener("touchend", c);
      };
      document.addEventListener("mouseup", c), document.addEventListener("touchend", c), D()(n);
    },
    [D]
  ), V = S((n) => {
    n.preventDefault(), n.stopPropagation();
  }, []), W = {
    width: B,
    transform: F.Translate.toString(w),
    transition: "width transform 0.2s ease-in-out",
    whiteSpace: "nowrap",
    opacity: h ? 0.8 : 1,
    position: "relative",
    zIndex: h ? 1 : 0,
    flexShrink: 0
  };
  return {
    state: {
      column: t,
      columnAlign: v,
      headerDef: T,
      headerContext: y,
      isSelectionColumn: o,
      isActionColumn: C,
      isSorting: P,
      isDragging: h,
      isBorderVisible: R,
      canResize: H,
      clickable: M,
      sorting: l,
      columnActionEnabled: u == null ? void 0 : u.enabled,
      draggableEnabled: m == null ? void 0 : m.enabled,
      colSpan: O,
      isResizing: Z
    },
    style: W,
    handlers: {
      setNodeRef: U,
      handleHeaderClick: G,
      handleResize: K,
      handleResizeClick: V
    },
    dndProps: {
      draggableAttributes: k,
      draggableListeners: A
    }
  };
}
export {
  le as default
};
//# sourceMappingURL=useDataTableHeadCell.js.map
