import { n as AnalyticsId } from "../../constants2.js";
import { n as useBreakpoint } from "../../useBreakpoint.js";
import { n as getAriaLabelAttributes } from "../../accessibility.js";
import { t as useIsVisible } from "../../useIsVisible.js";
import { t as useLayoutEvent } from "../../useLayoutEvent.js";
import { t as HorizontalScroll_default } from "../../HorizontalScroll.js";
import { a as TextAlign, i as SortDirection, n as ModeType, o as defaultConfig, r as ResponsiveTableVariant, s as simpleConfig, t as HeaderCategory } from "../../constants3.js";
import { a as omitProps, i as mapChildrenWithMode, n as getCenteredOverflowTableStyle, r as getCurrentConfig, t as getBreakpointClass } from "../../utils6.js";
import { n as TableBody } from "../../TableBody.js";
import { n as TableCell } from "../../TableCell.js";
import { n as TableExpandedRow } from "../../TableExpandedRow.js";
import { n as TableExpanderCell } from "../../TableExpanderCell.js";
import { n as TableHead } from "../../TableHead.js";
import { n as TableHeadCell } from "../../TableHeadCell.js";
import { n as TableRow } from "../../TableRow.js";
import classNames from "classnames";
import { useEffect, useRef, useState } from "react";
import { jsx } from "react/jsx-runtime";
import styles from "./styles.module.scss";
const Table = ({ id, testId, className, children, breakpointConfig = defaultConfig, mode = ModeType.normal, scrollAriaLabel, scrollAriaLabelledById, ...rest }) => {
	const [currentConfig, setCurrentConfig] = useState();
	const [tableWidth, setTableWidth] = useState(0);
	const [parentWidth, setParentWidth] = useState(0);
	const [windowWidth, setWindowWidth] = useState(window.innerWidth);
	const tableRef = useRef(null);
	const tableIsVisible = useIsVisible(tableRef, 0);
	const breakpoint = useBreakpoint();
	useEffect(() => {
		setCurrentConfig(getCurrentConfig(breakpointConfig, breakpoint, tableWidth, windowWidth));
	}, [
		breakpointConfig,
		breakpoint,
		tableWidth,
		windowWidth
	]);
	useEffect(() => {
		if (currentConfig?.variant === ResponsiveTableVariant.centeredoverflow || currentConfig?.variant === ResponsiveTableVariant.horizontalscroll) setTableWidth(tableRef.current?.getBoundingClientRect().width ?? 0);
		if (currentConfig?.variant === ResponsiveTableVariant.centeredoverflow) setParentWidth(tableRef.current?.parentElement?.getBoundingClientRect().width ?? 0);
	}, [currentConfig, breakpoint]);
	useLayoutEvent(() => setWindowWidth(window.innerWidth), ["resize"], 100);
	useEffect(() => {
		if (tableWidth === 0 && tableIsVisible) setTableWidth(tableRef.current?.getBoundingClientRect().width ?? 0);
	}, [tableWidth, tableIsVisible]);
	const tableStyle = currentConfig?.variant === ResponsiveTableVariant.centeredoverflow ? getCenteredOverflowTableStyle(parentWidth, tableWidth) : void 0;
	const breakpointClass = getBreakpointClass(currentConfig);
	const tableClass = classNames(styles.table, breakpointClass, className);
	const domRest = omitProps(rest, [
		"breakpoint",
		"variant",
		"fallbackVariant",
		"headerCategory"
	]);
	const table = /* @__PURE__ */ jsx("table", {
		className: tableClass,
		id,
		"data-testid": testId,
		"data-analyticsid": AnalyticsId.Table,
		ref: tableRef,
		style: tableStyle,
		...domRest,
		children: mapChildrenWithMode(children, mode)
	});
	const ariaLabelAttributes = getAriaLabelAttributes({
		label: scrollAriaLabel,
		id: scrollAriaLabelledById
	});
	if (currentConfig?.variant === ResponsiveTableVariant.horizontalscroll) return /* @__PURE__ */ jsx(HorizontalScroll_default, {
		childWidth: tableWidth,
		testId: "horizontal-scroll",
		...ariaLabelAttributes,
		children: table
	});
	return table;
};
var Table_default = Table;
export { HeaderCategory, ModeType, ResponsiveTableVariant, SortDirection, Table, TableBody, TableCell, TableExpandedRow, TableExpanderCell, TableHead, TableHeadCell, TableRow, TextAlign, Table_default as default, defaultConfig, getBreakpointClass, getCenteredOverflowTableStyle, getCurrentConfig, mapChildrenWithMode, omitProps, simpleConfig };

//# sourceMappingURL=index.js.map