import { jsx as n } from "react/jsx-runtime";
import { useVirtualizer as S } from "@tanstack/react-virtual";
import { useMemo as l, useCallback as v } from "react";
import { TableBody as y } from "../../../table/components/TablePrimitive.js";
import E from "../data-table-row/DataTableRow.js";
import { DEFAULT_ROW_HEIGHT as T } from "../../constants/tableDefaults.js";
import I from "../../hooks/useDataTableStaticContext.js";
const _ = ({
  rows: r,
  tableContainerRef: s,
  columnSizingId: d = !1,
  columnSizingDeltaOffset: m = null,
  columnSize: c,
  selectedColumns: a
}) => {
  const { rowHeight: o = T, hasColumnSeparator: u, onRowClick: g, cellEdit: b } = I(), e = S({
    count: r.length,
    getScrollElement: () => s.current,
    estimateSize: () => o,
    overscan: 5,
    // Number of rows to render above and below the visible area
    measureElement: typeof window < "u" && !/Firefox/i.test(navigator.userAgent) ? (t) => t == null ? void 0 : t.getBoundingClientRect().height : void 0
  }), f = e.getVirtualItems(), p = l(() => (a == null ? void 0 : a.map((t) => t.key).join(",")) ?? "", [a]), h = v(
    (t) => {
      e.measureElement(t);
    },
    [e]
  ), x = l(() => r.length ? e.getTotalSize() : 0, [r.length, e]);
  return /* @__PURE__ */ n(
    y,
    {
      className: "bg-[var(--base-background)] divide-y divide-[var(--base-border)] grid relative [&_tr:last-child]:border-b",
      style: { height: `${x}px` },
      children: f.map((t) => {
        const i = r[t.index];
        return i ? /* @__PURE__ */ n(
          E,
          {
            dataIndex: t.index,
            measureElement: h,
            rowStartPosition: t.start,
            row: i,
            isSelected: i.getIsSelected(),
            columnSizingId: d,
            columnSizingDeltaOffset: m,
            columnSize: c,
            rowHeight: o,
            hasColumnSeparator: u,
            onRowClick: g,
            cellEdit: b,
            columnKey: p
          },
          i.id
        ) : null;
      })
    }
  );
};
export {
  _ as default
};
//# sourceMappingURL=DataTableBody.js.map
