import { useMemo as f } from "react";
const z = (g) => {
  const { renderHeaderColumns: i, resolvedRenderColumns: a, sortBy: l, sortDirection: h } = g;
  return f(() => {
    if (i.length === 0 || a.length === 0)
      return;
    const y = new Set(Array.isArray(l) ? l : l ? [l] : []), b = Math.max(...i.map((e) => e.row + e.rowSpan - 1), 1), d = Array.from({ length: b }, () => Array(a.length).fill(!1)), c = new Map(
      a.map((e) => [e.columnKey, e])
    ), m = new Map(
      a.map((e, r) => [e.columnKey, r + 1])
    ), w = (e, r) => {
      for (let o = 1; o <= a.length - r + 1; o += 1)
        if (d[e - 1]?.slice(o - 1, o - 1 + r).every((t) => !t))
          return o;
      return 1;
    }, p = i.map((e) => {
      const r = e.columnKey ? c.get(e.columnKey) : void 0, o = r?.columnKey ? {
        key: r.columnKey,
        label: r.label,
        width: r.width,
        mobileLabel: r.mobileLabel,
        horizontalAlign: r.horizontalAlign,
        headerClassName: r.headerClassName,
        hideOnMobile: r.hideOnMobile,
        sortable: r.sortable,
        draggable: r.draggable,
        resizeable: r.resizeable,
        minResizeWidth: r.minResizeWidth,
        maxResizeWidth: r.maxResizeWidth
      } : void 0, n = r ? m.get(r.columnKey) ?? 1 : w(e.row, e.colSpan);
      for (let t = e.row - 1; t < e.row - 1 + e.rowSpan; t += 1)
        for (let s = n - 1; s < n - 1 + e.colSpan; s += 1)
          d[t]?.[s] !== void 0 && (d[t][s] = !0);
      return {
        key: e.id,
        columnKey: e.columnKey,
        label: e.label,
        icon: e.icon,
        filter: e.filter,
        hideLabel: e.hideLabel,
        horizontalAlign: r?.horizontalAlign ?? e.horizontalAlign,
        verticalAlign: r?.verticalAlign ?? e.verticalAlign,
        className: void 0,
        headerClassName: r?.headerClassName ?? e.headerClassName,
        hideOnMobile: r?.hideOnMobile ?? e.hideOnMobile,
        draggable: r?.draggable ?? e.draggable,
        resizeable: r?.resizeable ?? e.resizeable,
        sortable: r?.sortable ?? e.sortable,
        sortDirection: e.columnKey && y.has(e.columnKey) ? h : void 0,
        rowStart: e.row,
        rowSpan: e.rowSpan,
        columnStart: n,
        colSpan: e.colSpan,
        source: o
      };
    });
    return {
      rowCount: b,
      totalColumnCount: a.length,
      columns: p
    };
  }, [i, a, l, h]);
};
export {
  z as default
};
//# sourceMappingURL=useResolvedRenderHeader.js.map
