import { useBodyScrollLock } from "../core/vuiProvider/useBodyScrollLock.js";
import "../core/index.js";
import { useEffect } from "react";

//#region src/modal/modalManager.ts
/** State management for nested modals. */
var ModalManager = class {
	modals = [];
	add = (modal) => this.modals.push(modal);
	remove = (modal) => this.modals = this.modals.filter((m) => m !== modal);
	isTopModal = (modal) => {
		return this.modals[this.modals.length - 1] === modal;
	};
};
const manager = new ModalManager();
/** Refs of new modals will be automatically added/removed from the state when rendering. */
function useModalManager(ref, isOpen, disableScrollLock) {
	const { setIsScrollLocked } = useBodyScrollLock();
	useEffect(() => {
		if (isOpen) {
			manager.add(ref);
			if (!disableScrollLock) setIsScrollLocked(true);
		}
		return () => {
			manager.remove(ref);
			if (!disableScrollLock) setIsScrollLocked(false);
		};
	}, [isOpen, ref]);
}

//#endregion
export { manager, useModalManager };
globalThis.__vuiVersion__ = "4.0.0-beta.1"
//# sourceMappingURL=modalManager.js.map