'use client';

import { useSyncExternalStore } from "react";

//#region src/components/RightDrawer/useRightDrawer.ts
var DrawerObservable = class {
	listeners = /* @__PURE__ */ new Set();
	drawers = {};
	subscribe = (listener) => {
		this.listeners.add(listener);
		return () => {
			this.listeners.delete(listener);
		};
	};
	getSnapshot = () => {
		return this.drawers;
	};
	open = (key) => {
		if (this.drawers[key]) return;
		this.drawers = {
			...this.drawers,
			[key]: true
		};
		this.emit();
	};
	close = (key) => {
		if (!this.drawers[key]) return;
		this.drawers = {
			...this.drawers,
			[key]: false
		};
		this.emit();
	};
	set = (states) => {
		let changed = false;
		const newDrawers = { ...this.drawers };
		for (const [key, value] of Object.entries(states)) if (newDrawers[key] !== value) {
			newDrawers[key] = value;
			changed = true;
		}
		if (changed) {
			this.drawers = newDrawers;
			this.emit();
		}
	};
	emit = () => {
		this.listeners.forEach((listener) => {
			listener();
		});
	};
};
const drawerManager = new DrawerObservable();
const useRightDrawer = () => {
	const drawers = useSyncExternalStore(drawerManager.subscribe, drawerManager.getSnapshot, () => ({}));
	return {
		open: drawerManager.open,
		close: drawerManager.close,
		set: drawerManager.set,
		isOpen: (key) => !!drawers[key]
	};
};

//#endregion
export { drawerManager, useRightDrawer };
//# sourceMappingURL=useRightDrawer.mjs.map