import { c } from "react-compiler-runtime";
import { useState } from "react";
//#region src/hooks/useDynamicListCalculation.jsx
/**
* A custom React hook for calculating the number of visible children in a dynamic list based on container width and child widths.
*
* @returns {object} An object containing the `calculateNumberOfVisibleChildren` function.
*
* @example
* // Basic usage:
* const parentRef = useRef();
* const childRefs = useRef([]);
* const { calculateNumberOfVisibleChildren } = useDynamicListCalculation();
* const maxVisibleChildren = calculateNumberOfVisibleChildren(parentRef, childRefs);

* @example
* // Excluding a buffer for less white space:
* const parentRef = useRef();
* const childRefs = useRef([]);
* const { calculateNumberOfVisibleChildren } = useDynamicListCalculation();
* const maxVisibleChildren = calculateNumberOfVisibleChildren(parentRef, childRefs, false);
*/
const useDynamicListCalculation = () => {
	const $ = c(6);
	const [averageChildWidth, setAverageChildWidth] = useState(0);
	let t0;
	if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
		t0 = [];
		$[0] = t0;
	} else t0 = $[0];
	const [previousChildRefs, setPreviousChildRefs] = useState(t0);
	let t1;
	if ($[1] !== averageChildWidth || $[2] !== previousChildRefs) {
		t1 = (parentRef, childRefs, t2) => {
			const includeBuffer = t2 === void 0 ? true : t2;
			if (!parentRef.current || !childRefs.current) return;
			const containerWidth = parentRef.current.getBoundingClientRect().width ?? 0;
			if (!averageChildWidth || previousChildRefs !== childRefs.current) {
				setAverageChildWidth(childRefs.current.map(_temp).reduce(_temp2, 0) / childRefs.current.length);
				setPreviousChildRefs(childRefs.current);
			}
			const maxVisibleChildren = Math.floor(containerWidth / averageChildWidth);
			if (includeBuffer) return maxVisibleChildren - 1;
			return maxVisibleChildren;
		};
		$[1] = averageChildWidth;
		$[2] = previousChildRefs;
		$[3] = t1;
	} else t1 = $[3];
	const calculateNumberOfVisibleChildren = t1;
	let t2;
	if ($[4] !== calculateNumberOfVisibleChildren) {
		t2 = { calculateNumberOfVisibleChildren };
		$[4] = calculateNumberOfVisibleChildren;
		$[5] = t2;
	} else t2 = $[5];
	return t2;
};
function _temp(ref) {
	return ref && typeof ref?.getBoundingClientRect === "function" ? ref.getBoundingClientRect().width : 0;
}
function _temp2(acc, curr) {
	return acc + curr;
}
//#endregion
export { useDynamicListCalculation };

//# sourceMappingURL=useDynamicListCalculation.mjs.map