import { jsx as r } from "react/jsx-runtime";
import { forwardRef as Je, useRef as Qe, Children as Xe, isValidElement as u, Fragment as Ye } from "react";
import Ze from "../../utils/classNames.js";
import _e from "../../hooks/useMergeRefs.js";
import eo from "./TableBody.js";
import oo from "./TableColumn.js";
import to from "./TableExpanderButton.js";
import ro from "./TableExpandAllGroupsButton.js";
import lo from "./TableExpandedContentRow.js";
import no from "./TableExpandedRow.js";
import k from "./TableFooter.js";
import ao from "./TableGroupFooterRow.js";
import so from "./TableGroupRow.js";
import V from "./TableHeader.js";
import io from "./TableHeaderColumn.js";
import mo from "./TableHeaderRow.js";
import co from "./TableRow.js";
import uo from "./TableStickyRowButton.js";
import po from "./TableSpacerRow.js";
import { useTableLayout as bo } from "./layout/useTableLayout.js";
import { resolveTableClassConfig as fo, resolveTableBaseClassName as Co } from "./model/resolveTableClassConfig.js";
import Ro from "./render/header/TableBatchDropdown.js";
import wo from "./render/header/TableColumnFilter.js";
import To from "./runtime/useRenderDraftState.js";
import ho from "./runtime/useResponsiveResolvedViewType.js";
import yo from "./runtime/useResolvedRenderColumns.js";
import vo from "./runtime/useResolvedRenderHeader.js";
import go from "./selection/useInternalTableSelectionState.js";
import { TableInteractionContext as So } from "./context/TableInteractionContext.js";
import { TableLayoutContext as xo } from "./context/TableLayoutContext.js";
import { TableRenderConfigContext as Bo } from "./context/TableRenderConfigContext.js";
import { TableRenderContext as Eo } from "./context/TableRenderContext.js";
import Ho from "./settings/TableColumnsDropdown.js";
const mt = eo, ct = V, ut = mo, pt = io, bt = k, ft = oo, Ct = to, Rt = ro, wt = co, Tt = uo, ht = po, yt = no, vt = lo, gt = so, St = ao, xt = Ro, Bt = wo, Et = Ho, c = (e, n) => Xe.toArray(e).some((o) => n(o) ? !0 : u(o) && o.type === Ye ? c(o.props.children, n) : !1), Fo = (e) => u(e) && e.type === V, $o = (e) => u(e) && e.type === k, Ht = Je(
  (e, n) => {
    const {
      children: o,
      viewType: p = "TABLE",
      cardsStyle: b,
      responsiveBreakpoint: D,
      onViewTypeChange: K,
      condensed: L = !1,
      striped: N = !1,
      hover: I = !1,
      shadow: M = !1,
      border: P = !0,
      rounded: G = !0,
      gridLines: O = !1,
      rowClassName: W,
      rowKey: j,
      rowSeparatorWidth: U,
      stickyReference: q = "applicationLayout",
      stickyColumns: i,
      activeRowId: J,
      onActiveRowChange: f,
      rowAnimationProps: Q,
      expandedRowAnimation: X,
      sortBy: Y,
      sortDirection: Z,
      onSortChange: _,
      cellClassName: ee,
      selectionCheckboxVerticalAlignment: oe = "middle",
      onRowClick: C,
      onSelectionChange: te,
      hideSelectionCheckboxesForExcludedRows: re = !1,
      selectedRowIds: le,
      selectionHeaderContent: ne,
      columnOrder: ae,
      onColumnResize: se,
      onColumnOrderChange: ie,
      showSelectionColumn: d = !1,
      noRowsState: de = "No data available",
      virtualizedRows: R = !1,
      virtualizationOverscan: me = 5,
      className: w,
      style: ce,
      ...ue
    } = e, t = Qe({ headerColumns: [], bodyRows: [] });
    t.current.headerColumns = [], t.current.bodyRows = [], t.current.bodyMaxHeight = void 0, t.current.hasFooter = !1, t.current.hasFooterCells = void 0, t.current.hasExpandableRows = void 0;
    const {
      renderHeaderColumns: T,
      renderBodyRows: h,
      renderBodyMaxHeight: y,
      renderHasFooter: pe,
      renderHasFooterCells: v,
      renderHasExpandableRows: be,
      renderBodyRow: fe
    } = To(t), {
      columnDefinitionsByKey: Ce,
      columnIndexByKey: Re,
      draggableColumnKeys: we,
      draggableColumnsEnabled: g,
      handleColumnDragEnd: Te,
      handleColumnResizeReset: he,
      handleColumnResizeStart: ye,
      lastResizableColumnKey: ve,
      resettableColumnKeys: ge,
      resizeColumnsEnabled: a,
      resolvedRenderColumns: s,
      resizedColumns: Se
    } = yo({
      columnOrder: ae,
      onColumnOrderChange: ie,
      onColumnResize: se,
      renderHeaderColumns: T,
      viewType: p
    }), S = vo({
      renderHeaderColumns: T,
      resolvedRenderColumns: s,
      sortBy: Y,
      sortDirection: Z
    }), xe = v ?? !1, {
      handleBodyScroll: x,
      hasHorizontalScrollEndOffset: Be,
      hasHorizontalScrollStartOffset: B,
      tableUseOverflow: m,
      tableWrapperRef: Ee,
      wrapperStyle: E,
      tableHeadRowRef: He,
      tableFooterRowRef: Fe,
      wrapperWidth: $e
    } = bo({
      bodyMaxHeight: y,
      cardsStyle: b,
      columns: Se,
      hasFooterCells: xe,
      rowSeparatorWidth: U,
      showSelectionColumn: d,
      stickyReference: q,
      style: ce
    }), l = ho({
      onViewTypeChange: K,
      responsiveBreakpoint: D,
      viewType: p,
      wrapperTableWidth: E["--table-width"],
      wrapperWidth: $e
    }), { cardClasses: ze, hasHover: Ae, isTableView: H, styleClassSwitches: ke } = fo({
      viewType: l,
      hover: I,
      shadow: M,
      border: P,
      rounded: G,
      className: w,
      cardsStyle: b
    }), F = H ? Math.min(i?.left ?? 0, 1) : 0, $ = H ? Math.min(i?.right ?? 0, 1) : 0, Ve = (F > 0 || $ > 0) && i?.footer === !0, De = _e(Ee, n), z = {
      hasHeader: !!S || c(o, (qe) => Fo(qe)),
      hasFooter: l === "TABLE" && (pe || c(o, $o)),
      isClickable: typeof C == "function" || typeof f == "function",
      isTableView: l === "TABLE"
    }, {
      selectedRowIdSet: Ke,
      selectableRowIdSet: Le,
      isAllRowsSelected: Ne,
      isSomeRowsSelected: Ie,
      hasSelectableRows: Me,
      handleToggleAllSelection: Pe,
      handleToggleRowSelection: Ge
    } = go({
      bodyRows: h,
      onSelectionChange: te,
      selectedRowIds: le
    }), Oe = {
      showSelectionColumn: d,
      selectedRowIdSet: Ke,
      selectableRowIdSet: Le,
      selectionHeaderContent: ne,
      isAllRowsSelected: Ne,
      isSomeRowsSelected: Ie,
      hasSelectableRows: Me,
      hideSelectionCheckboxesForExcludedRows: re,
      onToggleAllSelection: Pe,
      onToggleRowSelection: Ge,
      activeRowId: J,
      onActiveRowChange: f,
      onRowClick: C,
      isClickable: z.isClickable,
      onSortChange: _
    }, We = {
      handleBodyScroll: x,
      tableHeadRowRef: He,
      tableFooterRowRef: Fe,
      draggableColumnKeys: g ? we : void 0,
      lastResizableColumnKey: a ? ve : void 0,
      resettableColumnKeys: a ? ge : void 0,
      stickyLeftColumnCount: F,
      stickyRightColumnCount: $,
      stickyFooter: Ve,
      onColumnDragEnd: g ? Te : void 0,
      onColumnResizeReset: a ? he : void 0,
      onColumnResizeStart: a ? ye : void 0
    }, je = {
      viewType: l,
      isTableView: l === "TABLE",
      cardClasses: ze,
      noRowsState: de,
      rowKey: j,
      rowClassName: W,
      cellClassName: ee,
      selectionCheckboxVerticalAlignment: oe,
      rowAnimationProps: R ? void 0 : Q,
      expandedRowAnimation: X,
      virtualizedRows: R,
      virtualizationOverscan: me
    }, Ue = {
      renderDraft: t.current,
      header: S,
      columns: s,
      columnDefinitionsByKey: Ce,
      columnIndexByKey: Re,
      bodyRows: h,
      renderBodyRow: fe,
      hasFooterCells: v,
      hasExpandableRows: be,
      isRegisteringBodyRows: !0
    }, A = /* @__PURE__ */ r(
      So.Provider,
      {
        value: Oe,
        children: /* @__PURE__ */ r(xo.Provider, { value: We, children: /* @__PURE__ */ r(
          Bo.Provider,
          {
            value: je,
            children: /* @__PURE__ */ r(
              Eo.Provider,
              {
                value: Ue,
                children: o
              }
            )
          }
        ) })
      }
    );
    return /* @__PURE__ */ r(
      "div",
      {
        ...ue,
        className: Ze(
          Co({
            viewType: l,
            condensed: L,
            striped: N,
            gridLines: O,
            className: w,
            tableUseOverflow: m,
            flags: z,
            hasHover: Ae,
            styleClassSwitches: ke
          }),
          B && "table-has-horizontal-scroll-start-offset",
          (Be || m && !B) && "table-has-horizontal-scroll-end-offset"
        ),
        ref: De,
        role: "table",
        "aria-colcount": s.length > 0 ? s.length + (d ? 1 : 0) : void 0,
        style: E,
        children: m && !y ? /* @__PURE__ */ r("div", { className: "overflow-x-auto", onScroll: x, role: "presentation", children: /* @__PURE__ */ r("div", { className: "table-scroll-content", role: "presentation", children: A }) }) : A
      }
    );
  }
);
export {
  xt as TableBatchDropdown,
  mt as TableBody,
  ft as TableColumn,
  Bt as TableColumnFilter,
  Et as TableColumnsDropdown,
  Rt as TableExpandAllGroupsButton,
  vt as TableExpandedContentRow,
  yt as TableExpandedRow,
  Ct as TableExpanderButton,
  bt as TableFooter,
  St as TableGroupFooterRow,
  gt as TableGroupRow,
  ct as TableHeader,
  pt as TableHeaderColumn,
  ut as TableHeaderRow,
  wt as TableRow,
  ht as TableSpacerRow,
  Tt as TableStickyRowButton,
  Ht as default
};
//# sourceMappingURL=Table.js.map
