import { useMemo as l } from "react";
import { useDraggableColumns as A } from "../layout/useDraggableColumns.js";
import { useResizableColumns as L } from "../layout/useResizableColumns.js";
const B = (m) => {
  const { columnOrder: g, onColumnOrderChange: C, onColumnResize: y, renderHeaderColumns: t, viewType: d } = m, i = l(
    () => t.flatMap(
      (e) => e.columnKey && e.colSpan === 1 ? [
        {
          ...e,
          columnKey: e.columnKey
        }
      ] : []
    ),
    [t]
  ), n = l(
    () => i.map((e) => ({
      key: e.columnKey,
      label: e.columnKey,
      mobileLabel: e.mobileLabel,
      width: e.width,
      minResizeWidth: e.minResizeWidth,
      maxResizeWidth: e.maxResizeWidth,
      draggable: e.draggable,
      resizeable: e.resizeable,
      horizontalAlign: e.horizontalAlign,
      headerClassName: e.headerClassName,
      hideOnMobile: e.hideOnMobile,
      sortable: e.sortable
    })),
    [i]
  ), o = d === "TABLE" && n.filter((e) => e.draggable === !0).length > 1, { draggableColumnKeys: R, handleColumnDragEnd: p, orderedColumns: b } = A({
    columns: n,
    columnOrder: g,
    enabled: o,
    onColumnOrderChange: C
  }), h = d === "TABLE" && b.some((e) => e.resizeable === !0), {
    handleColumnResizeReset: K,
    handleColumnResizeStart: M,
    lastResizableColumnKey: W,
    resettableColumnKeys: f,
    resizedColumns: r
  } = L({
    columns: b,
    enabled: h,
    onColumnResize: y
  }), s = l(() => {
    const e = new Map(i.map((a) => [a.columnKey, a]));
    return r.flatMap((a) => {
      const z = e.get(a.key);
      return z ? [
        {
          ...z,
          width: a.width,
          minResizeWidth: a.minResizeWidth,
          maxResizeWidth: a.maxResizeWidth,
          draggable: a.draggable,
          resizeable: a.resizeable,
          horizontalAlign: a.horizontalAlign,
          headerClassName: a.headerClassName,
          hideOnMobile: a.hideOnMobile,
          sortable: a.sortable
        }
      ] : [];
    });
  }, [i, r]), w = l(
    () => new Map(
      s.map((e) => [
        e.columnKey,
        {
          key: e.columnKey,
          label: e.label,
          mobileLabel: e.mobileLabel,
          icon: e.icon,
          filter: e.filter,
          hideLabel: e.hideLabel,
          width: e.width,
          minResizeWidth: e.minResizeWidth,
          maxResizeWidth: e.maxResizeWidth,
          draggable: e.draggable,
          resizeable: e.resizeable,
          horizontalAlign: e.horizontalAlign,
          className: void 0,
          headerClassName: e.headerClassName,
          hideOnMobile: e.hideOnMobile,
          sortable: e.sortable
        }
      ])
    ),
    [s]
  ), x = l(
    () => new Map(s.map((e, a) => [e.columnKey, a])),
    [s]
  );
  return {
    columnDefinitionsByKey: w,
    columnIndexByKey: x,
    draggableColumnKeys: R,
    draggableColumnsEnabled: o,
    handleColumnDragEnd: p,
    handleColumnResizeReset: K,
    handleColumnResizeStart: M,
    lastResizableColumnKey: W,
    resettableColumnKeys: f,
    renderDataColumns: i,
    resizeColumnsEnabled: h,
    resolvedRenderColumns: s,
    resizedColumns: r
  };
};
export {
  B as default
};
//# sourceMappingURL=useResolvedRenderColumns.js.map
