import { create } from "zustand";

//#region src/hooks/useScrollBlockage/useScrollBlockageStore.ts
const useScrollBlockageStore = create((set, get) => ({
	scrollBlockers: [],
	addBlockage: (blockerName, element) => set((state) => {
		const scrollBlockers = state.scrollBlockers;
		const blockersElement = scrollBlockers.find((blocker) => blocker.element === element);
		if (blockersElement) {
			const newBlockers = blockersElement.blockers.includes(blockerName) ? blockersElement.blockers : [...blockersElement.blockers, blockerName];
			return { scrollBlockers: scrollBlockers.map((blocker) => blocker.element === element ? {
				...blocker,
				blockers: newBlockers
			} : blocker) };
		}
		element.style.overflowY = "hidden";
		element.style.overflowX = "hidden";
		return { scrollBlockers: [...scrollBlockers, {
			element,
			blockers: [blockerName]
		}] };
	}),
	removeBlockage: (blockerName, element) => set((state) => {
		const scrollBlockers = state.scrollBlockers;
		const blocker = scrollBlockers.find((blocker$1) => blocker$1.element === element);
		if (blocker) {
			if (blocker.blockers.length > 1) return { scrollBlockers: scrollBlockers.map((blocker$1) => blocker$1.element === element ? {
				...blocker$1,
				blockers: blocker$1.blockers.filter((b) => b !== blockerName)
			} : blocker$1) };
			element.style.overflowY = "auto";
			return { scrollBlockers: scrollBlockers.filter((blocker$1) => blocker$1.element !== element) };
		}
		return { scrollBlockers };
	}),
	isElementScrollBlocked: (element) => get().scrollBlockers.some((blocker) => blocker.element === element)
}));

//#endregion
export { useScrollBlockageStore };
//# sourceMappingURL=useScrollBlockageStore.mjs.map