import { t as e } from "./clsx.js";
import { Portal as t } from "../ui/Portal.js";
import { useCallback as n, useEffect as r, useRef as i, useState as a } from "react";
import { jsx as o, jsxs as s } from "react/jsx-runtime";
var c = 5, l = 6, u = [
	"preEnter",
	"entering",
	"entered",
	"preExit",
	"exiting",
	"exited",
	"unmounted"
], d = (e) => ({
	_s: e,
	status: u[e],
	isEnter: e < 3,
	isMounted: e !== l,
	isResolved: e === 2 || e > 4
}), f = (e) => e ? l : c, p = (e, t) => {
	switch (e) {
		case 1:
		case 0: return 2;
		case 4:
		case 3: return f(t);
	}
}, m = (e) => typeof e == "object" ? [e.enter, e.exit] : [e, e], h = (...e) => setTimeout(...e), g = (e, t) => h(() => {
	isNaN(document.body.offsetTop) || e(t + 1);
}, 0), _ = (e, t, n, r, i) => {
	clearTimeout(r.current);
	let a = d(e);
	t(a), n.current = a, i && i({ current: a });
}, v = ({ enter: e = !0, exit: t = !0, preEnter: r, preExit: o, timeout: s, initialEntered: c, mountOnEnter: l, unmountOnExit: u, onStateChange: v } = {}) => {
	let [y, b] = a(() => d(c ? 2 : f(l))), x = i(y), S = i(0), [C, w] = m(s), T = n(() => {
		let e = p(x.current._s, u);
		e && _(e, b, x, S, v);
	}, [v, u]);
	return [
		y,
		n((n) => {
			let i = (e) => {
				switch (_(e, b, x, S, v), e) {
					case 1:
						C >= 0 && (S.current = h(T, C));
						break;
					case 4:
						w >= 0 && (S.current = h(T, w));
						break;
					case 0:
					case 3:
						S.current = g(i, e);
						break;
				}
			}, a = x.current.isEnter;
			typeof n != "boolean" && (n = !a), n ? !a && i(e ? r ? 0 : 1 : 2) : a && i(t ? o ? 3 : 4 : f(u));
		}, [
			T,
			v,
			e,
			t,
			r,
			o,
			C,
			w,
			u
		]),
		T
	];
}, y = ({ children: n, className: i = "flex justify-center", onClose: a, isVisible: c, target: l = "backdrop", sweep: u = !1, ...d }) => {
	let [f, p] = v({
		timeout: {
			enter: 0,
			exit: 500
		},
		mountOnEnter: !0,
		unmountOnExit: !0,
		preEnter: !0
	}), { status: m, isMounted: h } = f;
	r(() => {
		p(c);
	}, [c, p]);
	let g = m === "preEnter" || m === "exiting";
	return /* @__PURE__ */ o(t, {
		target: l,
		children: h && /* @__PURE__ */ s("div", {
			...d,
			role: "presentation",
			className: e(i, "fixed inset-0 isolate items-center"),
			children: [/* @__PURE__ */ o("button", {
				"aria-hidden": "true",
				className: e("absolute inset-0 -z-1 transition-all duration-500", {
					"bg-white/80 backdrop-blur": !g,
					"bg-white/0 backdrop-blur-none": g,
					"-translate-x-full": u && (m === "preEnter" || m === "entering"),
					"translate-x-full": u && m === "exiting"
				}),
				onClick: a,
				type: "button"
			}), n]
		})
	});
};
//#endregion
export { v as n, y as t };

//# sourceMappingURL=Backdrop.js.map