"use client";
import { t as e } from "./useIsoLayoutEffect-CKOv1bV_.js";
import { t } from "./useStableCallback-CqEVb76s.js";
import { c as n, m as r, t as i } from "./createBaseUIEventDetails-ChcQXp54.js";
import { n as a } from "./useAnimationFrame-xwbX87TY.js";
import { f as o, l as s } from "./floating-ui.utils.dom-5U5b4xPf.js";
import { i as c, n as l, r as u, t as d } from "./constants-VB9bsA8p.js";
import { n as f, r as p, t as m } from "./shadowDom-C-4Ejp9R.js";
import { c as h, r as g } from "./shim-ieZ_MRlN.js";
import { O as _, k as v } from "./popupStateMapping-PdIQcWEz.js";
import { a as ee, i as te, o as y } from "./event-DWcDp5kt.js";
import { a as b, c as x, i as ne, l as re, n as S, o as ie, r as ae, s as oe, t as se, u as ce } from "./composite-HOje5ugx.js";
import { t as le } from "./owner-BrzQrszh.js";
import { t as C } from "./useValueAsRef-CCU3eUYq.js";
import { n as w } from "./useTimeout-B1x6NSZb.js";
import { o as ue } from "./useOpenInteractionType-D-ymktmc.js";
import * as T from "react";
//#region ../../node_modules/.bun/@base-ui+react@1.5.0+f4ada88178b00e6f/node_modules/@base-ui/react/esm/floating-ui-react/hooks/useListNavigation.js
var E = "Escape";
function D(e, t, n) {
	switch (e) {
		case "vertical": return t;
		case "horizontal": return n;
		default: return t || n;
	}
}
function O(e, t) {
	return D(t, e === "ArrowUp" || e === "ArrowDown", e === "ArrowLeft" || e === "ArrowRight");
}
function de(e, t, n) {
	return D(t, e === "ArrowDown", n ? e === "ArrowLeft" : e === "ArrowRight") || e === "Enter" || e === " " || e === "";
}
function fe(e, t, n) {
	return D(t, n ? e === l : e === u, e === d);
}
function pe(e, t, n, r) {
	return t === "both" || t === "horizontal" && r && r > 1 ? e === E : D(t, n ? e === u : e === l, e === c);
}
function k(s, c) {
	let { listRef: l, activeIndex: u, onNavigate: d = () => {}, enabled: x = !0, selectedIndex: w = null, allowEscape: E = !1, loopFocus: D = !1, nested: k = !1, rtl: A = !1, virtual: j = !1, focusItemOnOpen: M = "auto", focusItemOnHover: me = !0, openOnArrowKeyDown: he = !0, disabledIndices: N = void 0, orientation: P = "vertical", parentOrientation: ge, cols: F = 1, id: _e, resetOnPointerLeave: ve = !0, externalTree: ye } = c;
	process.env.NODE_ENV !== "production" && (E && (D || console.warn("`useListNavigation` looping must be enabled to allow escaping."), j || console.warn("`useListNavigation` must be virtual to allow escaping.")), P === "vertical" && F > 1 && console.warn("In grid list navigation mode (`cols` > 1), the `orientation` should", "be either \"horizontal\" or \"both\"."));
	let I = "rootStore" in s ? s.rootStore : s, L = I.useState("open"), R = I.useState("floatingElement"), z = I.useState("domReferenceElement"), be = I.context.dataRef, xe = g(R), Se = h(z), B = C(xe), Ce = _(), V = v(ye), H = T.useRef(M), U = T.useRef(w ?? -1), W = T.useRef(null), G = T.useRef(!0), K = t((e) => {
		d(U.current === -1 ? null : U.current, e);
	}), we = T.useRef(K), q = T.useRef(!!R), Te = T.useRef(L), J = T.useRef(!1), Y = T.useRef(!1), Ee = T.useRef(null), De = C(N), X = C(L), Z = C(w), Oe = C(ve), ke = a(), Ae = a(), je = t(() => {
		function e(e) {
			j ? V?.events.emit("virtualfocus", e) : Ee.current = ue(e, {
				sync: J.current,
				preventScroll: !0
			});
		}
		let t = l.current[U.current], n = Y.current;
		t && e(t), (J.current ? (e) => e() : (e) => ke.request(e))(() => {
			let r = l.current[U.current] || t;
			r && (t || e(r), Fe && (n || !G.current) && r.scrollIntoView?.({
				block: "nearest",
				inline: "nearest"
			}));
		});
	});
	e(() => {
		be.current.orientation = P;
	}, [be, P]), e(() => {
		x && (L && R ? (U.current = w ?? -1, H.current && w != null && (Y.current = !0, K())) : q.current && (U.current = -1, we.current()));
	}, [
		x,
		L,
		R,
		w,
		K
	]), e(() => {
		if (x) {
			if (!L) {
				J.current = !1;
				return;
			}
			if (R) if (u == null) {
				if (J.current = !1, Z.current != null) return;
				if (q.current && (U.current = -1, je()), (!Te.current || !q.current) && H.current && (W.current != null || H.current === !0 && W.current == null)) {
					let e = 0, t = () => {
						l.current[0] == null ? (e < 2 && (e ? (e) => Ae.request(e) : queueMicrotask)(t), e += 1) : (U.current = W.current == null || de(W.current, P, A) || k ? oe(l) : ie(l), W.current = null, K());
					};
					t();
				}
			} else re(l.current, u) || (U.current = u, je(), Y.current = !1);
		}
	}, [
		x,
		L,
		R,
		u,
		Z,
		k,
		l,
		P,
		A,
		K,
		je,
		Ae
	]), e(() => {
		if (!x || R || !V || j || !q.current) return;
		let e = V.nodesRef.current, t = e.find((e) => e.id === Ce)?.context?.elements.floating, n = m(le(R)), r = e.some((e) => e.context && f(e.context.elements.floating, n));
		t && !r && G.current && t.focus({ preventScroll: !0 });
	}, [
		x,
		R,
		V,
		Ce,
		j
	]), e(() => {
		we.current = K, Te.current = L, q.current = !!R;
	}), e(() => {
		L || (W.current = null, H.current = M);
	}, [L, M]);
	let Me = u != null, Ne = t((e) => {
		if (!X.current) return;
		let t = l.current.indexOf(e.currentTarget);
		t !== -1 && (U.current !== t || u !== t) && (U.current = t, K(e));
	}), Q = t(() => ge ?? V?.nodesRef.current.find((e) => e.id === Ce)?.context?.dataRef?.current.orientation), Pe = t(() => oe(l, De.current)), $ = t((e) => {
		if (G.current = !1, J.current = !0, e.which === 229 || !X.current && e.currentTarget === B.current) return;
		if (k && pe(e.key, P, A, F)) {
			O(e.key, Q()) || y(e), I.setOpen(!1, i(r, e.nativeEvent)), o(z) && (j ? V?.events.emit("virtualfocus", z) : z.focus());
			return;
		}
		let t = U.current, n = oe(l, N), a = ie(l, N);
		if (Se || (e.key === "Home" && (y(e), U.current = n, K(e)), e.key === "End" && (y(e), U.current = a, K(e))), F > 1) {
			let t = Array.from({ length: l.current.length }, () => ({
				width: 1,
				height: 1
			})), r = se(t, F, !1), i = r.findIndex((e) => e != null && !ce(l.current, e, N)), o = r.reduce((e, t, n) => t != null && !ce(l.current, t, N) ? n : e, -1), s = r[b(r.map((e) => e == null ? null : l.current[e]), {
				event: e,
				orientation: P,
				loopFocus: D,
				rtl: A,
				cols: F,
				disabledIndices: ne([...(typeof N == "function" ? null : N) || l.current.map((e, t) => ce(l.current, t, N) ? t : void 0), void 0], r),
				minIndex: i,
				maxIndex: o,
				prevIndex: ae(U.current > a ? n : U.current, t, r, F, e.key === "ArrowDown" ? "bl" : e.key === (A ? "ArrowLeft" : "ArrowRight") ? "tr" : "tl"),
				stopEvent: !0
			})];
			if (s != null && (U.current = s, K(e)), P === "both") return;
		}
		if (O(e.key, P)) {
			if (y(e), L && !j && m(e.currentTarget.ownerDocument) === e.currentTarget) {
				U.current = de(e.key, P, A) ? n : a, K(e);
				return;
			}
			de(e.key, P, A) ? D ? t >= a ? E && t !== l.current.length ? U.current = -1 : (J.current = !1, U.current = n) : U.current = S(l.current, {
				startingIndex: t,
				disabledIndices: N
			}) : U.current = Math.min(a, S(l.current, {
				startingIndex: t,
				disabledIndices: N
			})) : D ? t <= n ? E && t !== -1 ? U.current = l.current.length : (J.current = !1, U.current = a) : U.current = S(l.current, {
				startingIndex: t,
				decrement: !0,
				disabledIndices: N
			}) : U.current = Math.max(n, S(l.current, {
				startingIndex: t,
				decrement: !0,
				disabledIndices: N
			})), re(l.current, U.current) && (U.current = -1), K(e);
		}
	}), Fe = T.useMemo(() => ({
		onFocus(e) {
			J.current = !0, Ne(e);
		},
		onClick: ({ currentTarget: e }) => e.focus({ preventScroll: !0 }),
		onMouseMove(e) {
			J.current = !0, Y.current = !1, me && Ne(e);
		},
		onPointerLeave(e) {
			if (!X.current || !G.current || e.pointerType === "touch") return;
			J.current = !0;
			let t = e.relatedTarget;
			if (!(!me || l.current.includes(t)) && Oe.current && (Ee.current?.(), Ee.current = null, U.current = -1, K(e), !j)) {
				let e = B.current, t = m(le(e));
				e && f(e, t) && e.focus({ preventScroll: !0 });
			}
		}
	}), [
		Ne,
		X,
		B,
		me,
		l,
		K,
		Oe,
		j
	]), Ie = T.useMemo(() => j && L && Me && { "aria-activedescendant": `${_e}-${u}` }, [
		j,
		L,
		Me,
		_e,
		u
	]), Le = T.useMemo(() => ({
		"aria-orientation": P === "both" ? void 0 : P,
		...Se ? {} : Ie,
		onKeyDown(e) {
			if (e.key === "Tab" && e.shiftKey && L && !j) {
				let t = p(e.nativeEvent);
				if (t && !f(B.current, t)) return;
				y(e), I.setOpen(!1, i(n, e.nativeEvent)), o(z) && z.focus();
				return;
			}
			$(e);
		},
		onPointerMove() {
			G.current = !0;
		}
	}), [
		Ie,
		$,
		B,
		P,
		Se,
		I,
		L,
		j,
		z
	]), Re = T.useMemo(() => {
		function e(e) {
			I.setOpen(!0, i(r, e.nativeEvent, e.currentTarget));
		}
		function t(e) {
			M === "auto" && te(e.nativeEvent) && (H.current = !j);
		}
		function n(e) {
			H.current = M, M === "auto" && ee(e.nativeEvent) && (H.current = !0);
		}
		return {
			onKeyDown(t) {
				let n = I.select("open");
				G.current = !1;
				let r = t.key.startsWith("Arrow"), i = fe(t.key, Q(), A), a = O(t.key, P), o = (k ? i : a) || t.key === "Enter" || t.key.trim() === "";
				if (j && n) return $(t);
				if (!(!n && !he && r)) {
					if (o) {
						let e = O(t.key, Q());
						W.current = k && e ? null : t.key;
					}
					if (k) {
						i && (y(t), n ? (U.current = Pe(), K(t)) : e(t));
						return;
					}
					a && (Z.current != null && (U.current = Z.current), y(t), !n && he ? e(t) : $(t), n && K(t));
				}
			},
			onFocus(e) {
				I.select("open") && !j && (U.current = -1, K(e));
			},
			onPointerDown: n,
			onPointerEnter: n,
			onMouseDown: t,
			onClick: t
		};
	}, [
		$,
		M,
		Pe,
		k,
		K,
		I,
		he,
		P,
		Q,
		A,
		Z,
		j
	]), ze = T.useMemo(() => ({
		...Ie,
		...Re
	}), [Ie, Re]);
	return T.useMemo(() => x ? {
		reference: ze,
		floating: Le,
		item: Fe,
		trigger: Re
	} : {}, [
		x,
		ze,
		Le,
		Re,
		Fe
	]);
}
//#endregion
//#region ../../node_modules/.bun/@base-ui+react@1.5.0+f4ada88178b00e6f/node_modules/@base-ui/react/esm/floating-ui-react/hooks/useTypeahead.js
function A(n, r) {
	let { listRef: i, elementsRef: a, activeIndex: o, onMatch: s, onTyping: c, enabled: l = !0, resetMs: u = 750, selectedIndex: d = null } = r, p = "rootStore" in n ? n.rootStore : n, m = p.useState("open"), h = w(), g = T.useRef(""), _ = T.useRef(d ?? o ?? -1), v = T.useRef(null), ee = t((e) => {
		function t(e) {
			let t = a?.current[e];
			return !t || x(t);
		}
		function n(e, n, r = 0) {
			if (e.length === 0) return -1;
			let i = (r % e.length + e.length) % e.length, a = n.toLocaleLowerCase();
			for (let n = 0; n < e.length; n += 1) {
				let r = (i + n) % e.length;
				if (!(!e[r]?.toLocaleLowerCase().startsWith(a) || !t(r))) return r;
			}
			return -1;
		}
		let r = i.current;
		if (g.current.length > 0 && e.key === " " && (y(e), c?.(!0)), g.current.length > 0 && g.current[0] !== " " && n(r, g.current) === -1 && e.key !== " " && c?.(!1), r == null || e.key.length !== 1 || e.ctrlKey || e.metaKey || e.altKey) return;
		m && e.key !== " " && (y(e), c?.(!0));
		let l = g.current === "";
		l && (_.current = d ?? o ?? -1), r.every((e) => e ? e[0]?.toLocaleLowerCase() !== e[1]?.toLocaleLowerCase() : !0) && g.current === e.key && (g.current = "", _.current = v.current), g.current += e.key, h.start(u, () => {
			g.current = "", _.current = v.current, c?.(!1);
		});
		let f = ((l ? d ?? o ?? -1 : _.current) ?? 0) + 1, p = n(r, g.current, f);
		p === -1 ? e.key !== " " && (g.current = "", c?.(!1)) : (s?.(p), v.current = p);
	}), te = t((e) => {
		let t = e.relatedTarget, n = p.select("domReferenceElement"), r = p.select("floatingElement");
		f(n, t) || f(r, t) || (h.clear(), g.current = "", _.current = v.current, c?.(!1));
	});
	e(() => {
		!m && d !== null || (h.clear(), v.current = null, g.current !== "" && (g.current = ""));
	}, [
		m,
		d,
		h
	]), e(() => {
		m && g.current === "" && (_.current = d ?? o ?? -1);
	}, [
		m,
		d,
		o
	]);
	let b = T.useMemo(() => ({
		onKeyDown: ee,
		onBlur: te
	}), [ee, te]);
	return T.useMemo(() => l ? {
		reference: b,
		floating: b
	} : {}, [l, b]);
}
//#endregion
//#region ../../node_modules/.bun/@base-ui+react@1.5.0+f4ada88178b00e6f/node_modules/@base-ui/react/esm/utils/getPseudoElementBounds.js
function j(e) {
	let t = e.getBoundingClientRect();
	if (process.env.NODE_ENV !== "production") return t;
	let n = s(e), r = n.getComputedStyle(e, "::before"), i = n.getComputedStyle(e, "::after");
	if (!(r.content !== "none" || i.content !== "none")) return t;
	let a = parseFloat(r.width) || 0, o = parseFloat(r.height) || 0, c = parseFloat(i.width) || 0, l = parseFloat(i.height) || 0, u = Math.max(t.width, a, c), d = Math.max(t.height, o, l), f = u - t.width, p = d - t.height;
	return {
		left: t.left - f / 2,
		right: t.right + f / 2,
		top: t.top - p / 2,
		bottom: t.bottom + p / 2
	};
}
//#endregion
export { A as n, k as r, j as t };
