import { a as e, c as t, d as n, i as r, m as i, n as a, o as ee, r as te, s as ne, t as re } from "./base-table-D5IqsjQD.js";
import { useEffect as ie, useEffectEvent as ae, useMemo as o, useRef as s } from "react";
import { jsx as c } from "react/jsx-runtime";
import { formatPipelineDisplayValue as l } from "@ryuzaki13/react-foundation-lib/formatters";
import { useTableRowSelection as u } from "@ryuzaki13/react-foundation-lib/table";
import { getCoreRowModel as d, useReactTable as f } from "@tanstack/react-table";
var p = {
	selectedIndicatorCell: "hKghZt",
	sentinel: "QsLRvS"
};
//#endregion
//#region src/table/Table.tsx
function oe(e, t) {
	return String(t);
}
function m({ title: m, isLoading: h, isFetching: se, data: g, columns: _, selectionMode: v = "none", selectedRowIds: ce, getRowId: le, className: ue, minHeight: de, tableClassName: fe, columnVisibility: y, defaultColumnVisibility: b, columnOrder: x, defaultColumnOrder: S, columnSizing: C, defaultColumnSizing: w, columnPinning: T, defaultColumnPinning: E, enableColumnResizing: D = !1, enableColumnReordering: O = !1, columnResizeMinWidth: k, onColumnVisibilityChange: A, onColumnOrderChange: j, onColumnSizingChange: M, onColumnPinningChange: N, onRowClick: P, onRowSelectionChange: F, onReachEnd: I, getRowCanSelect: L, getRowClassName: R, renderHeaderContextMenu: pe, renderCellContent: z }) {
	let B = o(() => g ?? [], [g]), V = o(() => t(_), [_]), H = le ?? oe, U = o(() => new Map(B.map((e, t) => [H(e, t), e])), [H, B]), me = o(() => Array.from(U.keys()), [U]), W = s(null), G = s(null), { rowSelection: he, activateRowSelection: ge } = u({
		availableRowIds: me,
		rowById: U,
		selectionMode: v,
		selectedRowIds: ce,
		onRowSelectionChange: F
	}), { columnVisibility: K, onColumnVisibilityChange: _e } = te({
		columnVisibility: y,
		defaultColumnVisibility: b,
		onColumnVisibilityChange: A
	}), { columnOrder: q, onColumnOrderChange: ve } = ee({
		columnOrder: x,
		defaultColumnOrder: S,
		onColumnOrderChange: j
	}), { columnSizing: J, onColumnSizingChange: ye } = r({
		columnSizing: C,
		defaultColumnSizing: w,
		columnResizeMinWidth: k,
		onColumnSizingChange: M
	}), { columnPinning: Y, onColumnPinningChange: be } = e({
		columnPinning: T,
		defaultColumnPinning: E,
		onColumnPinningChange: N
	}), X = o(() => ({
		columnOrder: q,
		columnPinning: Y,
		columnSizing: J,
		columnVisibility: K
	}), [
		q,
		Y,
		J,
		K
	]), xe = ae(() => {
		I?.();
	});
	ie(() => {
		if (!I || !W.current || !G.current || h) return;
		let e = new IntersectionObserver((e) => {
			e[0]?.isIntersecting && xe();
		}, {
			root: W.current,
			threshold: .1
		});
		return e.observe(G.current), () => e.disconnect();
	}, [
		h,
		I,
		B.length
	]);
	let Z = f({
		data: B,
		columns: _,
		state: {
			columnOrder: q,
			columnPinning: Y,
			columnSizing: J,
			columnVisibility: K,
			rowSelection: he
		},
		onColumnOrderChange: ve,
		onColumnPinningChange: be,
		onColumnSizingChange: ye,
		onColumnVisibilityChange: _e,
		getRowId: (e, t) => H(e, t),
		getCoreRowModel: d(),
		enableMultiRowSelection: v === "multi",
		enableRowSelection: (e) => v === "none" ? !1 : L ? L(e.original) : !0
	}), Q = i(Z, X), $ = Z.getRowModel().rows, Se = o(() => ne({
		rows: $,
		columns: Q
	}), [$, Q]), Ce = Q[0]?.id;
	return /* @__PURE__ */ c(a, {
		table: Z,
		columnState: X,
		title: m,
		isLoading: h,
		isFetching: se,
		className: ue,
		minHeight: de,
		tableClassName: fe,
		selectionMode: v,
		scrollableRef: W,
		onActivateRow: v !== "none" || P ? (e) => {
			ge(e.id, e.getCanSelect()), P?.(e.original);
		} : void 0,
		isRowInteractive: (e) => !!(P || v !== "none" && e.getCanSelect()),
		getRowClassName: (e) => R?.(e.original),
		getCellClassName: ({ row: e, cell: t }) => t.column.id === Ce && e.getIsSelected() ? p.selectedIndicatorCell : void 0,
		getCellLayout: ({ cell: e }) => Se.get(e.id),
		renderHeaderContextMenu: pe,
		enableColumnResizing: D,
		enableColumnReordering: O,
		columnResizeMinWidth: k,
		renderCellContent: (e) => {
			let t = l({
				field: V.runtimeByColumnId[e.cell.column.id],
				rawValue: e.cell.getValue(),
				rowData: e.row.original,
				rowKind: "plain"
			}), r = n({
				columnId: e.cell.column.id,
				runtimeByColumnId: V.runtimeByColumnId,
				customCellColumnIds: V.customCellColumnIds
			}) ? /* @__PURE__ */ c(re, {
				displayValue: t,
				align: e.columnMeta?.align
			}) : e.defaultContent;
			return z ? z({
				...e,
				defaultContent: r,
				displayValue: t
			}) : r;
		},
		afterTableContent: I ? /* @__PURE__ */ c("div", {
			ref: G,
			className: p.sentinel,
			"aria-hidden": "true"
		}) : null
	});
}
//#endregion
export { m as t };

//# sourceMappingURL=table-xMAjqtcY.js.map