"use client";
import * as React$1 from "react";
import React, { useEffect, useLayoutEffect, useMemo } from "react";
import * as DialogPrimitive from "@radix-ui/react-dialog";
function __insertCSS(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 DrawerContext = React.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
}), useDrawerContext = () => {
	let e = React.useContext(DrawerContext);
	if (!e) throw Error("useDrawerContext must be used within a Drawer.Root");
	return e;
};
__insertCSS("[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 isMobileFirefox() {
	let e = navigator.userAgent;
	return typeof window < "u" && (/Firefox/.test(e) && /Mobile/.test(e) || /FxiOS/.test(e));
}
function isMac() {
	return testPlatform(/^Mac/);
}
function isIPhone() {
	return testPlatform(/^iPhone/);
}
function isSafari() {
	return /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
}
function isIPad() {
	return testPlatform(/^iPad/) || isMac() && navigator.maxTouchPoints > 1;
}
function isIOS() {
	return isIPhone() || isIPad();
}
function testPlatform(e) {
	return typeof window < "u" && window.navigator != null ? e.test(window.navigator.platform) : void 0;
}
var KEYBOARD_BUFFER = 24, useIsomorphicLayoutEffect = typeof window < "u" ? useLayoutEffect : useEffect;
function chain$1(...e) {
	return (...t) => {
		for (let n of e) typeof n == "function" && n(...t);
	};
}
var visualViewport = typeof document < "u" && window.visualViewport;
function isScrollable(e) {
	let t = window.getComputedStyle(e);
	return /(auto|scroll)/.test(t.overflow + t.overflowX + t.overflowY);
}
function getScrollParent(e) {
	for (isScrollable(e) && (e = e.parentElement); e && !isScrollable(e);) e = e.parentElement;
	return e || document.scrollingElement || document.documentElement;
}
var nonTextInputTypes = new Set([
	"checkbox",
	"radio",
	"range",
	"color",
	"file",
	"image",
	"button",
	"submit",
	"reset"
]), preventScrollCount = 0, restore;
function usePreventScroll(e = {}) {
	let { isDisabled: t } = e;
	useIsomorphicLayoutEffect(() => {
		if (!t) return preventScrollCount++, preventScrollCount === 1 && isIOS() && (restore = preventScrollMobileSafari()), () => {
			preventScrollCount--, preventScrollCount === 0 && restore?.();
		};
	}, [t]);
}
function preventScrollMobileSafari() {
	let e, t = 0, n = (n) => {
		e = getScrollParent(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;
		isInput(t) && t !== document.activeElement && (e.preventDefault(), t.style.transform = "translateY(-2000px)", t.focus(), requestAnimationFrame(() => {
			t.style.transform = "";
		}));
	}, a = (e) => {
		let t = e.target;
		isInput(t) && (t.style.transform = "translateY(-2000px)", requestAnimationFrame(() => {
			t.style.transform = "", visualViewport && (visualViewport.height < window.innerHeight ? requestAnimationFrame(() => {
				scrollIntoView(t);
			}) : visualViewport.addEventListener("resize", () => scrollIntoView(t), { once: !0 }));
		}));
	}, o = () => {
		window.scrollTo(0, 0);
	}, s = window.pageXOffset, c = window.pageYOffset, l = chain$1(setStyle(document.documentElement, "paddingRight", `${window.innerWidth - document.documentElement.clientWidth}px`));
	window.scrollTo(0, 0);
	let u = chain$1(addEvent(document, "touchstart", n, {
		passive: !1,
		capture: !0
	}), addEvent(document, "touchmove", r, {
		passive: !1,
		capture: !0
	}), addEvent(document, "touchend", i, {
		passive: !1,
		capture: !0
	}), addEvent(document, "focus", a, !0), addEvent(window, "scroll", o));
	return () => {
		l(), u(), window.scrollTo(s, c);
	};
}
function setStyle(e, t, n) {
	let r = e.style[t];
	return e.style[t] = n, () => {
		e.style[t] = r;
	};
}
function addEvent(e, t, n, r) {
	return e.addEventListener(t, n, r), () => {
		e.removeEventListener(t, n, r);
	};
}
function scrollIntoView(e) {
	let t = document.scrollingElement || document.documentElement;
	for (; e && e !== t;) {
		let t = getScrollParent(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 + KEYBOARD_BUFFER && (t.scrollTop += r - n);
		}
		e = t.parentElement;
	}
}
function isInput(e) {
	return e instanceof HTMLInputElement && !nonTextInputTypes.has(e.type) || e instanceof HTMLTextAreaElement || e instanceof HTMLElement && e.isContentEditable;
}
function setRef(e, t) {
	typeof e == "function" ? e(t) : e != null && (e.current = t);
}
function composeRefs(...e) {
	return (t) => e.forEach((e) => setRef(e, t));
}
function useComposedRefs(...t) {
	return React$1.useCallback(composeRefs(...t), t);
}
var cache = /* @__PURE__ */ new WeakMap();
function set(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 && cache.set(e, r);
}
function reset(e, t) {
	if (!e || !(e instanceof HTMLElement)) return;
	let n = cache.get(e);
	n && (e.style[t] = n[t]);
}
var isVertical = (e) => {
	switch (e) {
		case "top":
		case "bottom": return !0;
		case "left":
		case "right": return !1;
		default: return e;
	}
};
function getTranslate(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(", ")[isVertical(t) ? 13 : 12]) : (i = r.match(/^matrix\((.+)\)$/), i ? parseFloat(i[1].split(", ")[isVertical(t) ? 5 : 4]) : null);
}
function dampenValue(e) {
	return 8 * (Math.log(e + 1) - 2);
}
function assignStyle(e, t) {
	if (!e) return () => {};
	let n = e.style.cssText;
	return Object.assign(e.style, t), () => {
		e.style.cssText = n;
	};
}
var TRANSITIONS = {
	DURATION: .5,
	EASE: [
		.32,
		.72,
		0,
		1
	]
}, VELOCITY_THRESHOLD = .4, CLOSE_THRESHOLD = .25, SCROLL_LOCK_TIMEOUT = 100, BORDER_RADIUS = 8, NESTED_DISPLACEMENT = 16, WINDOW_TOP_OFFSET = 26, DRAG_CLASS = "vaul-dragging";
function useCallbackRef(e) {
	let n = React.useRef(e);
	return React.useEffect(() => {
		n.current = e;
	}), React.useMemo(() => (...e) => n.current == null ? void 0 : n.current.call(n, ...e), []);
}
function useUncontrolledState({ defaultProp: e, onChange: n }) {
	let r = React.useState(e), [i] = r, a = React.useRef(i), o = useCallbackRef(n);
	return React.useEffect(() => {
		a.current !== i && (o(i), a.current = i);
	}, [
		i,
		a,
		o
	]), r;
}
function useControllableState({ prop: e, defaultProp: n, onChange: r = () => {} }) {
	let [i, a] = useUncontrolledState({
		defaultProp: n,
		onChange: r
	}), o = e !== void 0, s = o ? e : i, c = useCallbackRef(r);
	return [s, React.useCallback((t) => {
		if (o) {
			let n = typeof t == "function" ? t(e) : t;
			n !== e && c(n);
		} else a(t);
	}, [
		o,
		e,
		a,
		c
	])];
}
function useSnapPoints({ activeSnapPointProp: e, setActiveSnapPointProp: n, snapPoints: r, drawerRef: i, overlayRef: a, fadeFromIndex: o, onSnapPointChange: s, direction: c = "bottom", container: l, snapToSequentialPoint: u }) {
	let [d, f] = useControllableState({
		prop: e,
		defaultProp: r?.[0],
		onChange: n
	}), [p, m] = React.useState(typeof window < "u" ? {
		innerWidth: window.innerWidth,
		innerHeight: window.innerHeight
	} : void 0);
	React.useEffect(() => {
		function e() {
			m({
				innerWidth: window.innerWidth,
				innerHeight: window.innerHeight
			});
		}
		return window.addEventListener("resize", e), () => window.removeEventListener("resize", e);
	}, []);
	let h = React.useMemo(() => d === r?.[r.length - 1] || null, [r, d]), g = React.useMemo(() => r?.findIndex((e) => e === d) ?? null, [r, d]), _ = r && r.length > 0 && (o || o === 0) && !Number.isNaN(o) && r[o] === d || !r, v = React.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)), isVertical(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 = React.useMemo(() => g === null ? null : v?.[g], [v, g]), b = React.useCallback((e) => {
		let t = v?.findIndex((t) => t === e) ?? null;
		s(t), set(i.current, {
			transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(",")})`,
			transform: isVertical(c) ? `translate3d(0, ${e}px, 0)` : `translate3d(${e}px, 0, 0)`
		}), v && t !== v.length - 1 && o !== void 0 && t !== o && t < o ? set(a.current, {
			transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(",")})`,
			opacity: "0"
		}) : set(a.current, {
			transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(",")})`,
			opacity: "1"
		}), f(r?.[Math.max(t, 0)]);
	}, [
		i.current,
		r,
		v,
		o,
		a,
		f
	]);
	React.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 && set(a.current, { transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.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 = isVertical(c) ? window.innerHeight : window.innerWidth;
		if (n > VELOCITY_THRESHOLD && 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] || set(i.current, { transform: isVertical(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 useScaleBackground() {
	let { direction: e, isOpen: n, shouldScaleBackground: r, setBackgroundColorOnScale: a, noBodyStyles: o } = useDrawerContext(), s = React.useRef(null), l = useMemo(() => document.body.style.backgroundColor, []);
	function u() {
		return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
	}
	React.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 && assignStyle(document.body, { background: "black" }), assignStyle(t, {
				transformOrigin: isVertical(e) ? "top" : "left",
				transitionProperty: "transform, border-radius",
				transitionDuration: `${TRANSITIONS.DURATION}s`,
				transitionTimingFunction: `cubic-bezier(${TRANSITIONS.EASE.join(",")})`
			});
			let n = assignStyle(t, {
				borderRadius: `${BORDER_RADIUS}px`,
				overflow: "hidden",
				...isVertical(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");
				}, TRANSITIONS.DURATION * 1e3);
			};
		}
	}, [
		n,
		r,
		l
	]);
}
var previousBodyPosition = null;
function usePositionFixed({ isOpen: e, modal: n, nested: r, hasBeenOpened: i, preventScrollRestoration: a, noBodyStyles: o }) {
	let [s, c] = React.useState(() => typeof window < "u" ? window.location.href : ""), l = React.useRef(0), u = React.useCallback(() => {
		if (isSafari() && previousBodyPosition === null && e && !o) {
			previousBodyPosition = {
				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 = React.useCallback(() => {
		if (isSafari() && previousBodyPosition !== null && !o) {
			let e = -parseInt(document.body.style.top, 10), t = -parseInt(document.body.style.left, 10);
			Object.assign(document.body.style, previousBodyPosition), window.requestAnimationFrame(() => {
				if (a && s !== window.location.href) {
					c(window.location.href);
					return;
				}
				window.scrollTo(t, e);
			}), previousBodyPosition = null;
		}
	}, [s]);
	return React.useEffect(() => {
		function e() {
			l.current = window.scrollY;
		}
		return e(), window.addEventListener("scroll", e), () => {
			window.removeEventListener("scroll", e);
		};
	}, []), React.useEffect(() => {
		if (n) return () => {
			typeof document > "u" || document.querySelector("[data-vaul-drawer]") || d();
		};
	}, [n, d]), React.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 Root({ open: e, onOpenChange: n, children: r, onDrag: i, onRelease: o, snapPoints: c, shouldScaleBackground: u = !1, setBackgroundColorOnScale: d = !0, closeThreshold: f = CLOSE_THRESHOLD, scrollLockTimeout: p = SCROLL_LOCK_TIMEOUT, 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: k = !1, repositionInputs: A = !0, onAnimationEnd: ve, container: j, autoFocus: ye = !1 }) {
	let [M = !1, N] = useControllableState({
		defaultProp: E,
		prop: e,
		onChange: (e) => {
			n?.(e), !e && !C && je(), setTimeout(() => {
				ve?.(e);
			}, TRANSITIONS.DURATION * 1e3), e && !x && typeof window < "u" && window.requestAnimationFrame(() => {
				document.body.style.pointerEvents = "auto";
			}), e || (document.body.style.pointerEvents = "auto");
		}
	}), [P, be] = React.useState(!1), [F, I] = React.useState(!1), [xe, L] = React.useState(!1), R = React.useRef(null), z = React.useRef(null), B = React.useRef(null), V = React.useRef(null), H = React.useRef(null), U = React.useRef(!1), W = React.useRef(null), G = React.useRef(0), K = React.useRef(!1), q = React.useRef(!E), Se = React.useRef(0), J = React.useRef(null), Ce = React.useRef(J.current?.getBoundingClientRect().height || 0), we = React.useRef(J.current?.getBoundingClientRect().width || 0), Te = React.useRef(0), { activeSnapPoint: Ee, activeSnapPointIndex: Y, setActiveSnapPoint: De, onRelease: Oe, snapPointsOffset: X, onDrag: ke, shouldFade: Z, getPercentageDragged: Ae } = useSnapPoints({
		snapPoints: c,
		activeSnapPointProp: v,
		setActiveSnapPointProp: y,
		drawerRef: J,
		fadeFromIndex: _,
		overlayRef: R,
		onSnapPointChange: React.useCallback((e) => {
			c && e === X.length - 1 && (z.current = /* @__PURE__ */ new Date());
		}, []),
		direction: T,
		container: j,
		snapToSequentialPoint: O
	});
	usePreventScroll({ isDisabled: !M || F || !x || xe || !P || !A || !D });
	let { restorePositionSetting: je } = usePositionFixed({
		isOpen: M,
		modal: x,
		nested: C ?? !1,
		hasBeenOpened: P,
		preventScrollRestoration: k,
		noBodyStyles: w
	});
	function Q() {
		return (window.innerWidth - WINDOW_TOP_OFFSET) / window.innerWidth;
	}
	function Me(e) {
		!h && !c || J.current && !J.current.contains(e.target) || (Ce.current = J.current?.getBoundingClientRect().height || 0, we.current = J.current?.getBoundingClientRect().width || 0, I(!0), B.current = /* @__PURE__ */ new Date(), isIOS() && window.addEventListener("touchend", () => U.current = !1, { once: !0 }), e.target.setPointerCapture(e.pointerId), G.current = isVertical(T) ? e.pageY : e.pageX);
	}
	function Ne(e, t) {
		let n = e, r = window.getSelection()?.toString(), i = J.current ? getTranslate(J.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 (z.current && a.getTime() - z.current.getTime() < 500) return !1;
		if (i !== null && (T === "bottom" ? i > 0 : i < 0)) return !0;
		if (r && r.length > 0) return !1;
		if (H.current && a.getTime() - H.current.getTime() < p && i === 0 || t) return H.current = a, !1;
		for (; n;) {
			if (n.scrollHeight > n.clientHeight) {
				if (n.scrollTop !== 0) return H.current = /* @__PURE__ */ new Date(), !1;
				if (n.getAttribute("role") === "dialog") return !0;
			}
			n = n.parentNode;
		}
		return !0;
	}
	function Pe(e) {
		if (J.current && F) {
			let t = T === "bottom" || T === "right" ? 1 : -1, n = (G.current - (isVertical(T) ? e.pageY : e.pageX)) * t, r = n > 0, a = c && !h && !r;
			if (a && Y === 0) return;
			let o = Math.abs(n), s = document.querySelector("[data-vaul-drawer-wrapper]"), l = o / (T === "bottom" || T === "top" ? Ce.current : we.current), d = Ae(o, r);
			if (d !== null && (l = d), a && l >= 1 || !U.current && !Ne(e.target, r)) return;
			if (J.current.classList.add(DRAG_CLASS), U.current = !0, set(J.current, { transition: "none" }), set(R.current, { transition: "none" }), c && ke({ draggedDistance: n }), r && !c) {
				let e = dampenValue(n), r = Math.min(e * -1, 0) * t;
				set(J.current, { transform: isVertical(T) ? `translate3d(0, ${r}px, 0)` : `translate3d(${r}px, 0, 0)` });
				return;
			}
			let f = 1 - l;
			if ((Z || _ && Y === _ - 1) && (i?.(e, l), set(R.current, {
				opacity: `${f}`,
				transition: "none"
			}, !0)), s && R.current && u) {
				let e = Math.min(Q() + l * (1 - Q()), 1), t = 8 - l * 8, n = Math.max(0, 14 - l * 14);
				set(s, {
					borderRadius: `${t}px`,
					transform: isVertical(T) ? `scale(${e}) translate3d(0, ${n}px, 0)` : `scale(${e}) translate3d(${n}px, 0, 0)`,
					transition: "none"
				}, !0);
			}
			if (!c) {
				let e = o * t;
				set(J.current, { transform: isVertical(T) ? `translate3d(0, ${e}px, 0)` : `translate3d(${e}px, 0, 0)` });
			}
		}
	}
	React.useEffect(() => {
		window.requestAnimationFrame(() => {
			q.current = !0;
		});
	}, []), React.useEffect(() => {
		var e;
		function t() {
			if (!J.current || !A) return;
			let e = document.activeElement;
			if (isInput(e) || K.current) {
				let e = window.visualViewport?.height || 0, t = window.innerHeight, n = t - e, r = J.current.getBoundingClientRect().height || 0, i = r > t * .8;
				Te.current ||= r;
				let a = J.current.getBoundingClientRect().top;
				if (Math.abs(Se.current - n) > 60 && (K.current = !K.current), c && c.length > 0 && X && Y) {
					let e = X[Y] || 0;
					n += e;
				}
				if (Se.current = n, r > e || K.current) {
					let t = J.current.getBoundingClientRect().height, r = t;
					t > e && (r = e - (i ? a : WINDOW_TOP_OFFSET)), b ? J.current.style.height = `${t - Math.max(n, 0)}px` : J.current.style.height = `${Math.max(r, e - a)}px`;
				} else isMobileFirefox() || (J.current.style.height = `${Te.current}px`);
				c && c.length > 0 && !K.current ? J.current.style.bottom = "0px" : J.current.style.bottom = `${Math.max(n, 0)}px`;
			}
		}
		return (e = window.visualViewport) == null || e.addEventListener("resize", t), () => window.visualViewport?.removeEventListener("resize", t);
	}, [
		Y,
		c,
		X
	]);
	function $(e) {
		Ie(), S?.(), e || N(!1), setTimeout(() => {
			c && De(c[0]);
		}, TRANSITIONS.DURATION * 1e3);
	}
	function Fe() {
		if (!J.current) return;
		let e = document.querySelector("[data-vaul-drawer-wrapper]"), t = getTranslate(J.current, T);
		set(J.current, {
			transform: "translate3d(0, 0, 0)",
			transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(",")})`
		}), set(R.current, {
			transition: `opacity ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(",")})`,
			opacity: "1"
		}), u && t && t > 0 && M && set(e, {
			borderRadius: `${BORDER_RADIUS}px`,
			overflow: "hidden",
			...isVertical(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: `${TRANSITIONS.DURATION}s`,
			transitionTimingFunction: `cubic-bezier(${TRANSITIONS.EASE.join(",")})`
		}, !0);
	}
	function Ie() {
		!F || !J.current || (J.current.classList.remove(DRAG_CLASS), U.current = !1, I(!1), V.current = /* @__PURE__ */ new Date());
	}
	function Le(e) {
		if (!F || !J.current) return;
		J.current.classList.remove(DRAG_CLASS), U.current = !1, I(!1), V.current = /* @__PURE__ */ new Date();
		let t = getTranslate(J.current, T);
		if (!e || !Ne(e.target, !1) || !t || Number.isNaN(t) || B.current === null) return;
		let n = V.current.getTime() - B.current.getTime(), r = G.current - (isVertical(T) ? e.pageY : e.pageX), i = Math.abs(r) / n;
		if (i > .05 && (L(!0), setTimeout(() => {
			L(!1);
		}, 200)), c) {
			Oe({
				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 > VELOCITY_THRESHOLD) {
			$(), o?.(e, !1);
			return;
		}
		let a = Math.min(J.current.getBoundingClientRect().height ?? 0, window.innerHeight), s = Math.min(J.current.getBoundingClientRect().width ?? 0, window.innerWidth), l = T === "left" || T === "right";
		if (Math.abs(t) >= (l ? s : a) * f) {
			$(), o?.(e, !1);
			return;
		}
		o?.(e, !0), Fe();
	}
	React.useEffect(() => (M && (set(document.documentElement, { scrollBehavior: "auto" }), z.current = /* @__PURE__ */ new Date()), () => {
		reset(document.documentElement, "scrollBehavior");
	}), [M]);
	function Re(e) {
		let t = e ? (window.innerWidth - NESTED_DISPLACEMENT) / window.innerWidth : 1, n = e ? -NESTED_DISPLACEMENT : 0;
		W.current && window.clearTimeout(W.current), set(J.current, {
			transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(",")})`,
			transform: isVertical(T) ? `scale(${t}) translate3d(0, ${n}px, 0)` : `scale(${t}) translate3d(${n}px, 0, 0)`
		}), !e && J.current && (W.current = setTimeout(() => {
			let e = getTranslate(J.current, T);
			set(J.current, {
				transition: "none",
				transform: isVertical(T) ? `translate3d(0, ${e}px, 0)` : `translate3d(${e}px, 0, 0)`
			});
		}, 500));
	}
	function ze(e, t) {
		if (t < 0) return;
		let n = (window.innerWidth - NESTED_DISPLACEMENT) / window.innerWidth, r = n + t * (1 - n), i = -NESTED_DISPLACEMENT + t * NESTED_DISPLACEMENT;
		set(J.current, {
			transform: isVertical(T) ? `scale(${r}) translate3d(0, ${i}px, 0)` : `scale(${r}) translate3d(${i}px, 0, 0)`,
			transition: "none"
		});
	}
	function Be(e, t) {
		let n = isVertical(T) ? window.innerHeight : window.innerWidth, r = t ? (n - NESTED_DISPLACEMENT) / n : 1, i = t ? -NESTED_DISPLACEMENT : 0;
		t && set(J.current, {
			transition: `transform ${TRANSITIONS.DURATION}s cubic-bezier(${TRANSITIONS.EASE.join(",")})`,
			transform: isVertical(T) ? `scale(${r}) translate3d(0, ${i}px, 0)` : `scale(${r}) translate3d(${i}px, 0, 0)`
		});
	}
	return React.useEffect(() => {
		x || window.requestAnimationFrame(() => {
			document.body.style.pointerEvents = "auto";
		});
	}, [x]), /* @__PURE__ */ React.createElement(DialogPrimitive.Root, {
		defaultOpen: E,
		onOpenChange: (e) => {
			!h && !e || (e ? be(!0) : $(!0), N(e));
		},
		open: M
	}, /* @__PURE__ */ React.createElement(DrawerContext.Provider, { value: {
		activeSnapPoint: Ee,
		snapPoints: c,
		setActiveSnapPoint: De,
		drawerRef: J,
		overlayRef: R,
		onOpenChange: n,
		onPress: Me,
		onRelease: Le,
		onDrag: Pe,
		dismissible: h,
		shouldAnimate: q,
		handleOnly: g,
		isOpen: M,
		isDragging: F,
		shouldFade: Z,
		closeDrawer: $,
		onNestedDrag: ze,
		onNestedOpenChange: Re,
		onNestedRelease: Be,
		keyboardIsOpen: K,
		modal: x,
		snapPointsOffset: X,
		activeSnapPointIndex: Y,
		direction: T,
		shouldScaleBackground: u,
		setBackgroundColorOnScale: d,
		noBodyStyles: w,
		container: j,
		autoFocus: ye
	} }, r));
}
var Overlay = /* @__PURE__ */ React.forwardRef(function({ ...e }, n) {
	let { overlayRef: r, snapPoints: i, onRelease: o, shouldFade: s, isOpen: l, modal: u, shouldAnimate: d } = useDrawerContext(), f = useComposedRefs(n, r), p = i && i.length > 0;
	if (!u) return null;
	let m = React.useCallback((e) => o(e), [o]);
	return /* @__PURE__ */ React.createElement(DialogPrimitive.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
	});
});
Overlay.displayName = "Drawer.Overlay";
var Content = /* @__PURE__ */ React.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 } = useDrawerContext(), [C, w] = React.useState(!1), ge = useComposedRefs(o, s), T = React.useRef(null), E = React.useRef(null), D = React.useRef(!1), O = v && v.length > 0;
	useScaleBackground();
	let _e = (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;
	};
	React.useEffect(() => {
		O && window.requestAnimationFrame(() => {
			w(!0);
		});
	}, []);
	function k(e) {
		T.current = null, D.current = !1, u(e);
	}
	return /* @__PURE__ */ React.createElement(DialogPrimitive.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: ge,
		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;
			_e({
				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), k(E.current);
		},
		onContextMenu: (e) => {
			i.onContextMenu == null || i.onContextMenu.call(i, e), E.current && k(E.current);
		}
	});
});
Content.displayName = "Drawer.Content";
var LONG_HANDLE_PRESS_TIMEOUT = 250, DOUBLE_TAP_TIMEOUT = 120, Handle = /* @__PURE__ */ React.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 } = useDrawerContext(), g = React.useRef(null), _ = React.useRef(!1);
	function v() {
		if (_.current) {
			x();
			return;
		}
		window.setTimeout(() => {
			y();
		}, DOUBLE_TAP_TIMEOUT);
	}
	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;
		}, LONG_HANDLE_PRESS_TIMEOUT);
	}
	function x() {
		g.current && window.clearTimeout(g.current), _.current = !1;
	}
	return /* @__PURE__ */ React.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__ */ React.createElement("span", {
		"data-vaul-handle-hitarea": "",
		"aria-hidden": "true"
	}, n));
});
Handle.displayName = "Drawer.Handle";
function NestedRoot({ onDrag: e, onOpenChange: n, open: r, ...i }) {
	let { onNestedDrag: a, onNestedOpenChange: o, onNestedRelease: s } = useDrawerContext();
	if (!a) throw Error("Drawer.NestedRoot must be placed in another drawer");
	return /* @__PURE__ */ React.createElement(Root, {
		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 Portal(e) {
	let n = useDrawerContext(), { container: r = n.container, ...i } = e;
	return /* @__PURE__ */ React.createElement(DialogPrimitive.Portal, {
		container: r,
		...i
	});
}
var Drawer = {
	Root,
	NestedRoot,
	Content,
	Overlay,
	Trigger: DialogPrimitive.Trigger,
	Portal,
	Handle,
	Close: DialogPrimitive.Close,
	Title: DialogPrimitive.Title,
	Description: DialogPrimitive.Description
};
export { Drawer };
