import { t as useElementList } from "./useElementList.js";
import { t as FOCUSABLE_SELECTORS } from "./useFocusableElements.js";
import { useEffect } from "react";
const useFocusToggle = (ref, allowFocus) => {
	const focusableElementList = useElementList(ref, FOCUSABLE_SELECTORS, { attributes: false });
	useEffect(() => {
		const TABINDEX_ATTRIBUTE_NAME = "tabindex";
		const PREVIOUS_TABINDEX_ATTRIBUTE_NAME = "data-tabindex";
		if (allowFocus) focusableElementList?.forEach((el) => {
			const prevTabIndex = el.getAttribute(PREVIOUS_TABINDEX_ATTRIBUTE_NAME);
			if (prevTabIndex) el.setAttribute(TABINDEX_ATTRIBUTE_NAME, prevTabIndex);
			else el.removeAttribute(TABINDEX_ATTRIBUTE_NAME);
		});
		else focusableElementList?.forEach((el) => {
			if (el.hasAttribute(TABINDEX_ATTRIBUTE_NAME)) el.setAttribute(PREVIOUS_TABINDEX_ATTRIBUTE_NAME, `${el.tabIndex}`);
			el.tabIndex = -1;
		});
	}, [
		ref,
		allowFocus,
		focusableElementList
	]);
};
export { useFocusToggle as t };

//# sourceMappingURL=useFocusToggle.js.map