import { useEffect, useRef, useState } from "react";
const useElementList = (ref, selectors, options) => {
	const [elementList, setElementList] = useState();
	const previousElementsRef = useRef([]);
	useEffect(() => {
		const handleMutationChange = () => {
			const elements = ref.current?.querySelectorAll(selectors);
			if (!elements) {
				if (previousElementsRef.current.length > 0) {
					previousElementsRef.current = [];
					setElementList(void 0);
				}
				return;
			}
			const elementsArray = Array.from(elements);
			const previousElements = previousElementsRef.current;
			if (elementsArray.length !== previousElements.length || elementsArray.some((el, i) => el !== previousElements[i])) {
				previousElementsRef.current = elementsArray;
				setElementList(elements);
			}
		};
		const mutationObserver = new MutationObserver(handleMutationChange);
		if (ref?.current) mutationObserver.observe(ref.current, {
			subtree: true,
			childList: true,
			attributes: true,
			...options
		});
		handleMutationChange();
		return () => {
			mutationObserver.disconnect();
		};
	}, [ref, selectors]);
	return elementList;
};
export { useElementList as t };

//# sourceMappingURL=useElementList.js.map