import { jsx as l, jsxs as B } from "react/jsx-runtime";
import { useState as I, useCallback as d } from "react";
import { Table as y } from "../../../table/components/TablePrimitive.js";
import { useSensors as L, useSensor as f, MouseSensor as R, TouchSensor as G, KeyboardSensor as M, DndContext as j, closestCenter as F } from "@dnd-kit/core";
import { restrictToHorizontalAxis as N } from "@dnd-kit/modifiers";
import { arrayMove as U } from "@dnd-kit/sortable";
import { DEFAULT_TABLE_HEIGHT as m, DEFAULT_ROW_HEIGHT as k, TABLE_HEADER_HEIGHT as w } from "../../constants/tableDefaults.js";
import z from "../../hooks/useDataTableStaticContext.js";
import { ScrollArea as K } from "../../../scroll-area/ScrollAreaPrimitive.js";
import W from "../../../table/components/table-loader/TableLoader.js";
const ee = ({
  containerRef: H,
  children: g,
  onScrollEnd: a,
  isLoading: T,
  rowLength: h = 0,
  rowHeight: b = k
}) => {
  const { tableHeight: i = m, autoHeight: p, setColumnOrder: s } = z(), n = i === "auto", [c, x] = I(n ? 0 : i), A = L(f(R, {}), f(G, {}), f(M, {})), E = d(
    (t) => {
      if (!a) return;
      const { scrollTop: e, scrollHeight: o, clientHeight: r } = t.currentTarget;
      e + r >= o - 10 && a();
    },
    [a]
  ), D = d(
    (t) => {
      if (n || !t) return;
      const e = t.getBoundingClientRect().height;
      e !== c && x(e);
    },
    [c, n]
  ), S = d(
    (t) => {
      const { active: e, over: o } = t;
      e && o && e.id !== o.id && (s == null || s((r) => {
        const u = r.indexOf(e.id), _ = r.indexOf(o.id);
        return U(r, u, _);
      }));
    },
    [s]
  ), v = typeof i == "number" ? i : m, C = n ? p ?? m : Math.min(h ? b * h + w : c, v);
  return /* @__PURE__ */ l(j, { collisionDetection: F, modifiers: [N], onDragEnd: S, sensors: A, children: /* @__PURE__ */ B(
    K,
    {
      ref: H,
      className: "border border-[var(--base-border)] rounded-[var(--border-radius-default)] relative",
      style: { height: C },
      onScroll: E,
      children: [
        /* @__PURE__ */ l(y, { ref: D, className: "grid", children: g }),
        T && /* @__PURE__ */ l(W, {})
      ]
    }
  ) });
};
export {
  ee as default
};
//# sourceMappingURL=DataTableContainer.js.map
