"use client";
import { t as e } from "./useIsoLayoutEffect-CKOv1bV_.js";
import { f as t } from "./useRenderElement-CmuWsiNa.js";
import { t as n } from "./useStableCallback-CqEVb76s.js";
import { t as r, x as i } from "./createBaseUIEventDetails-ChcQXp54.js";
import { t as a } from "./useOnMount-Dirf6DNj.js";
import { d as o } from "./floating-ui.utils.dom-5U5b4xPf.js";
import { n as s, r as c } from "./shadowDom-C-4Ejp9R.js";
import { a as l, s as u } from "./shim-ieZ_MRlN.js";
import { B as d, O as f, Z as p, k as m } from "./popupStateMapping-PdIQcWEz.js";
import { n as h } from "./event-DWcDp5kt.js";
import { t as g } from "./owner-BrzQrszh.js";
import { t as _ } from "./addEventListener-B4Gs94GY.js";
import { t as v } from "./useValueAsRef-CCU3eUYq.js";
import { n as y, t as b } from "./useTimeout-B1x6NSZb.js";
import * as x from "react";
import * as S from "react-dom";
//#region ../../node_modules/.bun/@base-ui+react@1.5.0+f4ada88178b00e6f/node_modules/@base-ui/react/esm/floating-ui-react/hooks/useHoverShared.js
function C(e, t) {
	return t != null && !h(t) ? 0 : typeof e == "function" ? e() : e;
}
function w(e, t, n) {
	let r = C(e, n);
	return typeof r == "number" ? r : r?.[t];
}
function T(e) {
	return typeof e == "function" ? e() : e;
}
function E(e, t) {
	return t || e === "click" || e === "mousedown";
}
function D(e) {
	return e?.includes("mouse") && e !== "mousedown";
}
//#endregion
//#region ../../node_modules/.bun/@base-ui+react@1.5.0+f4ada88178b00e6f/node_modules/@base-ui/react/esm/floating-ui-react/hooks/useHoverInteractionSharedState.js
var O = class e {
	constructor() {
		this.pointerType = void 0, this.interactedInside = !1, this.handler = void 0, this.blockMouseMove = !0, this.performedPointerEventsMutation = !1, this.pointerEventsScopeElement = null, this.pointerEventsReferenceElement = null, this.pointerEventsFloatingElement = null, this.restTimeoutPending = !1, this.openChangeTimeout = new b(), this.restTimeout = new b(), this.handleCloseOptions = void 0;
	}
	static create() {
		return new e();
	}
	dispose = () => {
		this.openChangeTimeout.clear(), this.restTimeout.clear();
	};
	disposeEffect = () => this.dispose;
}, k = /* @__PURE__ */ new WeakMap();
function A(e) {
	if (!e.performedPointerEventsMutation) return;
	let t = e.pointerEventsScopeElement;
	t && k.get(t) === e && (e.pointerEventsScopeElement?.style.removeProperty("pointer-events"), e.pointerEventsReferenceElement?.style.removeProperty("pointer-events"), e.pointerEventsFloatingElement?.style.removeProperty("pointer-events"), k.delete(t)), e.performedPointerEventsMutation = !1, e.pointerEventsScopeElement = null, e.pointerEventsReferenceElement = null, e.pointerEventsFloatingElement = null;
}
function j(e, t) {
	let { scopeElement: n, referenceElement: r, floatingElement: i } = t, a = k.get(n);
	a && a !== e && A(a), A(e), e.performedPointerEventsMutation = !0, e.pointerEventsScopeElement = n, e.pointerEventsReferenceElement = r, e.pointerEventsFloatingElement = i, k.set(n, e), n.style.pointerEvents = "none", r.style.pointerEvents = "auto", i.style.pointerEvents = "auto";
}
function M(e) {
	let n = e.context.dataRef.current, r = t(() => n.hoverInteractionState ?? O.create()).current;
	return n.hoverInteractionState ||= r, a(n.hoverInteractionState.disposeEffect), n.hoverInteractionState;
}
//#endregion
//#region ../../node_modules/.bun/@base-ui+react@1.5.0+f4ada88178b00e6f/node_modules/@base-ui/react/esm/floating-ui-react/hooks/useHoverFloatingInteraction.js
function N(t, a = {}) {
	let { enabled: h = !0, closeDelay: v = 0, nodeId: b } = a, S = "rootStore" in t ? t.rootStore : t, C = S.useState("open"), T = S.useState("floatingElement"), O = S.useState("domReferenceElement"), { dataRef: k } = S.context, N = m(), P = f(), F = M(S), I = y(), L = n(() => E(k.current.openEvent?.type, F.interactedInside)), R = n(() => D(k.current.openEvent?.type)), z = n(() => {
		A(F);
	});
	e(() => {
		C || (F.pointerType = void 0, F.restTimeoutPending = !1, F.interactedInside = !1, z());
	}, [
		C,
		F,
		z
	]), x.useEffect(() => z, [z]), e(() => {
		if (h && C && F.handleCloseOptions?.blockPointerEvents && R() && o(O) && T) {
			let e = O, t = T, n = g(T), r = N?.nodesRef.current.find((e) => e.id === P)?.context?.elements.floating;
			r && (r.style.pointerEvents = "");
			let i = F.pointerEventsScopeElement === t ? null : F.pointerEventsScopeElement, a = r === t ? null : r;
			return j(F, {
				scopeElement: F.handleCloseOptions?.getScope?.() ?? i ?? a ?? e.closest("[data-rootownerid]") ?? n.body,
				referenceElement: e,
				floatingElement: t
			}), () => {
				z();
			};
		}
	}, [
		h,
		C,
		O,
		T,
		F,
		R,
		N,
		P,
		z
	]), x.useEffect(() => {
		if (!h) return;
		function e() {
			return !!(N && P && p(N.nodesRef.current, P).length > 0);
		}
		function t(e) {
			let t = w(v, "close", F.pointerType), n = () => {
				S.setOpen(!1, r(i, e)), N?.events.emit("floating.closed", e);
			};
			t ? F.openChangeTimeout.start(t, n) : (F.openChangeTimeout.clear(), n());
		}
		function n(e) {
			let t = c(e);
			if (!l(t)) {
				F.interactedInside = !1;
				return;
			}
			F.interactedInside = t?.closest("[aria-haspopup]") != null;
		}
		function a() {
			F.openChangeTimeout.clear(), I.clear(), N?.events.off("floating.closed", m), z();
		}
		function f(n) {
			if (e() && N) {
				N.events.on("floating.closed", m);
				return;
			}
			if (u(n.relatedTarget, S.context.triggerElements)) return;
			let r = k.current.floatingContext?.nodeId ?? b, i = n.relatedTarget;
			if (!(N && r && o(i) && p(N.nodesRef.current, r, !1).some((e) => s(e.context?.elements.floating, i)))) {
				if (F.handler) {
					F.handler(n);
					return;
				}
				z(), L() || t(n);
			}
		}
		function m(t) {
			!N || !P || e() || I.start(0, () => {
				N.events.off("floating.closed", m), S.setOpen(!1, r(i, t)), N.events.emit("floating.closed", t);
			});
		}
		let g = T;
		return d(g && _(g, "mouseenter", a), g && _(g, "mouseleave", f), g && _(g, "pointerdown", n, !0), () => {
			N?.events.off("floating.closed", m);
		});
	}, [
		h,
		T,
		S,
		k,
		v,
		b,
		L,
		z,
		F,
		N,
		P,
		I
	]);
}
//#endregion
//#region ../../node_modules/.bun/@base-ui+react@1.5.0+f4ada88178b00e6f/node_modules/@base-ui/react/esm/floating-ui-react/hooks/useHoverReferenceInteraction.js
var P = { current: null };
function F(e, t = {}) {
	let { enabled: a = !0, delay: l = 0, handleClose: f = null, mouseOnly: p = !1, restMs: y = 0, move: b = !0, triggerElementRef: C = P, externalTree: D, isActiveTrigger: O = !0, getHandleCloseContext: k, isClosing: N, shouldOpen: F } = t, I = "rootStore" in e ? e.rootStore : e, { dataRef: L, events: R } = I.context, z = m(D), B = M(I), V = x.useRef(!1), H = v(f), U = v(l), W = v(y), G = v(a), K = v(F), q = v(N), J = n(() => E(L.current.openEvent?.type, B.interactedInside)), Y = n(() => K.current?.() !== !1), X = n((e, t, n) => {
		let r = I.context.triggerElements;
		if (r.hasElement(t)) return !e || !s(e, t);
		if (!o(n)) return !1;
		let i = n;
		return r.hasMatchingElement((e) => s(e, i)) && (!e || !s(e, i));
	}), Z = n(() => {
		B.handler &&= (g(I.select("domReferenceElement")).removeEventListener("mousemove", B.handler), void 0);
	}), Q = n(() => {
		A(B);
	});
	return O && (B.handleCloseOptions = H.current?.__options), x.useEffect(() => Z, [Z]), x.useEffect(() => {
		if (!a) return;
		function e(e) {
			e.open ? V.current = !1 : (V.current = e.reason === i, Z(), B.openChangeTimeout.clear(), B.restTimeout.clear(), B.blockMouseMove = !0, B.restTimeoutPending = !1);
		}
		return R.on("openchange", e), () => {
			R.off("openchange", e);
		};
	}, [
		a,
		R,
		B,
		Z
	]), x.useEffect(() => {
		if (!a) return;
		function e(e, t = !0) {
			let n = w(U.current, "close", B.pointerType);
			n ? B.openChangeTimeout.start(n, () => {
				I.setOpen(!1, r(i, e)), z?.events.emit("floating.closed", e);
			}) : t && (B.openChangeTimeout.clear(), I.setOpen(!1, r(i, e)), z?.events.emit("floating.closed", e));
		}
		let t = C.current ?? (O ? I.select("domReferenceElement") : null);
		if (!o(t)) return;
		function n(e) {
			if (B.openChangeTimeout.clear(), B.blockMouseMove = !1, p && !h(B.pointerType)) return;
			let t = T(W.current), n = w(U.current, "open", B.pointerType), a = c(e), l = e.currentTarget ?? null, u = I.select("domReferenceElement"), d = l;
			if (o(a) && !I.context.triggerElements.hasElement(a)) {
				for (let e of I.context.triggerElements.elements()) if (s(e, a)) {
					d = e;
					break;
				}
			}
			o(l) && o(u) && !I.context.triggerElements.hasElement(l) && s(l, u) && (d = u);
			let f = d == null ? !1 : X(u, d, a), m = I.select("open"), g = q.current?.() ?? I.select("transitionStatus") === "ending", _ = !m && g && V.current, v = !f && o(d) && o(u) && s(u, d) && _, y = t > 0 && !n, b = f && (m || _) || v, x = !m || f;
			if (b) {
				Y() && I.setOpen(!0, r(i, e, d));
				return;
			}
			y || (n ? B.openChangeTimeout.start(n, () => {
				x && Y() && I.setOpen(!0, r(i, e, d));
			}) : x && Y() && I.setOpen(!0, r(i, e, d)));
		}
		function l(t) {
			if (J()) {
				Q();
				return;
			}
			Z();
			let n = g(I.select("domReferenceElement"));
			B.restTimeout.clear(), B.restTimeoutPending = !1;
			let r = L.current.floatingContext ?? k?.();
			if (!u(t.relatedTarget, I.context.triggerElements)) {
				if (H.current && r) {
					I.select("open") || B.openChangeTimeout.clear();
					let i = C.current;
					B.handler = H.current({
						...r,
						tree: z,
						x: t.clientX,
						y: t.clientY,
						onClose() {
							Q(), Z(), G.current && !J() && i === I.select("domReferenceElement") && e(t, !0);
						}
					}), n.addEventListener("mousemove", B.handler), B.handler(t);
					return;
				}
				(B.pointerType !== "touch" || !s(I.select("floatingElement"), t.relatedTarget)) && e(t);
			}
		}
		return b ? d(_(t, "mousemove", n, { once: !0 }), _(t, "mouseenter", n), _(t, "mouseleave", l)) : d(_(t, "mouseenter", n), _(t, "mouseleave", l));
	}, [
		Z,
		Q,
		L,
		U,
		I,
		a,
		H,
		B,
		O,
		X,
		J,
		p,
		b,
		W,
		C,
		z,
		G,
		k,
		q,
		Y
	]), x.useMemo(() => {
		if (!a) return;
		function e(e) {
			B.pointerType = e.pointerType;
		}
		return {
			onPointerDown: e,
			onPointerEnter: e,
			onMouseMove(e) {
				let { nativeEvent: t } = e, n = e.currentTarget, a = I.select("domReferenceElement"), o = I.select("open"), s = X(a, n, e.target);
				if (p && !h(B.pointerType)) return;
				if (o && s && B.handleCloseOptions?.blockPointerEvents) {
					let e = I.select("floatingElement");
					e && j(B, {
						scopeElement: B.handleCloseOptions?.getScope?.() ?? n.ownerDocument.body,
						referenceElement: n,
						floatingElement: e
					});
				}
				let c = T(W.current);
				if (o && !s || c === 0 || !s && B.restTimeoutPending && e.movementX ** 2 + e.movementY ** 2 < 2) return;
				B.restTimeout.clear();
				function l() {
					if (B.restTimeoutPending = !1, J()) return;
					let e = I.select("open");
					!B.blockMouseMove && (!e || s) && Y() && I.setOpen(!0, r(i, t, n));
				}
				B.pointerType === "touch" ? S.flushSync(() => {
					l();
				}) : s && o ? l() : (B.restTimeoutPending = !0, B.restTimeout.start(c, l));
			}
		};
	}, [
		a,
		B,
		J,
		X,
		p,
		I,
		W,
		Y
	]);
}
//#endregion
//#region ../../node_modules/.bun/@base-ui+react@1.5.0+f4ada88178b00e6f/node_modules/@base-ui/react/esm/floating-ui-react/safePolygon.js
var I = .1, L = I * I, R = .5;
function z(e, t, n, r, i, a) {
	return r >= t != a >= t && e <= (i - n) * (t - r) / (a - r) + n;
}
function B(e, t, n, r, i, a, o, s, c, l) {
	let u = !1;
	return z(e, t, n, r, i, a) && (u = !u), z(e, t, i, a, o, s) && (u = !u), z(e, t, o, s, c, l) && (u = !u), z(e, t, c, l, n, r) && (u = !u), u;
}
function V(e, t, n) {
	return e >= n.x && e <= n.x + n.width && t >= n.y && t <= n.y + n.height;
}
function H(e, t, n, r, i, a) {
	return e >= Math.min(n, i) && e <= Math.max(n, i) && t >= Math.min(r, a) && t <= Math.max(r, a);
}
function U(e = {}) {
	let { blockPointerEvents: t = !1 } = e, n = new b(), r = ({ x: e, y: t, placement: r, elements: i, onClose: a, nodeId: l, tree: u }) => {
		let d = r?.split("-")[0], f = !1, m = null, h = null, g = typeof performance < "u" ? performance.now() : 0;
		function _(e, t) {
			let n = performance.now(), r = n - g;
			if (m === null || h === null || r === 0) return m = e, h = t, g = n, !1;
			let i = e - m, a = t - h, o = i * i + a * a, s = r * r * L;
			return m = e, h = t, g = n, o < s;
		}
		function v() {
			n.clear(), a();
		}
		return function(r) {
			n.clear();
			let a = i.domReference, m = i.floating;
			if (!a || !m || d == null || e == null || t == null) return;
			let { clientX: h, clientY: g } = r, y = c(r), b = r.type === "mouseleave", x = s(m, y), S = s(a, y);
			if (x && (f = !0, !b)) return;
			if (S && (f = !1, !b)) {
				f = !0;
				return;
			}
			if (b && o(r.relatedTarget) && s(m, r.relatedTarget)) return;
			function C() {
				return !!(u && p(u.nodesRef.current, l).length > 0);
			}
			function w() {
				C() || v();
			}
			if (C()) return;
			let T = a.getBoundingClientRect(), E = m.getBoundingClientRect(), D = e > E.right - E.width / 2, O = t > E.bottom - E.height / 2, k = E.width > T.width, A = E.height > T.height, j = (k ? T : E).left, M = (k ? T : E).right, N = (A ? T : E).top, P = (A ? T : E).bottom;
			if (d === "top" && t >= T.bottom - 1 || d === "bottom" && t <= T.top + 1 || d === "left" && e >= T.right - 1 || d === "right" && e <= T.left + 1) {
				w();
				return;
			}
			let F = !1;
			switch (d) {
				case "top":
					F = H(h, g, j, T.top + 1, M, E.bottom - 1);
					break;
				case "bottom":
					F = H(h, g, j, E.top + 1, M, T.bottom - 1);
					break;
				case "left":
					F = H(h, g, E.right - 1, P, T.left + 1, N);
					break;
				case "right":
					F = H(h, g, T.right - 1, P, E.left + 1, N);
					break;
				default:
			}
			if (F) return;
			if (f && !V(h, g, T)) {
				w();
				return;
			}
			if (!b && _(h, g)) {
				w();
				return;
			}
			let I = !1;
			switch (d) {
				case "top": {
					let n = k ? R / 2 : R * 4, r = k || D ? e + n : e - n, i = k ? e - n : D ? e + n : e - n, a = t + R + 1, o = D || k ? E.bottom - R : E.top, s = D ? k ? E.bottom - R : E.top : E.bottom - R;
					I = B(h, g, r, a, i, a, E.left, o, E.right, s);
					break;
				}
				case "bottom": {
					let n = k ? R / 2 : R * 4, r = k || D ? e + n : e - n, i = k ? e - n : D ? e + n : e - n, a = t - R, o = D || k ? E.top + R : E.bottom, s = D ? k ? E.top + R : E.bottom : E.top + R;
					I = B(h, g, r, a, i, a, E.left, o, E.right, s);
					break;
				}
				case "left": {
					let n = A ? R / 2 : R * 4, r = A || O ? t + n : t - n, i = A ? t - n : O ? t + n : t - n, a = e + R + 1, o = O || A ? E.right - R : E.left, s = O ? A ? E.right - R : E.left : E.right - R;
					I = B(h, g, o, E.top, s, E.bottom, a, r, a, i);
					break;
				}
				case "right": {
					let n = A ? R / 2 : R * 4, r = A || O ? t + n : t - n, i = A ? t - n : O ? t + n : t - n, a = e - R, o = O || A ? E.left + R : E.right, s = O ? A ? E.left + R : E.right : E.left + R;
					I = B(h, g, a, r, a, i, o, E.top, s, E.bottom);
					break;
				}
				default:
			}
			I ? f || n.start(40, w) : w();
		};
	};
	return r.__options = {
		...e,
		blockPointerEvents: t
	}, r;
}
//#endregion
export { w as a, M as i, F as n, N as r, U as t };
