"use client";
import * as e from "react";
import t, { useEffect as n, useLayoutEffect as r, useMemo as i } from "react";
import * as a from "@radix-ui/react-dialog";
//#region ../../node_modules/vaul/dist/index.mjs
function o(e) {
	if (!e || typeof document > "u") return;
	let t = document.head || document.getElementsByTagName("head")[0], n = document.createElement("style");
	n.type = "text/css", t.appendChild(n), n.styleSheet ? n.styleSheet.cssText = e : n.appendChild(document.createTextNode(e));
}
var s = t.createContext({
	drawerRef: { current: null },
	overlayRef: { current: null },
	onPress: () => {},
	onRelease: () => {},
	onDrag: () => {},
	onNestedDrag: () => {},
	onNestedOpenChange: () => {},
	onNestedRelease: () => {},
	openProp: void 0,
	dismissible: !1,
	isOpen: !1,
	isDragging: !1,
	keyboardIsOpen: { current: !1 },
	snapPointsOffset: null,
	snapPoints: null,
	handleOnly: !1,
	modal: !1,
	shouldFade: !1,
	activeSnapPoint: null,
	onOpenChange: () => {},
	setActiveSnapPoint: () => {},
	closeDrawer: () => {},
	direction: "bottom",
	shouldAnimate: { current: !0 },
	shouldScaleBackground: !1,
	setBackgroundColorOnScale: !0,
	noBodyStyles: !1,
	container: null,
	autoFocus: !1
}), c = () => {
	let e = t.useContext(s);
	if (!e) throw Error("useDrawerContext must be used within a Drawer.Root");
	return e;
};
o("[data-vaul-drawer]{touch-action:none;will-change:transform;transition:transform .5s cubic-bezier(.32, .72, 0, 1);animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=open]{animation-name:slideFromBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=bottom][data-state=closed]{animation-name:slideToBottom}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=open]{animation-name:slideFromTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=top][data-state=closed]{animation-name:slideToTop}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=open]{animation-name:slideFromLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=left][data-state=closed]{animation-name:slideToLeft}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=open]{animation-name:slideFromRight}[data-vaul-drawer][data-vaul-snap-points=false][data-vaul-drawer-direction=right][data-state=closed]{animation-name:slideToRight}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--initial-transform,100%),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}[data-vaul-drawer][data-vaul-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--initial-transform,100%),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=top]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=bottom]{transform:translate3d(0,var(--snap-point-height,0),0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=left]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-drawer][data-vaul-delayed-snap-points=true][data-vaul-drawer-direction=right]{transform:translate3d(var(--snap-point-height,0),0,0)}[data-vaul-overlay][data-vaul-snap-points=false]{animation-duration:.5s;animation-timing-function:cubic-bezier(0.32,0.72,0,1)}[data-vaul-overlay][data-vaul-snap-points=false][data-state=open]{animation-name:fadeIn}[data-vaul-overlay][data-state=closed]{animation-name:fadeOut}[data-vaul-animate=false]{animation:none!important}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:0;transition:opacity .5s cubic-bezier(.32, .72, 0, 1)}[data-vaul-overlay][data-vaul-snap-points=true]{opacity:1}[data-vaul-drawer]:not([data-vaul-custom-container=true])::after{content:'';position:absolute;background:inherit;background-color:inherit}[data-vaul-drawer][data-vaul-drawer-direction=top]::after{top:initial;bottom:100%;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=bottom]::after{top:100%;bottom:initial;left:0;right:0;height:200%}[data-vaul-drawer][data-vaul-drawer-direction=left]::after{left:initial;right:100%;top:0;bottom:0;width:200%}[data-vaul-drawer][data-vaul-drawer-direction=right]::after{left:100%;right:initial;top:0;bottom:0;width:200%}[data-vaul-overlay][data-vaul-snap-points=true]:not([data-vaul-snap-points-overlay=true]):not(\n[data-state=closed]\n){opacity:0}[data-vaul-overlay][data-vaul-snap-points-overlay=true]{opacity:1}[data-vaul-handle]{display:block;position:relative;opacity:.7;background:#e2e2e4;margin-left:auto;margin-right:auto;height:5px;width:32px;border-radius:1rem;touch-action:pan-y}[data-vaul-handle]:active,[data-vaul-handle]:hover{opacity:1}[data-vaul-handle-hitarea]{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:max(100%,2.75rem);height:max(100%,2.75rem);touch-action:inherit}@media (hover:hover) and (pointer:fine){[data-vaul-drawer]{user-select:none}}@media (pointer:fine){[data-vaul-handle-hitarea]:{width:100%;height:100%}}@keyframes fadeIn{from{opacity:0}to{opacity:1}}@keyframes fadeOut{to{opacity:0}}@keyframes slideFromBottom{from{transform:translate3d(0,var(--initial-transform,100%),0)}to{transform:translate3d(0,0,0)}}@keyframes slideToBottom{to{transform:translate3d(0,var(--initial-transform,100%),0)}}@keyframes slideFromTop{from{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}to{transform:translate3d(0,0,0)}}@keyframes slideToTop{to{transform:translate3d(0,calc(var(--initial-transform,100%) * -1),0)}}@keyframes slideFromLeft{from{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}to{transform:translate3d(0,0,0)}}@keyframes slideToLeft{to{transform:translate3d(calc(var(--initial-transform,100%) * -1),0,0)}}@keyframes slideFromRight{from{transform:translate3d(var(--initial-transform,100%),0,0)}to{transform:translate3d(0,0,0)}}@keyframes slideToRight{to{transform:translate3d(var(--initial-transform,100%),0,0)}}");
function l() {
	let e = navigator.userAgent;
	return typeof window < "u" && (/Firefox/.test(e) && /Mobile/.test(e) || /FxiOS/.test(e));
}
function u() {
	return h(/^Mac/);
}
function d() {
	return h(/^iPhone/);
}
function f() {
	return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
}
function p() {
	return h(/^iPad/) || u() && navigator.maxTouchPoints > 1;
}
function m() {
	return d() || p();
}
function h(e) {
	return typeof window < "u" && window.navigator != null ? e.test(window.navigator.platform) : void 0;
}
var g = 24, _ = typeof window < "u" ? r : n;
function v(...e) {
	return (...t) => {
		for (let n of e) typeof n == "function" && n(...t);
	};
}
var y = typeof document < "u" && window.visualViewport;
function b(e) {
	let t = window.getComputedStyle(e);
	return /(auto|scroll)/.test(t.overflow + t.overflowX + t.overflowY);
}
function x(e) {
	for (b(e) && (e = e.parentElement); e && !b(e);) e = e.parentElement;
	return e || document.scrollingElement || document.documentElement;
}
var S = new Set([
	"checkbox",
	"radio",
	"range",
	"color",
	"file",
	"image",
	"button",
	"submit",
	"reset"
]), C = 0, w;
function ee(e = {}) {
	let { isDisabled: t } = e;
	_(() => {
		if (!t) return C++, C === 1 && m() && (w = T()), () => {
			C--, C === 0 && w?.();
		};
	}, [t]);
}
function T() {
	let e, t = 0, n = (n) => {
		e = x(n.target), !(e === document.documentElement && e === document.body) && (t = n.changedTouches[0].pageY);
	}, r = (n) => {
		if (!e || e === document.documentElement || e === document.body) {
			n.preventDefault();
			return;
		}
		let r = n.changedTouches[0].pageY, i = e.scrollTop, a = e.scrollHeight - e.clientHeight;
		a !== 0 && ((i <= 0 && r > t || i >= a && r < t) && n.preventDefault(), t = r);
	}, i = (e) => {
		let t = e.target;
		k(t) && t !== document.activeElement && (e.preventDefault(), t.style.transform = "translateY(-2000px)", t.focus(), requestAnimationFrame(() => {
			t.style.transform = "";
		}));
	}, a = (e) => {
		let t = e.target;
		k(t) && (t.style.transform = "translateY(-2000px)", requestAnimationFrame(() => {
			t.style.transform = "", y && (y.height < window.innerHeight ? requestAnimationFrame(() => {
				O(t);
			}) : y.addEventListener("resize", () => O(t), { once: !0 }));
		}));
	}, o = () => {
		window.scrollTo(0, 0);
	}, s = window.pageXOffset, c = window.pageYOffset, l = v(E(document.documentElement, "paddingRight", `${window.innerWidth - document.documentElement.clientWidth}px`));
	window.scrollTo(0, 0);
	let u = v(D(document, "touchstart", n, {
		passive: !1,
		capture: !0
	}), D(document, "touchmove", r, {
		passive: !1,
		capture: !0
	}), D(document, "touchend", i, {
		passive: !1,
		capture: !0
	}), D(document, "focus", a, !0), D(window, "scroll", o));
	return () => {
		l(), u(), window.scrollTo(s, c);
	};
}
function E(e, t, n) {
	let r = e.style[t];
	return e.style[t] = n, () => {
		e.style[t] = r;
	};
}
function D(e, t, n, r) {
	return e.addEventListener(t, n, r), () => {
		e.removeEventListener(t, n, r);
	};
}
function O(e) {
	let t = document.scrollingElement || document.documentElement;
	for (; e && e !== t;) {
		let t = x(e);
		if (t !== document.documentElement && t !== document.body && t !== e) {
			let n = t.getBoundingClientRect().top, r = e.getBoundingClientRect().top;
			e.getBoundingClientRect().bottom > t.getBoundingClientRect().bottom + g && (t.scrollTop += r - n);
		}
		e = t.parentElement;
	}
}
function k(e) {
	return e instanceof HTMLInputElement && !S.has(e.type) || e instanceof HTMLTextAreaElement || e instanceof HTMLElement && e.isContentEditable;
}
function A(e, t) {
	typeof e == "function" ? e(t) : e != null && (e.current = t);
}
function te(...e) {
	return (t) => e.forEach((e) => A(e, t));
}
function ne(...t) {
	return e.useCallback(te(...t), t);
}
var j = /* @__PURE__ */ new WeakMap();
function M(e, t, n = !1) {
	if (!e || !(e instanceof HTMLElement)) return;
	let r = {};
	Object.entries(t).forEach(([t, n]) => {
		if (t.startsWith("--")) {
			e.style.setProperty(t, n);
			return;
		}
		r[t] = e.style[t], e.style[t] = n;
	}), !n && j.set(e, r);
}
function re(e, t) {
	if (!e || !(e instanceof HTMLElement)) return;
	let n = j.get(e);
	n && (e.style[t] = n[t]);
}
var N = (e) => {
	switch (e) {
		case "top":
		case "bottom": return !0;
		case "left":
		case "right": return !1;
		default: return e;
	}
};
function P(e, t) {
	if (!e) return null;
	let n = window.getComputedStyle(e), r = n.transform || n.webkitTransform || n.mozTransform, i = r.match(/^matrix3d\((.+)\)$/);
	return i ? parseFloat(i[1].split(", ")[N(t) ? 13 : 12]) : (i = r.match(/^matrix\((.+)\)$/), i ? parseFloat(i[1].split(", ")[N(t) ? 5 : 4]) : null);
}
function ie(e) {
	return 8 * (Math.log(e + 1) - 2);
}
function F(e, t) {
	if (!e) return () => {};
	let n = e.style.cssText;
	return Object.assign(e.style, t), () => {
		e.style.cssText = n;
	};
}
var I = {
	DURATION: .5,
	EASE: [
		.32,
		.72,
		0,
		1
	]
}, ae = .4, oe = .25, se = 100, ce = 8, L = 16, le = 26, ue = "vaul-dragging";
function R(e) {
	let n = t.useRef(e);
	return t.useEffect(() => {
		n.current = e;
	}), t.useMemo(() => (...e) => n.current == null ? void 0 : n.current.call(n, ...e), []);
}
function de({ defaultProp: e, onChange: n }) {
	let r = t.useState(e), [i] = r, a = t.useRef(i), o = R(n);
	return t.useEffect(() => {
		a.current !== i && (o(i), a.current = i);
	}, [
		i,
		a,
		o
	]), r;
}
function fe({ prop: e, defaultProp: n, onChange: r = () => {} }) {
	let [i, a] = de({
		defaultProp: n,
		onChange: r
	}), o = e !== void 0, s = o ? e : i, c = R(r);
	return [s, t.useCallback((t) => {
		if (o) {
			let n = typeof t == "function" ? t(e) : t;
			n !== e && c(n);
		} else a(t);
	}, [
		o,
		e,
		a,
		c
	])];
}
function pe({ activeSnapPointProp: e, setActiveSnapPointProp: n, snapPoints: r, drawerRef: i, overlayRef: a, fadeFromIndex: o, onSnapPointChange: s, direction: c = "bottom", container: l, snapToSequentialPoint: u }) {
	let [d, f] = fe({
		prop: e,
		defaultProp: r?.[0],
		onChange: n
	}), [p, m] = t.useState(typeof window < "u" ? {
		innerWidth: window.innerWidth,
		innerHeight: window.innerHeight
	} : void 0);
	t.useEffect(() => {
		function e() {
			m({
				innerWidth: window.innerWidth,
				innerHeight: window.innerHeight
			});
		}
		return window.addEventListener("resize", e), () => window.removeEventListener("resize", e);
	}, []);
	let h = t.useMemo(() => d === r?.[r.length - 1] || null, [r, d]), g = t.useMemo(() => r?.findIndex((e) => e === d) ?? null, [r, d]), _ = r && r.length > 0 && (o || o === 0) && !Number.isNaN(o) && r[o] === d || !r, v = t.useMemo(() => {
		let e = l ? {
			width: l.getBoundingClientRect().width,
			height: l.getBoundingClientRect().height
		} : typeof window < "u" ? {
			width: window.innerWidth,
			height: window.innerHeight
		} : {
			width: 0,
			height: 0
		};
		return r?.map((t) => {
			let n = typeof t == "string", r = 0;
			if (n && (r = parseInt(t, 10)), N(c)) {
				let i = n ? r : p ? t * e.height : 0;
				return p ? c === "bottom" ? e.height - i : -e.height + i : i;
			}
			let i = n ? r : p ? t * e.width : 0;
			return p ? c === "right" ? e.width - i : -e.width + i : i;
		}) ?? [];
	}, [
		r,
		p,
		l
	]), y = t.useMemo(() => g === null ? null : v?.[g], [v, g]), b = t.useCallback((e) => {
		let t = v?.findIndex((t) => t === e) ?? null;
		s(t), M(i.current, {
			transition: `transform ${I.DURATION}s cubic-bezier(${I.EASE.join(",")})`,
			transform: N(c) ? `translate3d(0, ${e}px, 0)` : `translate3d(${e}px, 0, 0)`
		}), v && t !== v.length - 1 && o !== void 0 && t !== o && t < o ? M(a.current, {
			transition: `opacity ${I.DURATION}s cubic-bezier(${I.EASE.join(",")})`,
			opacity: "0"
		}) : M(a.current, {
			transition: `opacity ${I.DURATION}s cubic-bezier(${I.EASE.join(",")})`,
			opacity: "1"
		}), f(r?.[Math.max(t, 0)]);
	}, [
		i.current,
		r,
		v,
		o,
		a,
		f
	]);
	t.useEffect(() => {
		if (d || e) {
			let t = r?.findIndex((t) => t === e || t === d) ?? -1;
			v && t !== -1 && typeof v[t] == "number" && b(v[t]);
		}
	}, [
		d,
		e,
		r,
		v,
		b
	]);
	function x({ draggedDistance: e, closeDrawer: t, velocity: n, dismissible: i }) {
		if (o === void 0) return;
		let s = c === "bottom" || c === "right" ? (y ?? 0) - e : (y ?? 0) + e, l = g === o - 1, d = g === 0, f = e > 0;
		if (l && M(a.current, { transition: `opacity ${I.DURATION}s cubic-bezier(${I.EASE.join(",")})` }), !u && n > 2 && !f) {
			i ? t() : b(v[0]);
			return;
		}
		if (!u && n > 2 && f && v && r) {
			b(v[r.length - 1]);
			return;
		}
		let p = v?.reduce((e, t) => typeof e != "number" || typeof t != "number" ? e : Math.abs(t - s) < Math.abs(e - s) ? t : e), m = N(c) ? window.innerHeight : window.innerWidth;
		if (n > ae && Math.abs(e) < m * .4) {
			let e = f ? 1 : -1;
			if (e > 0 && h && r) {
				b(v[r.length - 1]);
				return;
			}
			if (d && e < 0 && i && t(), g === null) return;
			b(v[g + e]);
			return;
		}
		b(p);
	}
	function S({ draggedDistance: e }) {
		if (y === null) return;
		let t = c === "bottom" || c === "right" ? y - e : y + e;
		(c === "bottom" || c === "right") && t < v[v.length - 1] || (c === "top" || c === "left") && t > v[v.length - 1] || M(i.current, { transform: N(c) ? `translate3d(0, ${t}px, 0)` : `translate3d(${t}px, 0, 0)` });
	}
	function C(e, t) {
		if (!r || typeof g != "number" || !v || o === void 0) return null;
		let n = g === o - 1;
		if (g >= o && t) return 0;
		if (n && !t) return 1;
		if (!_ && !n) return null;
		let i = n ? g + 1 : g - 1, a = n ? v[i] - v[i - 1] : v[i + 1] - v[i], s = e / Math.abs(a);
		return n ? 1 - s : s;
	}
	return {
		isLastSnapPoint: h,
		activeSnapPoint: d,
		shouldFade: _,
		getPercentageDragged: C,
		setActiveSnapPoint: f,
		activeSnapPointIndex: g,
		onRelease: x,
		onDrag: S,
		snapPointsOffset: v
	};
}
function me() {
	let { direction: e, isOpen: n, shouldScaleBackground: r, setBackgroundColorOnScale: a, noBodyStyles: o } = c(), s = t.useRef(null), l = i(() => document.body.style.backgroundColor, []);
	function u() {
		return (window.innerWidth - le) / window.innerWidth;
	}
	t.useEffect(() => {
		if (n && r) {
			s.current && clearTimeout(s.current);
			let t = document.querySelector("[data-vaul-drawer-wrapper]") || document.querySelector("[vaul-drawer-wrapper]");
			if (!t) return;
			a && !o && F(document.body, { background: "black" }), F(t, {
				transformOrigin: N(e) ? "top" : "left",
				transitionProperty: "transform, border-radius",
				transitionDuration: `${I.DURATION}s`,
				transitionTimingFunction: `cubic-bezier(${I.EASE.join(",")})`
			});
			let n = F(t, {
				borderRadius: `${ce}px`,
				overflow: "hidden",
				...N(e) ? { transform: `scale(${u()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)` } : { transform: `scale(${u()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)` }
			});
			return () => {
				n(), s.current = window.setTimeout(() => {
					l ? document.body.style.background = l : document.body.style.removeProperty("background");
				}, I.DURATION * 1e3);
			};
		}
	}, [
		n,
		r,
		l
	]);
}
var z = null;
function he({ isOpen: e, modal: n, nested: r, hasBeenOpened: i, preventScrollRestoration: a, noBodyStyles: o }) {
	let [s, c] = t.useState(() => typeof window < "u" ? window.location.href : ""), l = t.useRef(0), u = t.useCallback(() => {
		if (f() && z === null && e && !o) {
			z = {
				position: document.body.style.position,
				top: document.body.style.top,
				left: document.body.style.left,
				height: document.body.style.height,
				right: "unset"
			};
			let { scrollX: e, innerHeight: t } = window;
			document.body.style.setProperty("position", "fixed", "important"), Object.assign(document.body.style, {
				top: `${-l.current}px`,
				left: `${-e}px`,
				right: "0px",
				height: "auto"
			}), window.setTimeout(() => window.requestAnimationFrame(() => {
				let e = t - window.innerHeight;
				e && l.current >= t && (document.body.style.top = `${-(l.current + e)}px`);
			}), 300);
		}
	}, [e]), d = t.useCallback(() => {
		if (f() && z !== null && !o) {
			let e = -parseInt(document.body.style.top, 10), t = -parseInt(document.body.style.left, 10);
			Object.assign(document.body.style, z), window.requestAnimationFrame(() => {
				if (a && s !== window.location.href) {
					c(window.location.href);
					return;
				}
				window.scrollTo(t, e);
			}), z = null;
		}
	}, [s]);
	return t.useEffect(() => {
		function e() {
			l.current = window.scrollY;
		}
		return e(), window.addEventListener("scroll", e), () => {
			window.removeEventListener("scroll", e);
		};
	}, []), t.useEffect(() => {
		if (n) return () => {
			typeof document > "u" || document.querySelector("[data-vaul-drawer]") || d();
		};
	}, [n, d]), t.useEffect(() => {
		r || !i || (e ? (!window.matchMedia("(display-mode: standalone)").matches && u(), n || window.setTimeout(() => {
			d();
		}, 500)) : d());
	}, [
		e,
		i,
		s,
		n,
		r,
		u,
		d
	]), { restorePositionSetting: d };
}
function B({ open: e, onOpenChange: n, children: r, onDrag: i, onRelease: o, snapPoints: c, shouldScaleBackground: u = !1, setBackgroundColorOnScale: d = !0, closeThreshold: f = oe, scrollLockTimeout: p = se, dismissible: h = !0, handleOnly: g = !1, fadeFromIndex: _ = c && c.length - 1, activeSnapPoint: v, setActiveSnapPoint: y, fixed: b, modal: x = !0, onClose: S, nested: C, noBodyStyles: w = !1, direction: T = "bottom", defaultOpen: E = !1, disablePreventScroll: D = !0, snapToSequentialPoint: O = !1, preventScrollRestoration: A = !1, repositionInputs: te = !0, onAnimationEnd: ne, container: j, autoFocus: F = !1 }) {
	let [R = !1, de] = fe({
		defaultProp: E,
		prop: e,
		onChange: (e) => {
			n?.(e), !e && !C && je(), setTimeout(() => {
				ne?.(e);
			}, I.DURATION * 1e3), e && !x && typeof window < "u" && window.requestAnimationFrame(() => {
				document.body.style.pointerEvents = "auto";
			}), e || (document.body.style.pointerEvents = "auto");
		}
	}), [me, z] = t.useState(!1), [B, V] = t.useState(!1), [ge, _e] = t.useState(!1), H = t.useRef(null), U = t.useRef(null), W = t.useRef(null), G = t.useRef(null), K = t.useRef(null), q = t.useRef(!1), ve = t.useRef(null), ye = t.useRef(0), J = t.useRef(!1), be = t.useRef(!E), xe = t.useRef(0), Y = t.useRef(null), Se = t.useRef(Y.current?.getBoundingClientRect().height || 0), Ce = t.useRef(Y.current?.getBoundingClientRect().width || 0), we = t.useRef(0), { activeSnapPoint: Te, activeSnapPointIndex: X, setActiveSnapPoint: Ee, onRelease: De, snapPointsOffset: Z, onDrag: Oe, shouldFade: ke, getPercentageDragged: Ae } = pe({
		snapPoints: c,
		activeSnapPointProp: v,
		setActiveSnapPointProp: y,
		drawerRef: Y,
		fadeFromIndex: _,
		overlayRef: H,
		onSnapPointChange: t.useCallback((e) => {
			c && e === Z.length - 1 && (U.current = /* @__PURE__ */ new Date());
		}, []),
		direction: T,
		container: j,
		snapToSequentialPoint: O
	});
	ee({ isDisabled: !R || B || !x || ge || !me || !te || !D });
	let { restorePositionSetting: je } = he({
		isOpen: R,
		modal: x,
		nested: C ?? !1,
		hasBeenOpened: me,
		preventScrollRestoration: A,
		noBodyStyles: w
	});
	function Q() {
		return (window.innerWidth - le) / window.innerWidth;
	}
	function Me(e) {
		!h && !c || Y.current && !Y.current.contains(e.target) || (Se.current = Y.current?.getBoundingClientRect().height || 0, Ce.current = Y.current?.getBoundingClientRect().width || 0, V(!0), W.current = /* @__PURE__ */ new Date(), m() && window.addEventListener("touchend", () => q.current = !1, { once: !0 }), e.target.setPointerCapture(e.pointerId), ye.current = N(T) ? e.pageY : e.pageX);
	}
	function Ne(e, t) {
		let n = e, r = window.getSelection()?.toString(), i = Y.current ? P(Y.current, T) : null, a = /* @__PURE__ */ new Date();
		if (n.tagName === "SELECT" || n.hasAttribute("data-vaul-no-drag") || n.closest("[data-vaul-no-drag]")) return !1;
		if (T === "right" || T === "left") return !0;
		if (U.current && a.getTime() - U.current.getTime() < 500) return !1;
		if (i !== null && (T === "bottom" ? i > 0 : i < 0)) return !0;
		if (r && r.length > 0) return !1;
		if (K.current && a.getTime() - K.current.getTime() < p && i === 0 || t) return K.current = a, !1;
		for (; n;) {
			if (n.scrollHeight > n.clientHeight) {
				if (n.scrollTop !== 0) return K.current = /* @__PURE__ */ new Date(), !1;
				if (n.getAttribute("role") === "dialog") return !0;
			}
			n = n.parentNode;
		}
		return !0;
	}
	function Pe(e) {
		if (Y.current && B) {
			let t = T === "bottom" || T === "right" ? 1 : -1, n = (ye.current - (N(T) ? e.pageY : e.pageX)) * t, r = n > 0, a = c && !h && !r;
			if (a && X === 0) return;
			let o = Math.abs(n), s = document.querySelector("[data-vaul-drawer-wrapper]"), l = o / (T === "bottom" || T === "top" ? Se.current : Ce.current), d = Ae(o, r);
			if (d !== null && (l = d), a && l >= 1 || !q.current && !Ne(e.target, r)) return;
			if (Y.current.classList.add(ue), q.current = !0, M(Y.current, { transition: "none" }), M(H.current, { transition: "none" }), c && Oe({ draggedDistance: n }), r && !c) {
				let e = ie(n), r = Math.min(e * -1, 0) * t;
				M(Y.current, { transform: N(T) ? `translate3d(0, ${r}px, 0)` : `translate3d(${r}px, 0, 0)` });
				return;
			}
			let f = 1 - l;
			if ((ke || _ && X === _ - 1) && (i?.(e, l), M(H.current, {
				opacity: `${f}`,
				transition: "none"
			}, !0)), s && H.current && u) {
				let e = Math.min(Q() + l * (1 - Q()), 1), t = 8 - l * 8, n = Math.max(0, 14 - l * 14);
				M(s, {
					borderRadius: `${t}px`,
					transform: N(T) ? `scale(${e}) translate3d(0, ${n}px, 0)` : `scale(${e}) translate3d(${n}px, 0, 0)`,
					transition: "none"
				}, !0);
			}
			if (!c) {
				let e = o * t;
				M(Y.current, { transform: N(T) ? `translate3d(0, ${e}px, 0)` : `translate3d(${e}px, 0, 0)` });
			}
		}
	}
	t.useEffect(() => {
		window.requestAnimationFrame(() => {
			be.current = !0;
		});
	}, []), t.useEffect(() => {
		var e;
		function t() {
			if (!Y.current || !te) return;
			let e = document.activeElement;
			if (k(e) || J.current) {
				let e = window.visualViewport?.height || 0, t = window.innerHeight, n = t - e, r = Y.current.getBoundingClientRect().height || 0, i = r > t * .8;
				we.current ||= r;
				let a = Y.current.getBoundingClientRect().top;
				if (Math.abs(xe.current - n) > 60 && (J.current = !J.current), c && c.length > 0 && Z && X) {
					let e = Z[X] || 0;
					n += e;
				}
				if (xe.current = n, r > e || J.current) {
					let t = Y.current.getBoundingClientRect().height, r = t;
					t > e && (r = e - (i ? a : le)), b ? Y.current.style.height = `${t - Math.max(n, 0)}px` : Y.current.style.height = `${Math.max(r, e - a)}px`;
				} else l() || (Y.current.style.height = `${we.current}px`);
				c && c.length > 0 && !J.current ? Y.current.style.bottom = "0px" : Y.current.style.bottom = `${Math.max(n, 0)}px`;
			}
		}
		return (e = window.visualViewport) == null || e.addEventListener("resize", t), () => window.visualViewport?.removeEventListener("resize", t);
	}, [
		X,
		c,
		Z
	]);
	function $(e) {
		Ie(), S?.(), e || de(!1), setTimeout(() => {
			c && Ee(c[0]);
		}, I.DURATION * 1e3);
	}
	function Fe() {
		if (!Y.current) return;
		let e = document.querySelector("[data-vaul-drawer-wrapper]"), t = P(Y.current, T);
		M(Y.current, {
			transform: "translate3d(0, 0, 0)",
			transition: `transform ${I.DURATION}s cubic-bezier(${I.EASE.join(",")})`
		}), M(H.current, {
			transition: `opacity ${I.DURATION}s cubic-bezier(${I.EASE.join(",")})`,
			opacity: "1"
		}), u && t && t > 0 && R && M(e, {
			borderRadius: `${ce}px`,
			overflow: "hidden",
			...N(T) ? {
				transform: `scale(${Q()}) translate3d(0, calc(env(safe-area-inset-top) + 14px), 0)`,
				transformOrigin: "top"
			} : {
				transform: `scale(${Q()}) translate3d(calc(env(safe-area-inset-top) + 14px), 0, 0)`,
				transformOrigin: "left"
			},
			transitionProperty: "transform, border-radius",
			transitionDuration: `${I.DURATION}s`,
			transitionTimingFunction: `cubic-bezier(${I.EASE.join(",")})`
		}, !0);
	}
	function Ie() {
		!B || !Y.current || (Y.current.classList.remove(ue), q.current = !1, V(!1), G.current = /* @__PURE__ */ new Date());
	}
	function Le(e) {
		if (!B || !Y.current) return;
		Y.current.classList.remove(ue), q.current = !1, V(!1), G.current = /* @__PURE__ */ new Date();
		let t = P(Y.current, T);
		if (!e || !Ne(e.target, !1) || !t || Number.isNaN(t) || W.current === null) return;
		let n = G.current.getTime() - W.current.getTime(), r = ye.current - (N(T) ? e.pageY : e.pageX), i = Math.abs(r) / n;
		if (i > .05 && (_e(!0), setTimeout(() => {
			_e(!1);
		}, 200)), c) {
			De({
				draggedDistance: r * (T === "bottom" || T === "right" ? 1 : -1),
				closeDrawer: $,
				velocity: i,
				dismissible: h
			}), o?.(e, !0);
			return;
		}
		if (T === "bottom" || T === "right" ? r > 0 : r < 0) {
			Fe(), o?.(e, !0);
			return;
		}
		if (i > ae) {
			$(), o?.(e, !1);
			return;
		}
		let a = Math.min(Y.current.getBoundingClientRect().height ?? 0, window.innerHeight), s = Math.min(Y.current.getBoundingClientRect().width ?? 0, window.innerWidth);
		if (Math.abs(t) >= (T === "left" || T === "right" ? s : a) * f) {
			$(), o?.(e, !1);
			return;
		}
		o?.(e, !0), Fe();
	}
	t.useEffect(() => (R && (M(document.documentElement, { scrollBehavior: "auto" }), U.current = /* @__PURE__ */ new Date()), () => {
		re(document.documentElement, "scrollBehavior");
	}), [R]);
	function Re(e) {
		let t = e ? (window.innerWidth - L) / window.innerWidth : 1, n = e ? -L : 0;
		ve.current && window.clearTimeout(ve.current), M(Y.current, {
			transition: `transform ${I.DURATION}s cubic-bezier(${I.EASE.join(",")})`,
			transform: N(T) ? `scale(${t}) translate3d(0, ${n}px, 0)` : `scale(${t}) translate3d(${n}px, 0, 0)`
		}), !e && Y.current && (ve.current = setTimeout(() => {
			let e = P(Y.current, T);
			M(Y.current, {
				transition: "none",
				transform: N(T) ? `translate3d(0, ${e}px, 0)` : `translate3d(${e}px, 0, 0)`
			});
		}, 500));
	}
	function ze(e, t) {
		if (t < 0) return;
		let n = (window.innerWidth - L) / window.innerWidth, r = n + t * (1 - n), i = -L + t * L;
		M(Y.current, {
			transform: N(T) ? `scale(${r}) translate3d(0, ${i}px, 0)` : `scale(${r}) translate3d(${i}px, 0, 0)`,
			transition: "none"
		});
	}
	function Be(e, t) {
		let n = N(T) ? window.innerHeight : window.innerWidth, r = t ? (n - L) / n : 1, i = t ? -L : 0;
		t && M(Y.current, {
			transition: `transform ${I.DURATION}s cubic-bezier(${I.EASE.join(",")})`,
			transform: N(T) ? `scale(${r}) translate3d(0, ${i}px, 0)` : `scale(${r}) translate3d(${i}px, 0, 0)`
		});
	}
	return t.useEffect(() => {
		x || window.requestAnimationFrame(() => {
			document.body.style.pointerEvents = "auto";
		});
	}, [x]), /* @__PURE__ */ t.createElement(a.Root, {
		defaultOpen: E,
		onOpenChange: (e) => {
			!h && !e || (e ? z(!0) : $(!0), de(e));
		},
		open: R
	}, /* @__PURE__ */ t.createElement(s.Provider, { value: {
		activeSnapPoint: Te,
		snapPoints: c,
		setActiveSnapPoint: Ee,
		drawerRef: Y,
		overlayRef: H,
		onOpenChange: n,
		onPress: Me,
		onRelease: Le,
		onDrag: Pe,
		dismissible: h,
		shouldAnimate: be,
		handleOnly: g,
		isOpen: R,
		isDragging: B,
		shouldFade: ke,
		closeDrawer: $,
		onNestedDrag: ze,
		onNestedOpenChange: Re,
		onNestedRelease: Be,
		keyboardIsOpen: J,
		modal: x,
		snapPointsOffset: Z,
		activeSnapPointIndex: X,
		direction: T,
		shouldScaleBackground: u,
		setBackgroundColorOnScale: d,
		noBodyStyles: w,
		container: j,
		autoFocus: F
	} }, r));
}
var V = /* @__PURE__ */ t.forwardRef(function({ ...e }, n) {
	let { overlayRef: r, snapPoints: i, onRelease: o, shouldFade: s, isOpen: l, modal: u, shouldAnimate: d } = c(), f = ne(n, r), p = i && i.length > 0;
	if (!u) return null;
	let m = t.useCallback((e) => o(e), [o]);
	return /* @__PURE__ */ t.createElement(a.Overlay, {
		onMouseUp: m,
		ref: f,
		"data-vaul-overlay": "",
		"data-vaul-snap-points": l && p ? "true" : "false",
		"data-vaul-snap-points-overlay": l && s ? "true" : "false",
		"data-vaul-animate": d?.current ? "true" : "false",
		...e
	});
});
V.displayName = "Drawer.Overlay";
var ge = /* @__PURE__ */ t.forwardRef(function({ onPointerDownOutside: e, style: n, onOpenAutoFocus: r, ...i }, o) {
	let { drawerRef: s, onPress: l, onRelease: u, onDrag: d, keyboardIsOpen: f, snapPointsOffset: p, activeSnapPointIndex: m, modal: h, isOpen: g, direction: _, snapPoints: v, container: y, handleOnly: b, shouldAnimate: x, autoFocus: S } = c(), [C, w] = t.useState(!1), ee = ne(o, s), T = t.useRef(null), E = t.useRef(null), D = t.useRef(!1), O = v && v.length > 0;
	me();
	let k = (e, t, n = 0) => {
		if (D.current) return !0;
		let r = Math.abs(e.y), i = Math.abs(e.x), a = i > r, o = ["bottom", "right"].includes(t) ? 1 : -1;
		if (t === "left" || t === "right") {
			if (!(e.x * o < 0) && i >= 0 && i <= n) return a;
		} else if (!(e.y * o < 0) && r >= 0 && r <= n) return !a;
		return D.current = !0, !0;
	};
	t.useEffect(() => {
		O && window.requestAnimationFrame(() => {
			w(!0);
		});
	}, []);
	function A(e) {
		T.current = null, D.current = !1, u(e);
	}
	return /* @__PURE__ */ t.createElement(a.Content, {
		"data-vaul-drawer-direction": _,
		"data-vaul-drawer": "",
		"data-vaul-delayed-snap-points": C ? "true" : "false",
		"data-vaul-snap-points": g && O ? "true" : "false",
		"data-vaul-custom-container": y ? "true" : "false",
		"data-vaul-animate": x?.current ? "true" : "false",
		...i,
		ref: ee,
		style: p && p.length > 0 ? {
			"--snap-point-height": `${p[m ?? 0]}px`,
			...n
		} : n,
		onPointerDown: (e) => {
			b || (i.onPointerDown == null || i.onPointerDown.call(i, e), T.current = {
				x: e.pageX,
				y: e.pageY
			}, l(e));
		},
		onOpenAutoFocus: (e) => {
			r?.(e), S || e.preventDefault();
		},
		onPointerDownOutside: (t) => {
			if (e?.(t), !h || t.defaultPrevented) {
				t.preventDefault();
				return;
			}
			f.current &&= !1;
		},
		onFocusOutside: (e) => {
			if (!h) {
				e.preventDefault();
				return;
			}
		},
		onPointerMove: (e) => {
			if (E.current = e, b || (i.onPointerMove == null || i.onPointerMove.call(i, e), !T.current)) return;
			let t = e.pageY - T.current.y, n = e.pageX - T.current.x, r = e.pointerType === "touch" ? 10 : 2;
			k({
				x: n,
				y: t
			}, _, r) ? d(e) : (Math.abs(n) > r || Math.abs(t) > r) && (T.current = null);
		},
		onPointerUp: (e) => {
			i.onPointerUp == null || i.onPointerUp.call(i, e), T.current = null, D.current = !1, u(e);
		},
		onPointerOut: (e) => {
			i.onPointerOut == null || i.onPointerOut.call(i, e), A(E.current);
		},
		onContextMenu: (e) => {
			i.onContextMenu == null || i.onContextMenu.call(i, e), E.current && A(E.current);
		}
	});
});
ge.displayName = "Drawer.Content";
var _e = 250, H = 120, U = /* @__PURE__ */ t.forwardRef(function({ preventCycle: e = !1, children: n, ...r }, i) {
	let { closeDrawer: a, isDragging: o, snapPoints: s, activeSnapPoint: l, setActiveSnapPoint: u, dismissible: d, handleOnly: f, isOpen: p, onPress: m, onDrag: h } = c(), g = t.useRef(null), _ = t.useRef(!1);
	function v() {
		if (_.current) {
			x();
			return;
		}
		window.setTimeout(() => {
			y();
		}, H);
	}
	function y() {
		if (o || e || _.current) {
			x();
			return;
		}
		if (x(), !s || s.length === 0) {
			d || a();
			return;
		}
		if (l === s[s.length - 1] && d) {
			a();
			return;
		}
		let t = s.findIndex((e) => e === l);
		if (t === -1) return;
		let n = s[t + 1];
		u(n);
	}
	function b() {
		g.current = window.setTimeout(() => {
			_.current = !0;
		}, _e);
	}
	function x() {
		g.current && window.clearTimeout(g.current), _.current = !1;
	}
	return /* @__PURE__ */ t.createElement("div", {
		onClick: v,
		onPointerCancel: x,
		onPointerDown: (e) => {
			f && m(e), b();
		},
		onPointerMove: (e) => {
			f && h(e);
		},
		ref: i,
		"data-vaul-drawer-visible": p ? "true" : "false",
		"data-vaul-handle": "",
		"aria-hidden": "true",
		...r
	}, /* @__PURE__ */ t.createElement("span", {
		"data-vaul-handle-hitarea": "",
		"aria-hidden": "true"
	}, n));
});
U.displayName = "Drawer.Handle";
function W({ onDrag: e, onOpenChange: n, open: r, ...i }) {
	let { onNestedDrag: a, onNestedOpenChange: o, onNestedRelease: s } = c();
	if (!a) throw Error("Drawer.NestedRoot must be placed in another drawer");
	return /* @__PURE__ */ t.createElement(B, {
		nested: !0,
		open: r,
		onClose: () => {
			o(!1);
		},
		onDrag: (t, n) => {
			a(t, n), e?.(t, n);
		},
		onOpenChange: (e) => {
			e && o(e), n?.(e);
		},
		onRelease: s,
		...i
	});
}
function G(e) {
	let n = c(), { container: r = n.container, ...i } = e;
	return /* @__PURE__ */ t.createElement(a.Portal, {
		container: r,
		...i
	});
}
var K = {
	Root: B,
	NestedRoot: W,
	Content: ge,
	Overlay: V,
	Trigger: a.Trigger,
	Portal: G,
	Handle: U,
	Close: a.Close,
	Title: a.Title,
	Description: a.Description
};
//#endregion
export { K as Drawer };
