import L from "../shared/parsePixelSize.js";
import { useMeasuredColumnMaxWidths as k } from "./useMeasuredColumnMaxWidths.js";
import { MIN_COLUMN_WIDTH_PX as N } from "../tableSizing.constants.js";
import { toCssSize as i, getColumnTrack as B } from "./columnSizing.js";
import { useHorizontalSectionSync as E } from "./useHorizontalSectionSync.js";
import $ from "../../../hooks/useResizeObserver.js";
const d = 50, F = (m) => {
  const {
    bodyMaxHeight: p,
    cardsStyle: s,
    columns: r,
    hasFooterCells: h,
    rowSeparatorWidth: f,
    showSelectionColumn: n,
    stickyReference: b = "applicationLayout",
    style: u
  } = m, [l, , { inlineSize: S }] = $(), t = r.map((e, a) => ({
    column: e,
    columnIndex: a,
    areaName: `table-col-${a + 1}`
  })), o = S ?? l.current?.clientWidth, W = (n ? d : 0) + r.reduce((e, a) => {
    if (a.width === void 0)
      return e + N;
    const _ = L(i(a.width));
    return e + (_ ?? 0);
  }, 0), c = o !== void 0 && W > o, w = o !== void 0 ? `${o}px` : "100%", {
    handleBodyScroll: y,
    hasHorizontalScrollEndOffset: x,
    hasHorizontalScrollStartOffset: C,
    tableFooterRowRef: M,
    tableHeadRowRef: T
  } = E({
    enabled: !!p,
    hasFooterCells: h
  }), g = k({
    columns: r,
    enabled: c,
    tableWrapperRef: l
  }), v = t.length > 0 ? [
    n ? `${d}px` : void 0,
    ...t.map(({ column: e }) => B(e, g[e.key]))
  ].filter(Boolean).join(" ") : "minmax(0, 1fr)", z = t.length > 0 ? `"${[
    n ? "table-selection" : void 0,
    ...t.map(({ areaName: e }) => e)
  ].filter(Boolean).join(" ")}"` : "none", H = i(s?.minWidth), O = i(s?.maxWidth), R = {
    ...u ?? {},
    "--table-columns": v,
    "--table-areas": z,
    "--table-cards-min": H,
    "--table-cards-max": O,
    "--table-column-count": String(r.length + (n ? 1 : 0)),
    "--table-row-separator-width": i(f),
    "--table-sticky-reference-top": b === "container" ? "0px" : "var(--table-sticky-offset)",
    "--table-width": w
  };
  return {
    columnsWithAreas: t,
    handleBodyScroll: y,
    hasHorizontalScrollEndOffset: x,
    hasHorizontalScrollStartOffset: C,
    tableUseOverflow: c,
    tableWrapperRef: l,
    tableFooterRowRef: M,
    tableHeadRowRef: T,
    wrapperWidth: o,
    wrapperStyle: R
  };
};
export {
  F as useTableLayout
};
//# sourceMappingURL=useTableLayout.js.map
