import * as e from "react";
//#region src/components/ui/use-toast.ts
var t = 5, n = 2e3, r = 2e3, i = 0;
function a() {
	return i = (i + 1) % (2 ** 53 - 1), i.toString();
}
var o = /* @__PURE__ */ new Map(), s = (e) => {
	if (o.has(e)) return;
	let t = setTimeout(() => {
		o.delete(e), d({
			type: "REMOVE_TOAST",
			toastId: e
		});
	}, n);
	o.set(e, t);
}, c = (e, n) => {
	switch (n.type) {
		case "ADD_TOAST": return {
			...e,
			toasts: [n.toast, ...e.toasts].slice(0, t)
		};
		case "UPDATE_TOAST": return {
			...e,
			toasts: e.toasts.map((e) => e.id === n.toast.id ? {
				...e,
				...n.toast
			} : e)
		};
		case "DISMISS_TOAST": {
			let { toastId: t } = n;
			return t ? s(t) : e.toasts.forEach((e) => {
				s(e.id);
			}), {
				...e,
				toasts: e.toasts.map((e) => e.id === t || t === void 0 ? {
					...e,
					open: !1
				} : e)
			};
		}
		case "REMOVE_TOAST": return n.toastId === void 0 ? {
			...e,
			toasts: []
		} : {
			...e,
			toasts: e.toasts.filter((e) => e.id !== n.toastId)
		};
	}
}, l = [], u = { toasts: [] };
function d(e) {
	u = c(u, e), l.forEach((e) => {
		e(u);
	});
}
function f({ ...e }) {
	let t = a(), n = (e) => d({
		type: "UPDATE_TOAST",
		toast: {
			...e,
			id: t
		}
	}), i = () => d({
		type: "DISMISS_TOAST",
		toastId: t
	});
	return d({
		type: "ADD_TOAST",
		toast: {
			...e,
			id: t,
			open: !0,
			duration: e.duration ?? r,
			onOpenChange: (e) => {
				e || i();
			}
		}
	}), {
		id: t,
		dismiss: i,
		update: n
	};
}
function p() {
	let [t, n] = e.useState(u);
	return e.useEffect(() => (l.push(n), () => {
		let e = l.indexOf(n);
		e > -1 && l.splice(e, 1);
	}), [t]), {
		...t,
		toast: f,
		dismiss: (e) => d({
			type: "DISMISS_TOAST",
			toastId: e
		})
	};
}
//#endregion
export { p as n, f as t };
