import { t as Breakpoint } from "./useBreakpoint.js";
import { r as ResponsiveTableVariant } from "./constants3.js";
import { t as isTouchDevice } from "./device.js";
import React from "react";
import styles from "./components/Table/styles.module.scss";
var configUsesCss = (config) => config.variant === ResponsiveTableVariant.centeredoverflow || config.variant === ResponsiveTableVariant.block;
var mapConfigToClass = (config) => config.variant === "centeredoverflow" || config.variant === "block" ? styles[`table--${config.variant}-${config.breakpoint}`] : "";
var sortByBreakpointsDescending = (a, b) => Breakpoint[a.breakpoint] - Breakpoint[b.breakpoint];
var isValidForCurrentBreakpoint = (config, breakpoint) => Breakpoint[config.breakpoint] >= breakpoint;
var getConfigForBreakpoint = (config, breakpoint) => {
	if (Array.isArray(config)) {
		config.sort(sortByBreakpointsDescending);
		return config.find((x) => isValidForCurrentBreakpoint(x, breakpoint));
	} else if (config && isValidForCurrentBreakpoint(config, breakpoint)) return config;
};
const getCurrentConfig = (config, breakpoint, tableWidth, windowWidth) => {
	const breakpointConfig = getConfigForBreakpoint(config, breakpoint);
	const canUseHorizontalScroll = isTouchDevice();
	const canUseCenteredOverflow = tableWidth <= windowWidth;
	if (!breakpointConfig) return;
	if (breakpointConfig.variant === ResponsiveTableVariant.centeredoverflow && !canUseCenteredOverflow && breakpointConfig.fallbackVariant === ResponsiveTableVariant.horizontalscroll) return {
		variant: canUseHorizontalScroll ? ResponsiveTableVariant.horizontalscroll : ResponsiveTableVariant.none,
		breakpoint: breakpointConfig.breakpoint
	};
	if (breakpointConfig.variant === ResponsiveTableVariant.centeredoverflow && !canUseCenteredOverflow && breakpointConfig.fallbackVariant !== ResponsiveTableVariant.centeredoverflow) return {
		variant: breakpointConfig.fallbackVariant ?? ResponsiveTableVariant.none,
		breakpoint: breakpointConfig.breakpoint
	};
	if (breakpointConfig.variant === ResponsiveTableVariant.horizontalscroll && !canUseHorizontalScroll && breakpointConfig.fallbackVariant === ResponsiveTableVariant.centeredoverflow) return {
		variant: canUseCenteredOverflow ? ResponsiveTableVariant.centeredoverflow : ResponsiveTableVariant.none,
		breakpoint: breakpointConfig.breakpoint
	};
	if (breakpointConfig.variant === ResponsiveTableVariant.horizontalscroll && !canUseHorizontalScroll && breakpointConfig.fallbackVariant !== ResponsiveTableVariant.horizontalscroll) return {
		variant: breakpointConfig.fallbackVariant ?? ResponsiveTableVariant.none,
		breakpoint: breakpointConfig.breakpoint
	};
	return breakpointConfig;
};
const getBreakpointClass = (config) => config && configUsesCss(config) ? mapConfigToClass(config) : void 0;
const getCenteredOverflowTableStyle = (parentWidth, tableWidth) => {
	if (parentWidth >= tableWidth) return;
	return { left: `${(parentWidth - tableWidth) / 2 - 8}px` };
};
const mapChildrenWithMode = (children, mode) => React.Children.map(children, (child) => {
	if (!React.isValidElement(child)) return child;
	if (child.type === React.Fragment) {
		const fragmentChildren = child.props.children;
		const mapped = React.Children.map(fragmentChildren, (gc) => React.isValidElement(gc) ? React.cloneElement(gc, { mode }) : gc);
		return React.cloneElement(child, void 0, mapped);
	}
	return React.cloneElement(child, { mode });
});
const omitProps = (obj, keys) => {
	const clone = { ...obj };
	for (const k of keys) delete clone[k];
	return clone;
};
export { omitProps as a, mapChildrenWithMode as i, getCenteredOverflowTableStyle as n, getCurrentConfig as r, getBreakpointClass as t };

//# sourceMappingURL=utils6.js.map