import { jsxs as At, jsx as K } from "react/jsx-runtime";
import * as u from "react";
import Ft, { createContext as Fn, useContext as _n, useRef as _t } from "react";
import { a as Z, N as Lt, A as Ln, c as V, q as Ve, e as Vt, g as pt, r as be, s as Vn, v as Bt, d as se, o as Bn, t as De, E as ke, w as Wn, n as jn, f as Me, p as zn, l as Wt, u as jt, m as zt, x as Kn, T as gt, j as Re, i as Kt, k as Ht, y as Hn } from "../useOpenChangeComplete-RUbg6RBw.mjs";
import { f as $e, p as $t, o as Ut, i as ve, e as Gt, c as pe, k as qe, j as $n, d as Xe, s as Un } from "../floating-ui.utils.dom-uiDUZc_y.mjs";
import { c as Gn, d as Yn } from "../detectBrowser-Bc7rk5fI.mjs";
import { T as nt, o as Ue, b as oe, d as mt, e as qn, f as Ne, h as ot, t as Yt, j as st, k as rt, a as xe, c as $, v as Xn, F as ht, l as Et, n as Jn, p as Qn, g as re, q as qt, C as Xt, r as Zn, s as eo, w as to, x as ne, y as no, A as Jt, S as Qt, z as oo, i as ro } from "../inertValue-Bif5Sqs6.mjs";
import { u as so, a as it } from "../useTransitionStatus-CktVVKxz.mjs";
import { r as Zt, s as io } from "../index-VL0YEmOW.mjs";
import { i as ao, d as lo, s as co, e as yt, f as en, g as uo, C as fo } from "../composite-Br3kM5N9.mjs";
import { a as po } from "../Slot-C98rL4yy.mjs";
import { useMergeRefs as tn } from "@spark-ui/hooks/use-merge-refs";
import { useScrollOverflow as go } from "@spark-ui/hooks/use-scroll-overflow";
import { a as Te } from "../index-BmAFn37q.mjs";
import { d as mo } from "../DialogContent.styles-WGWJS9dj.mjs";
function Se(e, t, n = !0) {
  return e.filter((r) => r.parentId === t && (!n || r.context?.open)).flatMap((r) => [r, ...Se(e, r.id, n)]);
}
function bt(e, t) {
  let n = [], o = e.find((r) => r.id === t)?.parentId;
  for (; o; ) {
    const r = e.find((s) => s.id === o);
    o = r?.parentId, r && (n = n.concat(r));
  }
  return n;
}
let vt = {}, St = {}, Ct = "";
function ho(e) {
  if (typeof document > "u")
    return !1;
  const t = Ue(e);
  return $e(t).innerWidth - t.documentElement.clientWidth > 0;
}
function Eo(e) {
  const t = Ue(e), n = t.documentElement, o = t.body, r = $t(n) ? n : o, s = r.style.overflow;
  return r.style.overflow = "hidden", () => {
    r.style.overflow = s;
  };
}
function yo(e) {
  const t = Ue(e), n = t.documentElement, o = t.body, r = $e(n);
  let s = 0, a = 0;
  const l = Ln.create(), i = typeof CSS < "u" && CSS.supports?.("scrollbar-gutter", "stable");
  if (Yn && (r.visualViewport?.scale ?? 1) !== 1)
    return () => {
    };
  function c() {
    const p = r.getComputedStyle(n), m = r.getComputedStyle(o), C = (p.scrollbarGutter || "").includes("both-edges") ? "stable both-edges" : "stable";
    s = n.scrollTop, a = n.scrollLeft, vt = {
      scrollbarGutter: n.style.scrollbarGutter,
      overflowY: n.style.overflowY,
      overflowX: n.style.overflowX
    }, Ct = n.style.scrollBehavior, St = {
      position: o.style.position,
      height: o.style.height,
      width: o.style.width,
      boxSizing: o.style.boxSizing,
      overflowY: o.style.overflowY,
      overflowX: o.style.overflowX,
      scrollBehavior: o.style.scrollBehavior
    };
    const T = n.scrollHeight > n.clientHeight, y = n.scrollWidth > n.clientWidth, E = p.overflowY === "scroll" || m.overflowY === "scroll", x = p.overflowX === "scroll" || m.overflowX === "scroll", k = Math.max(0, r.innerWidth - n.clientWidth), w = Math.max(0, r.innerHeight - n.clientHeight), D = parseFloat(m.marginTop) + parseFloat(m.marginBottom), I = parseFloat(m.marginLeft) + parseFloat(m.marginRight), B = $t(n) ? n : o;
    if (i) {
      n.style.scrollbarGutter = C, B.style.overflowY = "hidden", B.style.overflowX = "hidden";
      return;
    }
    Object.assign(n.style, {
      scrollbarGutter: C,
      overflowY: "hidden",
      overflowX: "hidden"
    }), (T || E) && (n.style.overflowY = "scroll"), (y || x) && (n.style.overflowX = "scroll"), Object.assign(o.style, {
      position: "relative",
      height: D || w ? `calc(100dvh - ${D + w}px)` : "100dvh",
      width: I || k ? `calc(100vw - ${I + k}px)` : "100vw",
      boxSizing: "border-box",
      overflow: "hidden",
      scrollBehavior: "unset"
    }), o.scrollTop = s, o.scrollLeft = a, n.setAttribute("data-base-ui-scroll-locked", ""), n.style.scrollBehavior = "unset";
  }
  function f() {
    Object.assign(n.style, vt), Object.assign(o.style, St), i || (n.scrollTop = s, n.scrollLeft = a, n.removeAttribute("data-base-ui-scroll-locked"), n.style.scrollBehavior = Ct);
  }
  function h() {
    f(), l.request(c);
  }
  return c(), r.addEventListener("resize", h), () => {
    l.cancel(), f(), typeof r.removeEventListener == "function" && r.removeEventListener("resize", h);
  };
}
class bo {
  lockCount = 0;
  restore = null;
  timeoutLock = nt.create();
  timeoutUnlock = nt.create();
  acquire(t) {
    return this.lockCount += 1, this.lockCount === 1 && this.restore === null && this.timeoutLock.start(0, () => this.lock(t)), this.release;
  }
  release = () => {
    this.lockCount -= 1, this.lockCount === 0 && this.restore && this.timeoutUnlock.start(0, this.unlock);
  };
  unlock = () => {
    this.lockCount === 0 && this.restore && (this.restore?.(), this.restore = null);
  };
  lock(t) {
    if (this.lockCount === 0 || this.restore !== null)
      return;
    const o = Ue(t).documentElement, r = $e(o).getComputedStyle(o).overflowY;
    if (r === "hidden" || r === "clip") {
      this.restore = Lt;
      return;
    }
    const s = Gn || !ho(t);
    this.restore = s ? Eo(t) : yo(t);
  }
}
const vo = new bo();
function So(e = !0, t = null) {
  Z(() => {
    if (e)
      return vo.acquire(t);
  }, [e, t]);
}
function Co() {
  const e = /* @__PURE__ */ new Map();
  return {
    emit(t, n) {
      e.get(t)?.forEach((o) => o(n));
    },
    on(t, n) {
      e.has(t) || e.set(t, /* @__PURE__ */ new Set()), e.get(t).add(n);
    },
    off(t, n) {
      e.get(t)?.delete(n);
    }
  };
}
const nn = /* @__PURE__ */ u.createContext(null);
process.env.NODE_ENV !== "production" && (nn.displayName = "FloatingNodeContext");
const on = /* @__PURE__ */ u.createContext(null);
process.env.NODE_ENV !== "production" && (on.displayName = "FloatingTreeContext");
const rn = () => u.useContext(nn)?.id || null, sn = (e) => {
  const t = u.useContext(on);
  return e ?? t;
};
let Rt = 0;
function Je(e, t = {}) {
  const {
    preventScroll: n = !1,
    cancelPrevious: o = !0,
    sync: r = !1
  } = t;
  o && cancelAnimationFrame(Rt);
  const s = () => e?.focus({
    preventScroll: n
  });
  r ? s() : Rt = requestAnimationFrame(s);
}
const Ce = {
  inert: /* @__PURE__ */ new WeakMap(),
  "aria-hidden": /* @__PURE__ */ new WeakMap(),
  none: /* @__PURE__ */ new WeakMap()
};
function Tt(e) {
  return e === "inert" ? Ce.inert : e === "aria-hidden" ? Ce["aria-hidden"] : Ce.none;
}
let Be = /* @__PURE__ */ new WeakSet(), We = {}, Qe = 0;
const an = (e) => e && (e.host || an(e.parentNode)), Ro = (e, t) => t.map((n) => {
  if (e.contains(n))
    return n;
  const o = an(n);
  return e.contains(o) ? o : null;
}).filter((n) => n != null);
function To(e, t, n, o) {
  const r = "data-base-ui-inert", s = o ? "inert" : n ? "aria-hidden" : null, a = Ro(t, e), l = /* @__PURE__ */ new Set(), i = new Set(a), c = [];
  We[r] || (We[r] = /* @__PURE__ */ new WeakMap());
  const f = We[r];
  a.forEach(h), p(t), l.clear();
  function h(m) {
    !m || l.has(m) || (l.add(m), m.parentNode && h(m.parentNode));
  }
  function p(m) {
    !m || i.has(m) || [].forEach.call(m.children, (g) => {
      if (Ut(g) !== "script")
        if (l.has(g))
          p(g);
        else {
          const b = s ? g.getAttribute(s) : null, C = b !== null && b !== "false", T = Tt(s), y = (T.get(g) || 0) + 1, E = (f.get(g) || 0) + 1;
          T.set(g, y), f.set(g, E), c.push(g), y === 1 && C && Be.add(g), E === 1 && g.setAttribute(r, ""), !C && s && g.setAttribute(s, s === "inert" ? "" : "true");
        }
    });
  }
  return Qe += 1, () => {
    c.forEach((m) => {
      const g = Tt(s), C = (g.get(m) || 0) - 1, T = (f.get(m) || 0) - 1;
      g.set(m, C), f.set(m, T), C || (!Be.has(m) && s && m.removeAttribute(s), Be.delete(m)), T || m.removeAttribute(r);
    }), Qe -= 1, Qe || (Ce.inert = /* @__PURE__ */ new WeakMap(), Ce["aria-hidden"] = /* @__PURE__ */ new WeakMap(), Ce.none = /* @__PURE__ */ new WeakMap(), Be = /* @__PURE__ */ new WeakSet(), We = {});
  };
}
function Oo(e, t = !1, n = !1) {
  const o = oe(e[0]).body;
  return To(e.concat(Array.from(o.querySelectorAll("[aria-live]"))), o, t, n);
}
function wo(e, t) {
  const n = $e(e.target);
  return e instanceof n.KeyboardEvent ? "keyboard" : e instanceof n.FocusEvent ? t || "keyboard" : "pointerType" in e ? e.pointerType || "keyboard" : "touches" in e ? "touch" : e instanceof n.MouseEvent ? t || (e.detail === 0 ? "keyboard" : "mouse") : "";
}
const Ot = 20;
let ue = [];
function at() {
  ue = ue.filter((e) => e.isConnected);
}
function xo(e) {
  at(), e && Ut(e) !== "body" && (ue.push(e), ue.length > Ot && (ue = ue.slice(-Ot)));
}
function Ze() {
  return at(), ue[ue.length - 1];
}
function Do(e) {
  if (!e)
    return null;
  const t = st();
  return qt(e, t) ? e : Yt(e, t)[0] || e;
}
function ko(e) {
  return !e || !e.isConnected ? !1 : typeof e.checkVisibility == "function" ? e.checkVisibility() : Gt(e).display !== "none";
}
function wt(e, t) {
  if (!t.current.includes("floating") && !e.getAttribute("role")?.includes("dialog"))
    return;
  const n = st(), r = Zn(e, n).filter((a) => {
    const l = a.getAttribute("data-tabindex") || "";
    return qt(a, n) || a.hasAttribute("data-tabindex") && !l.startsWith("-");
  }), s = e.getAttribute("tabindex");
  t.current.includes("floating") || r.length === 0 ? s !== "0" && e.setAttribute("tabindex", "0") : (s !== "-1" || e.hasAttribute("data-tabindex") && e.getAttribute("data-tabindex") !== "-1") && (e.setAttribute("tabindex", "-1"), e.setAttribute("data-tabindex", "-1"));
}
function Io(e) {
  const {
    context: t,
    children: n,
    disabled: o = !1,
    order: r = ["content"],
    initialFocus: s = !0,
    returnFocus: a = !0,
    restoreFocus: l = !1,
    modal: i = !0,
    closeOnFocusOut: c = !0,
    openInteractionType: f = "",
    getInsideElements: h = () => [],
    nextFocusableElement: p,
    previousFocusableElement: m,
    beforeContentFocusGuardRef: g,
    externalTree: b
  } = e, C = "rootStore" in t ? t.rootStore : t, T = C.useState("open"), y = C.useState("domReferenceElement"), E = C.useState("floatingElement"), {
    events: x,
    dataRef: k
  } = C.context, w = V(() => k.current.floatingContext?.nodeId), D = V(h), I = s === !1, B = mt(y) && I, W = Ve(r), H = Ve(s), q = Ve(a), Oe = Ve(f), G = sn(b), F = qn(), ae = u.useRef(null), Ge = u.useRef(null), U = u.useRef(!1), ie = u.useRef(!1), me = u.useRef(!1), Pe = u.useRef(-1), he = u.useRef(""), te = u.useRef(""), Ae = Ne(), Ee = Ne(), Fe = Vt(), fe = F != null, N = ot(E), J = V((S = N) => S ? Yt(S, st()) : []), ce = V((S) => {
    const O = J(S);
    return W.current.map(() => O).filter(Boolean).flat();
  });
  u.useEffect(() => {
    if (o || !i)
      return;
    function S(j) {
      j.key === "Tab" && $(N, xe(oe(N))) && J().length === 0 && !B && co(j);
    }
    const O = oe(N);
    return O.addEventListener("keydown", S), () => {
      O.removeEventListener("keydown", S);
    };
  }, [o, y, N, i, W, B, J, ce]), u.useEffect(() => {
    if (o || !E)
      return;
    function S(O) {
      const j = re(O), z = J().indexOf(j);
      z !== -1 && (Pe.current = z);
    }
    return E.addEventListener("focusin", S), () => {
      E.removeEventListener("focusin", S);
    };
  }, [o, E, J]), u.useEffect(() => {
    if (o || !T)
      return;
    const S = oe(N);
    function O() {
      me.current = !1;
    }
    function j(z) {
      const v = re(z), M = $(E, v) || $(y, v) || $(F?.portalNode, v);
      me.current = !M, te.current = z.pointerType || "keyboard";
    }
    function L() {
      te.current = "keyboard";
    }
    return S.addEventListener("pointerdown", j, !0), S.addEventListener("pointerup", O, !0), S.addEventListener("pointercancel", O, !0), S.addEventListener("keydown", L, !0), () => {
      S.removeEventListener("pointerdown", j, !0), S.removeEventListener("pointerup", O, !0), S.removeEventListener("pointercancel", O, !0), S.removeEventListener("keydown", L, !0);
    };
  }, [o, E, y, N, T, F]), u.useEffect(() => {
    if (o || !c)
      return;
    function S() {
      ie.current = !0, Ee.start(0, () => {
        ie.current = !1;
      });
    }
    function O(v) {
      const M = v.relatedTarget, le = v.currentTarget, X = re(v);
      queueMicrotask(() => {
        const ye = w(), _e = C.context.triggerElements, Ye = !($(y, M) || $(E, M) || $(M, E) || $(F?.portalNode, M) || M != null && _e.hasElement(M) || _e.hasMatchingElement((Q) => $(Q, M)) || M?.hasAttribute(rt("focus-guard")) || G && (Se(G.nodesRef.current, ye).find((Q) => $(Q.context?.elements.floating, M) || $(Q.context?.elements.domReference, M)) || bt(G.nodesRef.current, ye).find((Q) => [Q.context?.elements.floating, ot(Q.context?.elements.floating)].includes(M) || Q.context?.elements.domReference === M)));
        if (le === y && N && wt(N, W), l && le !== y && !ko(X) && xe(oe(N)) === oe(N).body) {
          if (ve(N) && (N.focus(), l === "popup")) {
            Fe.request(() => {
              N.focus();
            });
            return;
          }
          const Q = Pe.current, we = J(), Le = we[Q] || we[we.length - 1] || N;
          ve(Le) && Le.focus();
        }
        if (k.current.insideReactTree) {
          k.current.insideReactTree = !1;
          return;
        }
        (B || !i) && M && Ye && !ie.current && // Fix React 18 Strict Mode returnFocus due to double rendering.
        // For an "untrapped" typeable combobox (input role=combobox with
        // initialFocus=false), re-opening the popup and tabbing out should still close it even
        // when the previously focused element (e.g. the next tabbable outside the popup) is
        // focused again. Otherwise, the popup remains open on the second Tab sequence:
        // click input -> Tab (closes) -> click input -> Tab.
        // Allow closing when `isUntrappedTypeableCombobox` regardless of the previously focused element.
        (B || M !== Ze()) && (U.current = !0, C.setOpen(!1, se(Bn, v)));
      });
    }
    function j() {
      me.current || (k.current.insideReactTree = !0, Ae.start(0, () => {
        k.current.insideReactTree = !1;
      }));
    }
    const L = ve(y) ? y : null, z = [];
    if (!(!E && !L))
      return L && (L.addEventListener("focusout", O), L.addEventListener("pointerdown", S), z.push(() => {
        L.removeEventListener("focusout", O), L.removeEventListener("pointerdown", S);
      })), E && (E.addEventListener("focusout", O), F && (E.addEventListener("focusout", j, !0), z.push(() => {
        E.removeEventListener("focusout", j, !0);
      })), z.push(() => {
        E.removeEventListener("focusout", O);
      })), () => {
        z.forEach((v) => {
          v();
        });
      };
  }, [o, y, E, N, i, G, F, C, c, l, J, B, w, W, k, Ae, Ee, Fe]);
  const d = u.useRef(null), P = u.useRef(null), R = pt(d, g, F?.beforeInsideRef), Y = pt(P, F?.afterInsideRef);
  u.useEffect(() => {
    if (o || !E || !T)
      return;
    const S = Array.from(F?.portalNode?.querySelectorAll(`[${rt("portal")}]`) || []), j = (G ? bt(G.nodesRef.current, w()) : []).find((v) => mt(v.context?.elements.domReference || null))?.context?.elements.domReference, L = [E, j, ...S, ...D(), ae.current, Ge.current, d.current, P.current, F?.beforeOutsideRef.current, F?.afterOutsideRef.current, be(m), be(p), B ? y : null].filter((v) => v != null), z = Oo(L, i || B);
    return () => {
      z();
    };
  }, [T, o, y, E, i, W, F, B, G, w, D, p, m]), Z(() => {
    if (!T || o || !ve(N))
      return;
    const S = oe(N), O = xe(S);
    queueMicrotask(() => {
      const j = ce(N), L = H.current, z = typeof L == "function" ? L(Oe.current || "") : L;
      if (z === void 0 || z === !1)
        return;
      let v;
      z === !0 || z === null ? v = j[0] || N : v = be(z), v = v || j[0] || N, !$(N, O) && Je(v, {
        preventScroll: v === N
      });
    });
  }, [o, T, N, I, ce, H, Oe]), Z(() => {
    if (o || !N)
      return;
    const S = oe(N), O = xe(S);
    xo(O);
    function j(v) {
      if (v.open || (he.current = wo(v.nativeEvent, te.current)), v.reason === Vn && v.nativeEvent.type === "mouseleave" && (U.current = !0), v.reason === Bt)
        if (v.nested)
          U.current = !1;
        else if (ao(v.nativeEvent) || lo(v.nativeEvent))
          U.current = !1;
        else {
          let M = !1;
          document.createElement("div").focus({
            get preventScroll() {
              return M = !0, !1;
            }
          }), M ? U.current = !1 : U.current = !0;
        }
    }
    x.on("openchange", j);
    const L = S.createElement("span");
    L.setAttribute("tabindex", "-1"), L.setAttribute("aria-hidden", "true"), Object.assign(L.style, Xn), fe && y && y.insertAdjacentElement("afterend", L);
    function z() {
      const v = q.current;
      let M = typeof v == "function" ? v(he.current) : v;
      if (M === void 0 || M === !1)
        return null;
      if (M === null && (M = !0), typeof M == "boolean") {
        const X = y || Ze();
        return X && X.isConnected ? X : L;
      }
      const le = y || Ze() || L;
      return be(M) || le;
    }
    return () => {
      x.off("openchange", j);
      const v = xe(S), M = $(E, v) || G && Se(G.nodesRef.current, w(), !1).some((X) => $(X.context?.elements.floating, v)), le = z();
      queueMicrotask(() => {
        const X = Do(le), ye = typeof q.current != "boolean";
        // eslint-disable-next-line react-hooks/exhaustive-deps
        q.current && !U.current && ve(X) && // If the focus moved somewhere else after mount, avoid returning focus
        // since it likely entered a different element which should be
        // respected: https://github.com/floating-ui/floating-ui/issues/2607
        (!(!ye && X !== v && v !== S.body) || M) && X.focus({
          preventScroll: !0
        }), L.remove();
      });
    };
  }, [o, E, N, q, k, x, G, fe, y, w]), u.useEffect(() => {
    queueMicrotask(() => {
      U.current = !1;
    });
  }, [o]), u.useEffect(() => {
    if (o || !T)
      return;
    function S(j) {
      re(j)?.closest(`[${Xt}]`) && (ie.current = !0);
    }
    const O = oe(N);
    return O.addEventListener("pointerdown", S, !0), () => {
      O.removeEventListener("pointerdown", S, !0);
    };
  }, [o, T, N]), Z(() => {
    if (!o && F)
      return F.setFocusManagerState({
        modal: i,
        closeOnFocusOut: c,
        open: T,
        onOpenChange: C.setOpen,
        domReference: y
      }), () => {
        F.setFocusManagerState(null);
      };
  }, [o, F, i, T, C, c, y]), Z(() => {
    if (!(o || !N))
      return wt(N, W), () => {
        queueMicrotask(at);
      };
  }, [o, N, W]);
  const A = !o && (i ? !B : !0) && (fe || i);
  return /* @__PURE__ */ At(u.Fragment, {
    children: [A && /* @__PURE__ */ K(ht, {
      "data-type": "inside",
      ref: R,
      onFocus: (S) => {
        if (i) {
          const O = ce();
          Je(O[O.length - 1]);
        } else F?.portalNode && (U.current = !1, Et(S, F.portalNode) ? Jn(y)?.focus() : be(m ?? F.beforeOutsideRef)?.focus());
      }
    }), n, A && /* @__PURE__ */ K(ht, {
      "data-type": "inside",
      ref: Y,
      onFocus: (S) => {
        i ? Je(ce()[0]) : F?.portalNode && (c && (U.current = !0), Et(S, F.portalNode) ? Qn(y)?.focus() : be(p ?? F.afterOutsideRef)?.focus());
      }
    })]
  });
}
function No(e, t = {}) {
  const n = "rootStore" in e ? e.rootStore : e, o = n.context.dataRef, {
    enabled: r = !0,
    event: s = "click",
    toggle: a = !0,
    ignoreMouse: l = !1,
    stickIfOpen: i = !0,
    touchOpenDelay: c = 0
  } = t, f = u.useRef(void 0), h = Vt(), p = Ne(), m = u.useMemo(() => ({
    onPointerDown(g) {
      f.current = g.pointerType;
    },
    onMouseDown(g) {
      const b = f.current, C = g.nativeEvent, T = n.select("open");
      if (g.button !== 0 || s === "click" || yt(b) && l)
        return;
      const y = o.current.openEvent, E = y?.type, x = n.select("domReferenceElement") !== g.currentTarget, k = T && x || !(T && a && (!(y && i) || E === "click" || E === "mousedown"));
      if (eo(C.target)) {
        const D = se(De, C, C.target);
        k && b === "touch" && c > 0 ? p.start(c, () => {
          n.setOpen(!0, D);
        }) : n.setOpen(k, D);
        return;
      }
      const w = g.currentTarget;
      h.request(() => {
        const D = se(De, C, w);
        k && b === "touch" && c > 0 ? p.start(c, () => {
          n.setOpen(!0, D);
        }) : n.setOpen(k, D);
      });
    },
    onClick(g) {
      if (s === "mousedown-only")
        return;
      const b = f.current;
      if (s === "mousedown" && b) {
        f.current = void 0;
        return;
      }
      if (yt(b) && l)
        return;
      const C = n.select("open"), T = o.current.openEvent, y = n.select("domReferenceElement") !== g.currentTarget, E = C && y || !(C && a && (!(T && i) || en(T))), x = se(De, g.nativeEvent, g.currentTarget);
      E && b === "touch" && c > 0 ? p.start(c, () => {
        n.setOpen(!0, x);
      }) : n.setOpen(E, x);
    },
    onKeyDown() {
      f.current = void 0;
    }
  }), [o, s, l, n, i, a, h, p, c]);
  return u.useMemo(() => r ? {
    reference: m
  } : ke, [r, m]);
}
const Mo = {
  intentional: "onClick",
  sloppy: "onPointerDown"
};
function Po(e) {
  return {
    escapeKey: typeof e == "boolean" ? e : e?.escapeKey ?? !1,
    outsidePress: typeof e == "boolean" ? e : e?.outsidePress ?? !0
  };
}
function Ao(e, t = {}) {
  const n = "rootStore" in e ? e.rootStore : e, o = n.useState("open"), r = n.useState("floatingElement"), s = n.useState("referenceElement"), a = n.useState("domReferenceElement"), {
    onOpenChange: l,
    dataRef: i
  } = n.context, {
    enabled: c = !0,
    escapeKey: f = !0,
    outsidePress: h = !0,
    outsidePressEvent: p = "sloppy",
    referencePress: m = !1,
    referencePressEvent: g = "sloppy",
    ancestorScroll: b = !1,
    bubbles: C,
    externalTree: T
  } = t, y = sn(T), E = V(typeof h == "function" ? h : () => !1), x = typeof h == "function" ? E : h, k = u.useRef(!1), {
    escapeKey: w,
    outsidePress: D
  } = Po(C), I = u.useRef(null), B = Ne(), W = Ne(), H = V(() => {
    W.clear(), i.current.insideReactTree = !1;
  }), q = u.useRef(!1), Oe = u.useRef(""), G = V((d) => {
    Oe.current = d.pointerType;
  }), F = V(() => {
    const d = Oe.current, P = d === "pen" || !d ? "mouse" : d, R = typeof p == "function" ? p() : p;
    return typeof R == "string" ? R : R[P];
  }), ae = V((d) => {
    if (!o || !c || !f || d.key !== "Escape" || q.current)
      return;
    const P = i.current.floatingContext?.nodeId, R = y ? Se(y.nodesRef.current, P) : [];
    if (!w && R.length > 0) {
      let S = !0;
      if (R.forEach((O) => {
        O.context?.open && !O.context.dataRef.current.__escapeKeyBubbles && (S = !1);
      }), !S)
        return;
    }
    const Y = uo(d) ? d.nativeEvent : d, A = se(Wn, Y);
    n.setOpen(!1, A), !w && !A.isPropagationAllowed && d.stopPropagation();
  }), Ge = V((d) => {
    const P = F();
    return P === "intentional" && d.type !== "click" || P === "sloppy" && d.type === "click";
  }), U = V(() => {
    i.current.insideReactTree = !0, W.start(0, H);
  }), ie = V((d, P = !1) => {
    if (Ge(d)) {
      H();
      return;
    }
    if (i.current.insideReactTree) {
      H();
      return;
    }
    if (F() === "intentional" && P || typeof x == "function" && !x(d))
      return;
    const R = re(d), Y = `[${rt("inert")}]`, A = oe(n.select("floatingElement")).querySelectorAll(Y), S = n.context.triggerElements;
    if (R && (S.hasElement(R) || S.hasMatchingElement((v) => $(v, R))))
      return;
    let O = pe(R) ? R : null;
    for (; O && !qe(O); ) {
      const v = $n(O);
      if (qe(v) || !pe(v))
        break;
      O = v;
    }
    if (A.length && pe(R) && !to(R) && // Clicked on a direct ancestor (e.g. FloatingOverlay).
    !$(R, n.select("floatingElement")) && // If the target root element contains none of the markers, then the
    // element was injected after the floating element rendered.
    Array.from(A).every((v) => !$(O, v)))
      return;
    if (ve(R) && !("touches" in d)) {
      const v = qe(R), M = Gt(R), le = /auto|scroll/, X = v || le.test(M.overflowX), ye = v || le.test(M.overflowY), _e = X && R.clientWidth > 0 && R.scrollWidth > R.clientWidth, Ye = ye && R.clientHeight > 0 && R.scrollHeight > R.clientHeight, Q = M.direction === "rtl", we = Ye && (Q ? d.offsetX <= R.offsetWidth - R.clientWidth : d.offsetX > R.clientWidth), Le = _e && d.offsetY > R.clientHeight;
      if (we || Le)
        return;
    }
    const j = i.current.floatingContext?.nodeId, L = y && Se(y.nodesRef.current, j).some((v) => ne(d, v.context?.elements.floating));
    if (ne(d, n.select("floatingElement")) || ne(d, n.select("domReferenceElement")) || L)
      return;
    const z = y ? Se(y.nodesRef.current, j) : [];
    if (z.length > 0) {
      let v = !0;
      if (z.forEach((M) => {
        M.context?.open && !M.context.dataRef.current.__outsidePressBubbles && (v = !1);
      }), !v)
        return;
    }
    n.setOpen(!1, se(Bt, d)), H();
  }), me = V((d) => {
    F() !== "sloppy" || d.pointerType === "touch" || !n.select("open") || !c || ne(d, n.select("floatingElement")) || ne(d, n.select("domReferenceElement")) || ie(d);
  }), Pe = V((d) => {
    if (F() !== "sloppy" || !n.select("open") || !c || ne(d, n.select("floatingElement")) || ne(d, n.select("domReferenceElement")))
      return;
    const P = d.touches[0];
    P && (I.current = {
      startTime: Date.now(),
      startX: P.clientX,
      startY: P.clientY,
      dismissOnTouchEnd: !1,
      dismissOnMouseDown: !0
    }, B.start(1e3, () => {
      I.current && (I.current.dismissOnTouchEnd = !1, I.current.dismissOnMouseDown = !1);
    }));
  }), he = V((d) => {
    const P = re(d);
    function R() {
      Pe(d), P?.removeEventListener(d.type, R);
    }
    P?.addEventListener(d.type, R);
  }), te = V((d) => {
    const P = k.current;
    if (k.current = !1, B.clear(), d.type === "mousedown" && I.current && !I.current.dismissOnMouseDown)
      return;
    const R = re(d);
    function Y() {
      d.type === "pointerdown" ? me(d) : ie(d, P), R?.removeEventListener(d.type, Y);
    }
    R?.addEventListener(d.type, Y);
  }), Ae = V((d) => {
    if (F() !== "sloppy" || !I.current || ne(d, n.select("floatingElement")) || ne(d, n.select("domReferenceElement")))
      return;
    const P = d.touches[0];
    if (!P)
      return;
    const R = Math.abs(P.clientX - I.current.startX), Y = Math.abs(P.clientY - I.current.startY), A = Math.sqrt(R * R + Y * Y);
    A > 5 && (I.current.dismissOnTouchEnd = !0), A > 10 && (ie(d), B.clear(), I.current = null);
  }), Ee = V((d) => {
    const P = re(d);
    function R() {
      Ae(d), P?.removeEventListener(d.type, R);
    }
    P?.addEventListener(d.type, R);
  }), Fe = V((d) => {
    F() !== "sloppy" || !I.current || ne(d, n.select("floatingElement")) || ne(d, n.select("domReferenceElement")) || (I.current.dismissOnTouchEnd && ie(d), B.clear(), I.current = null);
  }), fe = V((d) => {
    const P = re(d);
    function R() {
      Fe(d), P?.removeEventListener(d.type, R);
    }
    P?.addEventListener(d.type, R);
  });
  u.useEffect(() => {
    if (!o || !c)
      return;
    i.current.__escapeKeyBubbles = w, i.current.__outsidePressBubbles = D;
    const d = new nt();
    function P(O) {
      n.setOpen(!1, se(jn, O));
    }
    function R() {
      d.clear(), q.current = !0;
    }
    function Y() {
      d.start(
        // 0ms or 1ms don't work in Safari. 5ms appears to consistently work.
        // Only apply to WebKit for the test to remain 0ms.
        Un() ? 5 : 0,
        () => {
          q.current = !1;
        }
      );
    }
    const A = oe(r);
    A.addEventListener("pointerdown", G, !0), f && (A.addEventListener("keydown", ae), A.addEventListener("compositionstart", R), A.addEventListener("compositionend", Y)), x && (A.addEventListener("click", te, !0), A.addEventListener("pointerdown", te, !0), A.addEventListener("touchstart", he, !0), A.addEventListener("touchmove", Ee, !0), A.addEventListener("touchend", fe, !0), A.addEventListener("mousedown", te, !0));
    let S = [];
    return b && (pe(a) && (S = Xe(a)), pe(r) && (S = S.concat(Xe(r))), !pe(s) && s && s.contextElement && (S = S.concat(Xe(s.contextElement)))), S = S.filter((O) => O !== A.defaultView?.visualViewport), S.forEach((O) => {
      O.addEventListener("scroll", P, {
        passive: !0
      });
    }), () => {
      A.removeEventListener("pointerdown", G, !0), f && (A.removeEventListener("keydown", ae), A.removeEventListener("compositionstart", R), A.removeEventListener("compositionend", Y)), x && (A.removeEventListener("click", te, !0), A.removeEventListener("pointerdown", te, !0), A.removeEventListener("touchstart", he, !0), A.removeEventListener("touchmove", Ee, !0), A.removeEventListener("touchend", fe, !0), A.removeEventListener("mousedown", te, !0)), S.forEach((O) => {
        O.removeEventListener("scroll", P);
      }), d.clear();
    };
  }, [i, r, s, a, f, x, o, l, b, c, w, D, ae, ie, te, me, he, Ee, fe, G, n]), u.useEffect(H, [x, H]);
  const N = u.useMemo(() => ({
    onKeyDown: ae,
    ...m && {
      [Mo[g]]: (d) => {
        n.setOpen(!1, se(De, d.nativeEvent));
      },
      ...g !== "intentional" && {
        onClick(d) {
          n.setOpen(!1, se(De, d.nativeEvent));
        }
      }
    }
  }), [ae, n, m, g]), J = V((d) => {
    const P = re(d.nativeEvent);
    !$(n.select("floatingElement"), P) || d.button !== 0 || (k.current = !0);
  }), ce = u.useMemo(() => ({
    onKeyDown: ae,
    // `onMouseDown` may be blocked if `event.preventDefault()` is called in
    // `onPointerDown`, such as with <NumberField.ScrubArea>.
    // See https://github.com/mui/base-ui/pull/3379
    onPointerDown: J,
    onMouseDown: J,
    onMouseUp: J,
    onClickCapture: U,
    onMouseDownCapture: U,
    onPointerDownCapture: U,
    onMouseUpCapture: U,
    onTouchEndCapture: U,
    onTouchMoveCapture: U
  }), [ae, J, U]);
  return u.useMemo(() => c ? {
    reference: N,
    floating: ce,
    trigger: N
  } : {}, [c, N, ce]);
}
var Fo = (e, t, n) => {
  if (t.length === 1 && t[0] === n) {
    let o = !1;
    try {
      const r = {};
      e(r) === r && (o = !0);
    } catch {
    }
    if (o) {
      let r;
      try {
        throw new Error();
      } catch (s) {
        ({ stack: r } = s);
      }
      console.warn(
        `The result function returned its own inputs without modification. e.g
\`createSelector([state => state.todos], todos => todos)\`
This could lead to inefficient memoization and unnecessary re-renders.
Ensure transformation logic is in the result function, and extraction logic is in the input selectors.`,
        { stack: r }
      );
    }
  }
}, _o = (e, t, n) => {
  const { memoize: o, memoizeOptions: r } = t, { inputSelectorResults: s, inputSelectorResultsCopy: a } = e, l = o(() => ({}), ...r);
  if (!(l.apply(null, s) === l.apply(null, a))) {
    let c;
    try {
      throw new Error();
    } catch (f) {
      ({ stack: c } = f);
    }
    console.warn(
      `An input selector returned a different result when passed same arguments.
This means your output selector will likely run more frequently than intended.
Avoid returning a new reference inside your input selector, e.g.
\`createSelector([state => state.todos.map(todo => todo.id)], todoIds => todoIds.length)\``,
      {
        arguments: n,
        firstInputs: s,
        secondInputs: a,
        stack: c
      }
    );
  }
}, Lo = {
  inputStabilityCheck: "once",
  identityFunctionCheck: "once"
}, He = /* @__PURE__ */ Symbol("NOT_FOUND");
function Vo(e, t = `expected a function, instead received ${typeof e}`) {
  if (typeof e != "function")
    throw new TypeError(t);
}
function Bo(e, t = `expected an object, instead received ${typeof e}`) {
  if (typeof e != "object")
    throw new TypeError(t);
}
function Wo(e, t = "expected all items to be functions, instead received the following types: ") {
  if (!e.every((n) => typeof n == "function")) {
    const n = e.map(
      (o) => typeof o == "function" ? `function ${o.name || "unnamed"}()` : typeof o
    ).join(", ");
    throw new TypeError(`${t}[${n}]`);
  }
}
var xt = (e) => Array.isArray(e) ? e : [e];
function jo(e) {
  const t = Array.isArray(e[0]) ? e[0] : e;
  return Wo(
    t,
    "createSelector expects all input-selectors to be functions, but received the following types: "
  ), t;
}
function Dt(e, t) {
  const n = [], { length: o } = e;
  for (let r = 0; r < o; r++)
    n.push(e[r].apply(null, t));
  return n;
}
var zo = (e, t) => {
  const { identityFunctionCheck: n, inputStabilityCheck: o } = {
    ...Lo,
    ...t
  };
  return {
    identityFunctionCheck: {
      shouldRun: n === "always" || n === "once" && e,
      run: Fo
    },
    inputStabilityCheck: {
      shouldRun: o === "always" || o === "once" && e,
      run: _o
    }
  };
};
function Ko(e) {
  let t;
  return {
    get(n) {
      return t && e(t.key, n) ? t.value : He;
    },
    put(n, o) {
      t = { key: n, value: o };
    },
    getEntries() {
      return t ? [t] : [];
    },
    clear() {
      t = void 0;
    }
  };
}
function Ho(e, t) {
  let n = [];
  function o(l) {
    const i = n.findIndex((c) => t(l, c.key));
    if (i > -1) {
      const c = n[i];
      return i > 0 && (n.splice(i, 1), n.unshift(c)), c.value;
    }
    return He;
  }
  function r(l, i) {
    o(l) === He && (n.unshift({ key: l, value: i }), n.length > e && n.pop());
  }
  function s() {
    return n;
  }
  function a() {
    n = [];
  }
  return { get: o, put: r, getEntries: s, clear: a };
}
var $o = (e, t) => e === t;
function Uo(e) {
  return function(n, o) {
    if (n === null || o === null || n.length !== o.length)
      return !1;
    const { length: r } = n;
    for (let s = 0; s < r; s++)
      if (!e(n[s], o[s]))
        return !1;
    return !0;
  };
}
function Go(e, t) {
  const n = typeof t == "object" ? t : { equalityCheck: t }, {
    equalityCheck: o = $o,
    maxSize: r = 1,
    resultEqualityCheck: s
  } = n, a = Uo(o);
  let l = 0;
  const i = r <= 1 ? Ko(a) : Ho(r, a);
  function c() {
    let f = i.get(arguments);
    if (f === He) {
      if (f = e.apply(null, arguments), l++, s) {
        const p = i.getEntries().find(
          (m) => s(m.value, f)
        );
        p && (f = p.value, l !== 0 && l--);
      }
      i.put(arguments, f);
    }
    return f;
  }
  return c.clearCache = () => {
    i.clear(), c.resetResultsCount();
  }, c.resultsCount = () => l, c.resetResultsCount = () => {
    l = 0;
  }, c;
}
var Yo = class {
  constructor(e) {
    this.value = e;
  }
  deref() {
    return this.value;
  }
}, qo = typeof WeakRef < "u" ? WeakRef : Yo, Xo = 0, kt = 1;
function je() {
  return {
    s: Xo,
    v: void 0,
    o: null,
    p: null
  };
}
function ln(e, t = {}) {
  let n = je();
  const { resultEqualityCheck: o } = t;
  let r, s = 0;
  function a() {
    let l = n;
    const { length: i } = arguments;
    for (let h = 0, p = i; h < p; h++) {
      const m = arguments[h];
      if (typeof m == "function" || typeof m == "object" && m !== null) {
        let g = l.o;
        g === null && (l.o = g = /* @__PURE__ */ new WeakMap());
        const b = g.get(m);
        b === void 0 ? (l = je(), g.set(m, l)) : l = b;
      } else {
        let g = l.p;
        g === null && (l.p = g = /* @__PURE__ */ new Map());
        const b = g.get(m);
        b === void 0 ? (l = je(), g.set(m, l)) : l = b;
      }
    }
    const c = l;
    let f;
    if (l.s === kt)
      f = l.v;
    else if (f = e.apply(null, arguments), s++, o) {
      const h = r?.deref?.() ?? r;
      h != null && o(h, f) && (f = h, s !== 0 && s--), r = typeof f == "object" && f !== null || typeof f == "function" ? new qo(f) : f;
    }
    return c.s = kt, c.v = f, f;
  }
  return a.clearCache = () => {
    n = je(), a.resetResultsCount();
  }, a.resultsCount = () => s, a.resetResultsCount = () => {
    s = 0;
  }, a;
}
function cn(e, ...t) {
  const n = typeof e == "function" ? {
    memoize: e,
    memoizeOptions: t
  } : e, o = (...r) => {
    let s = 0, a = 0, l, i = {}, c = r.pop();
    typeof c == "object" && (i = c, c = r.pop()), Vo(
      c,
      `createSelector expects an output function after the inputs, but received: [${typeof c}]`
    );
    const f = {
      ...n,
      ...i
    }, {
      memoize: h,
      memoizeOptions: p = [],
      argsMemoize: m = ln,
      argsMemoizeOptions: g = [],
      devModeChecks: b = {}
    } = f, C = xt(p), T = xt(g), y = jo(r), E = h(function() {
      return s++, c.apply(
        null,
        arguments
      );
    }, ...C);
    let x = !0;
    const k = m(function() {
      a++;
      const D = Dt(
        y,
        arguments
      );
      if (l = E.apply(null, D), process.env.NODE_ENV !== "production") {
        const { identityFunctionCheck: I, inputStabilityCheck: B } = zo(x, b);
        if (I.shouldRun && I.run(
          c,
          D,
          l
        ), B.shouldRun) {
          const W = Dt(
            y,
            arguments
          );
          B.run(
            { inputSelectorResults: D, inputSelectorResultsCopy: W },
            { memoize: h, memoizeOptions: C },
            arguments
          );
        }
        x && (x = !1);
      }
      return l;
    }, ...T);
    return Object.assign(k, {
      resultFunc: c,
      memoizedResultFunc: E,
      dependencies: y,
      dependencyRecomputations: () => a,
      resetDependencyRecomputations: () => {
        a = 0;
      },
      lastResult: () => l,
      recomputations: () => s,
      resetRecomputations: () => {
        s = 0;
      },
      memoize: h,
      argsMemoize: m
    });
  };
  return Object.assign(o, {
    withTypes: () => o
  }), o;
}
var Jo = /* @__PURE__ */ cn(ln), Qo = Object.assign(
  (e, t = Jo) => {
    Bo(
      e,
      `createStructuredSelector expects first argument to be an object where each property is a selector, instead received a ${typeof e}`
    );
    const n = Object.keys(e), o = n.map(
      (s) => e[s]
    );
    return t(
      o,
      (...s) => s.reduce((a, l, i) => (a[n[i]] = l, a), {})
    );
  },
  { withTypes: () => Qo }
);
cn({
  memoize: Go,
  memoizeOptions: {
    maxSize: 1,
    equalityCheck: Object.is
  }
});
const _ = (e, t, n, o, r, s, ...a) => {
  if (a.length > 0)
    throw new Error(process.env.NODE_ENV !== "production" ? "Unsupported number of selectors" : Me(1));
  let l;
  if (e)
    l = e;
  else
    throw new Error("Missing arguments");
  return l;
};
var ze = { exports: {} }, et = {};
/**
 * @license React
 * use-sync-external-store-shim/with-selector.production.js
 *
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
var It;
function Zo() {
  if (It) return et;
  It = 1;
  var e = Ft, t = Zt();
  function n(c, f) {
    return c === f && (c !== 0 || 1 / c === 1 / f) || c !== c && f !== f;
  }
  var o = typeof Object.is == "function" ? Object.is : n, r = t.useSyncExternalStore, s = e.useRef, a = e.useEffect, l = e.useMemo, i = e.useDebugValue;
  return et.useSyncExternalStoreWithSelector = function(c, f, h, p, m) {
    var g = s(null);
    if (g.current === null) {
      var b = { hasValue: !1, value: null };
      g.current = b;
    } else b = g.current;
    g = l(
      function() {
        function T(w) {
          if (!y) {
            if (y = !0, E = w, w = p(w), m !== void 0 && b.hasValue) {
              var D = b.value;
              if (m(D, w))
                return x = D;
            }
            return x = w;
          }
          if (D = x, o(E, w)) return D;
          var I = p(w);
          return m !== void 0 && m(D, I) ? (E = w, D) : (E = w, x = I);
        }
        var y = !1, E, x, k = h === void 0 ? null : h;
        return [
          function() {
            return T(f());
          },
          k === null ? void 0 : function() {
            return T(k());
          }
        ];
      },
      [f, h, p, m]
    );
    var C = r(c, g[0], g[1]);
    return a(
      function() {
        b.hasValue = !0, b.value = C;
      },
      [C]
    ), i(C), C;
  }, et;
}
var tt = {};
/**
 * @license React
 * use-sync-external-store-shim/with-selector.development.js
 *
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
var Nt;
function er() {
  return Nt || (Nt = 1, process.env.NODE_ENV !== "production" && (function() {
    function e(c, f) {
      return c === f && (c !== 0 || 1 / c === 1 / f) || c !== c && f !== f;
    }
    typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
    var t = Ft, n = Zt(), o = typeof Object.is == "function" ? Object.is : e, r = n.useSyncExternalStore, s = t.useRef, a = t.useEffect, l = t.useMemo, i = t.useDebugValue;
    tt.useSyncExternalStoreWithSelector = function(c, f, h, p, m) {
      var g = s(null);
      if (g.current === null) {
        var b = { hasValue: !1, value: null };
        g.current = b;
      } else b = g.current;
      g = l(
        function() {
          function T(w) {
            if (!y) {
              if (y = !0, E = w, w = p(w), m !== void 0 && b.hasValue) {
                var D = b.value;
                if (m(D, w))
                  return x = D;
              }
              return x = w;
            }
            if (D = x, o(E, w))
              return D;
            var I = p(w);
            return m !== void 0 && m(D, I) ? (E = w, D) : (E = w, x = I);
          }
          var y = !1, E, x, k = h === void 0 ? null : h;
          return [
            function() {
              return T(f());
            },
            k === null ? void 0 : function() {
              return T(k());
            }
          ];
        },
        [f, h, p, m]
      );
      var C = r(c, g[0], g[1]);
      return a(
        function() {
          b.hasValue = !0, b.value = C;
        },
        [C]
      ), i(C), C;
    }, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
  })()), tt;
}
var Mt;
function tr() {
  return Mt || (Mt = 1, process.env.NODE_ENV === "production" ? ze.exports = Zo() : ze.exports = er()), ze.exports;
}
var nr = tr();
const or = zn(19), rr = or ? ir : ar;
function sr(e, t, n, o, r) {
  return rr(e, t, n, o, r);
}
function ir(e, t, n, o, r) {
  const s = u.useCallback(() => t(e.getSnapshot(), n, o, r), [e, t, n, o, r]);
  return io.useSyncExternalStore(e.subscribe, s, s);
}
function ar(e, t, n, o, r) {
  return nr.useSyncExternalStoreWithSelector(e.subscribe, e.getSnapshot, e.getSnapshot, (s) => t(s, n, o, r));
}
class Ie {
  /**
   * The current state of the store.
   * This property is updated immediately when the state changes as a result of calling {@link setState}, {@link update}, or {@link set}.
   * To subscribe to state changes, use the {@link useState} method. The value returned by {@link useState} is updated after the component renders (similarly to React's useState).
   * The values can be used directly (to avoid subscribing to the store) in effects or event handlers.
   *
   * Do not modify properties in state directly. Instead, use the provided methods to ensure proper state management and listener notification.
   */
  // Internal state to handle recursive `setState()` calls
  constructor(t) {
    this.state = t, this.listeners = /* @__PURE__ */ new Set(), this.updateTick = 0;
  }
  /**
   * Registers a listener that will be called whenever the store's state changes.
   *
   * @param fn The listener function to be called on state changes.
   * @returns A function to unsubscribe the listener.
   */
  subscribe = (t) => (this.listeners.add(t), () => {
    this.listeners.delete(t);
  });
  /**
   * Returns the current state of the store.
   */
  getSnapshot = () => this.state;
  /**
   * Updates the entire store's state and notifies all registered listeners.
   *
   * @param newState The new state to set for the store.
   */
  setState(t) {
    if (this.state === t)
      return;
    this.state = t, this.updateTick += 1;
    const n = this.updateTick;
    for (const o of this.listeners) {
      if (n !== this.updateTick)
        return;
      o(t);
    }
  }
  /**
   * Merges the provided changes into the current state and notifies listeners if there are changes.
   *
   * @param changes An object containing the changes to apply to the current state.
   */
  update(t) {
    for (const n in t)
      if (!Object.is(this.state[n], t[n])) {
        Ie.prototype.setState.call(this, {
          ...this.state,
          ...t
        });
        return;
      }
  }
  /**
   * Sets a specific key in the store's state to a new value and notifies listeners if the value has changed.
   *
   * @param key The key in the store's state to update.
   * @param value The new value to set for the specified key.
   */
  set(t, n) {
    Object.is(this.state[t], n) || Ie.prototype.setState.call(this, {
      ...this.state,
      [t]: n
    });
  }
  /**
   * Gives the state a new reference and updates all registered listeners.
   */
  notifyAll() {
    const t = {
      ...this.state
    };
    Ie.prototype.setState.call(this, t);
  }
}
class un extends Ie {
  /**
   * Creates a new ReactStore instance.
   *
   * @param state Initial state of the store.
   * @param context Non-reactive context values.
   * @param selectors Optional selectors for use with `useState`.
   */
  constructor(t, n = {}, o) {
    super(t), this.context = n, this.selectors = o;
  }
  /**
   * Non-reactive values such as refs, callbacks, etc.
   */
  /**
   * Keeps track of which properties are controlled.
   */
  controlledValues = /* @__PURE__ */ new Map();
  /**
   * Synchronizes a single external value into the store.
   *
   * Note that the while the value in `state` is updated immediately, the value returned
   * by `useState` is updated before the next render (similarly to React's `useState`).
   */
  useSyncedValue(t, n) {
    u.useDebugValue(t), Z(() => {
      this.state[t] !== n && this.set(t, n);
    }, [t, n]);
  }
  /**
   * Synchronizes a single external value into the store and
   * cleans it up (sets to `undefined`) on unmount.
   *
   * Note that the while the value in `state` is updated immediately, the value returned
   * by `useState` is updated before the next render (similarly to React's `useState`).
   */
  useSyncedValueWithCleanup(t, n) {
    Z(() => (this.state[t] !== n && this.set(t, n), () => {
      this.set(t, void 0);
    }), [t, n]);
  }
  /**
   * Synchronizes multiple external values into the store.
   *
   * Note that the while the values in `state` are updated immediately, the values returned
   * by `useState` are updated before the next render (similarly to React's `useState`).
   */
  useSyncedValues(t) {
    if (process.env.NODE_ENV !== "production") {
      u.useDebugValue(t, (s) => Object.keys(s));
      const o = u.useRef(Object.keys(t)).current, r = Object.keys(t);
      (o.length !== r.length || o.some((s, a) => s !== r[a])) && console.error("ReactStore.useSyncedValues expects the same prop keys on every render. Keys should be stable.");
    }
    const n = Object.values(t);
    Z(() => {
      this.update(t);
    }, n);
  }
  /**
   * Registers a controllable prop pair (`controlled`, `defaultValue`) for a specific key.
   * - If `controlled` is non-undefined, the key is marked as controlled and the store's
   *   state at `key` is updated to match `controlled`. Local writes to that key are ignored.
   * - If `controlled` is undefined, the key is marked as uncontrolled. The store's state
   *   is initialized to `defaultValue` on first render and can be updated with local writes.
   */
  useControlledProp(t, n, o) {
    u.useDebugValue(t);
    const r = n !== void 0;
    if (process.env.NODE_ENV !== "production") {
      const s = this.controlledValues.get(t);
      s !== void 0 && s !== r && console.error(`A component is changing the ${r ? "" : "un"}controlled state of ${t.toString()} to be ${r ? "un" : ""}controlled. Elements should not switch from uncontrolled to controlled (or vice versa).`);
    }
    this.controlledValues.has(t) || (this.controlledValues.set(t, r), !r && !Object.is(this.state[t], o) && super.setState({
      ...this.state,
      [t]: o
    })), Z(() => {
      r && !Object.is(this.state[t], n) && super.setState({
        ...this.state,
        [t]: n
      });
    }, [t, n, o, r]);
  }
  /**
   * Sets a specific key in the store's state to a new value and notifies listeners if the value has changed.
   * If the key is controlled (registered via {@link useControlledProp} with a non-undefined value),
   * the update is ignored and no listeners are notified.
   *
   * @param key The state key to update.
   * @param value The new value to set for the specified key.
   */
  set(t, n) {
    this.controlledValues.get(t) !== !0 && super.set(t, n);
  }
  /**
   * Merges the provided changes into the current state and notifies listeners if there are changes.
   * Controlled keys are filtered out and not updated.
   *
   * @param values An object containing the changes to apply to the current state.
   */
  update(t) {
    const n = {
      ...t
    };
    for (const o in n)
      if (Object.hasOwn(n, o) && this.controlledValues.get(o) === !0) {
        delete n[o];
        continue;
      }
    super.update(n);
  }
  /**
   * Updates the entire store's state and notifies all registered listeners.
   * Controlled keys are left unchanged; only uncontrolled keys from `newState` are applied.
   *
   * @param newState The new state to set for the store.
   */
  setState(t) {
    const n = {
      ...t
    };
    for (const o in n)
      if (Object.hasOwn(n, o) && this.controlledValues.get(o) === !0) {
        delete n[o];
        continue;
      }
    super.setState({
      ...this.state,
      ...n
    });
  }
  /** Gets the current value from the store using a selector with the provided key.
   *
   * @param key Key of the selector to use.
   */
  select = (t, n, o, r) => {
    const s = this.selectors[t];
    return s(this.state, n, o, r);
  };
  /**
   * Returns a value from the store's state using a selector function.
   * Used to subscribe to specific parts of the state.
   * This methods causes a rerender whenever the selected state changes.
   *
   * @param key Key of the selector to use.
   */
  useState = (t, n, o, r) => {
    u.useDebugValue(t);
    const s = this.selectors[t];
    return sr(this, s, n, o, r);
  };
  /**
   * Wraps a function with `useStableCallback` to ensure it has a stable reference
   * and assigns it to the context.
   *
   * @param key Key of the event callback. Must be a function in the context.
   * @param fn Function to assign.
   */
  useContextCallback(t, n) {
    u.useDebugValue(t);
    const o = V(n ?? Lt);
    this.context[t] = o;
  }
  /**
   * Returns a stable setter function for a specific key in the store's state.
   * It's commonly used to pass as a ref callback to React elements.
   *
   * @param key Key of the state to set.
   */
  useStateSetter(t) {
    const n = u.useRef(void 0);
    return n.current === void 0 && (n.current = (o) => {
      this.set(t, o);
    }), n.current;
  }
  /**
   * Observes changes derived from the store's selectors and calls the listener when the selected value changes.
   *
   * @param key Key of the selector to observe.
   * @param listener Listener function called when the selector result changes.
   */
  observe(t, n) {
    let o;
    typeof t == "function" ? o = t : o = this.selectors[t];
    let r = o(this.state);
    return n(r, r, this), this.subscribe((s) => {
      const a = o(s);
      if (!Object.is(r, a)) {
        const l = r;
        r = a, n(a, l, this);
      }
    });
  }
}
const lr = {
  open: _((e) => e.open),
  domReferenceElement: _((e) => e.domReferenceElement),
  referenceElement: _((e) => e.positionReference ?? e.referenceElement),
  floatingElement: _((e) => e.floatingElement),
  floatingId: _((e) => e.floatingId)
};
class dn extends un {
  constructor(t) {
    const {
      nested: n,
      noEmit: o,
      onOpenChange: r,
      triggerElements: s,
      ...a
    } = t;
    super({
      ...a,
      positionReference: a.referenceElement,
      domReferenceElement: a.referenceElement
    }, {
      onOpenChange: r,
      dataRef: {
        current: {}
      },
      events: Co(),
      nested: n,
      noEmit: o,
      triggerElements: s
    }, lr);
  }
  /**
   * Emits the `openchange` event through the internal event emitter and calls the `onOpenChange` handler with the provided arguments.
   *
   * @param newOpen The new open state.
   * @param eventDetails Details about the event that triggered the open state change.
   */
  setOpen = (t, n) => {
    if ((!t || !this.state.open || // Prevent a pending hover-open from overwriting a click-open event, while allowing
    // click events to upgrade a hover-open.
    en(n.event)) && (this.context.dataRef.current.openEvent = t ? n.event : void 0), !this.context.noEmit) {
      const o = {
        open: t,
        reason: n.reason,
        nativeEvent: n.event,
        nested: this.context.nested,
        triggerElement: n.trigger
      };
      this.context.events.emit("openchange", o);
    }
    this.context.onOpenChange?.(t, n);
  };
}
function cr(e, t) {
  const n = u.useRef(null);
  return u.useCallback((o) => {
    e !== void 0 && (n.current !== null && (t.context.triggerElements.delete(n.current), n.current = null), o !== null && (n.current = e, t.context.triggerElements.add(e, o)));
  }, [t, e]);
}
function ur(e, t, n, o) {
  const r = n.useState("isMountedByTrigger", e), s = cr(e, n), a = V((l) => {
    s(l), l !== null && n.select("open") && n.select("activeTriggerId") == null && n.update({
      activeTriggerId: e,
      activeTriggerElement: l,
      ...o
    });
  });
  return Z(() => {
    r && n.update({
      activeTriggerElement: t.current,
      ...o
    });
  }, [r, n, t, ...Object.values(o)]), {
    registerTrigger: a,
    isMountedByThisTrigger: r
  };
}
function dr(e) {
  const t = e.useState("open");
  Z(() => {
    if (t && !e.select("activeTriggerId") && e.context.triggerElements.size === 1) {
      const n = e.context.triggerElements.entries().next();
      if (!n.done) {
        const [o, r] = n.value;
        e.update({
          activeTriggerId: o,
          activeTriggerElement: r
        });
      }
    }
  }, [t, e]);
}
function fr(e, t, n) {
  const {
    mounted: o,
    setMounted: r,
    transitionStatus: s
  } = so(e);
  t.useSyncedValues({
    mounted: o,
    transitionStatus: s
  });
  const a = V(() => {
    r(!1), t.update({
      activeTriggerId: null,
      activeTriggerElement: null,
      mounted: !1
    }), n?.(), t.context.onOpenChangeComplete?.(!1);
  }), l = t.useState("preventUnmountingOnClose");
  return Wt({
    enabled: !l,
    open: e,
    ref: t.context.popupRef,
    onComplete() {
      e || a();
    }
  }), {
    forceUnmount: a,
    transitionStatus: s
  };
}
class fn {
  constructor() {
    this.elements = /* @__PURE__ */ new Set(), this.idMap = /* @__PURE__ */ new Map();
  }
  /**
   * Adds a trigger element with the given ID.
   *
   * Note: The provided element is assumed to not be registered under multiple IDs.
   */
  add(t, n) {
    const o = this.idMap.get(t);
    if (o !== n && (o !== void 0 && this.elements.delete(o), this.elements.add(n), this.idMap.set(t, n), process.env.NODE_ENV !== "production" && this.elements.size !== this.idMap.size))
      throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: A trigger element cannot be registered under multiple IDs in PopupTriggerMap." : Me(87));
  }
  /**
   * Removes the trigger element with the given ID.
   */
  delete(t) {
    const n = this.idMap.get(t);
    n && (this.elements.delete(n), this.idMap.delete(t));
  }
  /**
   * Whether the given element is registered as a trigger.
   */
  hasElement(t) {
    return this.elements.has(t);
  }
  /**
   * Whether there is a registered trigger element matching the given predicate.
   */
  hasMatchingElement(t) {
    for (const n of this.elements)
      if (t(n))
        return !0;
    return !1;
  }
  getById(t) {
    return this.idMap.get(t);
  }
  entries() {
    return this.idMap.entries();
  }
  get size() {
    return this.idMap.size;
  }
}
function pr() {
  return new dn({
    open: !1,
    floatingElement: null,
    referenceElement: null,
    triggerElements: new fn(),
    floatingId: "",
    nested: !1,
    noEmit: !1,
    onOpenChange: void 0
  });
}
function gr() {
  return {
    open: !1,
    mounted: !1,
    transitionStatus: "idle",
    floatingRootContext: pr(),
    preventUnmountingOnClose: !1,
    payload: void 0,
    activeTriggerId: null,
    activeTriggerElement: null,
    popupElement: null,
    positionerElement: null,
    activeTriggerProps: ke,
    inactiveTriggerProps: ke,
    popupProps: ke
  };
}
const mr = {
  open: _((e) => e.open),
  mounted: _((e) => e.mounted),
  transitionStatus: _((e) => e.transitionStatus),
  floatingRootContext: _((e) => e.floatingRootContext),
  preventUnmountingOnClose: _((e) => e.preventUnmountingOnClose),
  payload: _((e) => e.payload),
  activeTriggerId: _((e) => e.activeTriggerId),
  activeTriggerElement: _((e) => e.mounted ? e.activeTriggerElement : null),
  /**
   * Whether the trigger with the given ID was used to open the popup.
   */
  isTriggerActive: _((e, t) => t !== void 0 && e.activeTriggerId === t),
  /**
   * Whether the popup is open and was activated by a trigger with the given ID.
   */
  isOpenedByTrigger: _((e, t) => t !== void 0 && e.activeTriggerId === t && e.open),
  /**
   * Whether the popup is mounted and was activated by a trigger with the given ID.
   */
  isMountedByTrigger: _((e, t) => t !== void 0 && e.activeTriggerId === t && e.mounted),
  triggerProps: _((e, t) => t ? e.activeTriggerProps : e.inactiveTriggerProps),
  popupProps: _((e) => e.popupProps),
  popupElement: _((e) => e.popupElement),
  positionerElement: _((e) => e.positionerElement)
};
function hr(e) {
  const {
    popupStore: t,
    noEmit: n = !1,
    treatPopupAsFloatingElement: o = !1,
    onOpenChange: r
  } = e, s = jt(), a = rn() != null, l = t.useState("open"), i = t.useState("activeTriggerElement"), c = t.useState(o ? "popupElement" : "positionerElement"), f = t.context.triggerElements, h = zt(() => new dn({
    open: l,
    referenceElement: i,
    floatingElement: c,
    triggerElements: f,
    onOpenChange: r,
    floatingId: s,
    nested: a,
    noEmit: n
  })).current;
  return Z(() => {
    const p = {
      open: l,
      floatingId: s,
      referenceElement: i,
      floatingElement: c
    };
    pe(i) && (p.domReferenceElement = i), h.update(p);
  }, [l, s, i, c, h]), h.context.onOpenChange = r, h.context.nested = a, h.context.noEmit = n, h;
}
function pn(e = []) {
  const t = e.map((c) => c?.reference), n = e.map((c) => c?.floating), o = e.map((c) => c?.item), r = e.map((c) => c?.trigger), s = u.useCallback(
    (c) => Ke(c, e, "reference"),
    // eslint-disable-next-line react-hooks/exhaustive-deps
    t
  ), a = u.useCallback(
    (c) => Ke(c, e, "floating"),
    // eslint-disable-next-line react-hooks/exhaustive-deps
    n
  ), l = u.useCallback(
    (c) => Ke(c, e, "item"),
    // eslint-disable-next-line react-hooks/exhaustive-deps
    o
  ), i = u.useCallback(
    (c) => Ke(c, e, "trigger"),
    // eslint-disable-next-line react-hooks/exhaustive-deps
    r
  );
  return u.useMemo(() => ({
    getReferenceProps: s,
    getFloatingProps: a,
    getItemProps: l,
    getTriggerProps: i
  }), [s, a, l, i]);
}
function Ke(e, t, n) {
  const o = /* @__PURE__ */ new Map(), r = n === "item", s = {};
  n === "floating" && (s.tabIndex = -1, s[no] = "");
  for (const a in e)
    r && e && (a === Jt || a === Qt) || (s[a] = e[a]);
  for (let a = 0; a < t.length; a += 1) {
    let l;
    const i = t[a]?.[n];
    typeof i == "function" ? l = e ? i(e) : null : l = i, l && Pt(s, l, r, o);
  }
  return Pt(s, e, r, o), s;
}
function Pt(e, t, n, o) {
  for (const r in t) {
    const s = t[r];
    n && (r === Jt || r === Qt) || (r.startsWith("on") ? (o.has(r) || o.set(r, []), typeof s == "function" && (o.get(r)?.push(s), e[r] = (...a) => o.get(r)?.map((l) => l(...a)).find((l) => l !== void 0))) : e[r] = s);
  }
}
const Er = /* @__PURE__ */ new Map([["select", "listbox"], ["combobox", "listbox"], ["label", !1]]);
function yr(e, t = {}) {
  const n = "rootStore" in e ? e.rootStore : e, o = n.useState("open"), r = n.useState("floatingId"), s = n.useState("domReferenceElement"), a = n.useState("floatingElement"), {
    enabled: l = !0,
    role: i = "dialog"
  } = t, c = jt(), f = s?.id || c, h = u.useMemo(() => ot(a)?.id || r, [a, r]), p = Er.get(i) ?? i, g = rn() != null, b = u.useMemo(() => p === "tooltip" || i === "label" ? ke : {
    "aria-haspopup": p === "alertdialog" ? "dialog" : p,
    "aria-expanded": "false",
    ...p === "listbox" && {
      role: "combobox"
    },
    ...p === "menu" && g && {
      role: "menuitem"
    },
    ...i === "select" && {
      "aria-autocomplete": "none"
    },
    ...i === "combobox" && {
      "aria-autocomplete": "list"
    }
  }, [p, g, i]), C = u.useMemo(() => p === "tooltip" || i === "label" ? {
    [`aria-${i === "label" ? "labelledby" : "describedby"}`]: o ? h : void 0
  } : {
    ...b,
    "aria-expanded": o ? "true" : "false",
    "aria-controls": o ? h : void 0,
    ...p === "menu" && {
      id: f
    }
  }, [p, h, o, f, i, b]), T = u.useMemo(() => {
    const E = {
      id: h,
      ...p && {
        role: p
      }
    };
    return p === "tooltip" || i === "label" ? E : {
      ...E,
      ...p === "menu" && {
        "aria-labelledby": f
      }
    };
  }, [p, h, f, i]), y = u.useCallback(({
    active: E,
    selected: x
  }) => {
    const k = {
      role: "option",
      ...E && {
        id: `${h}-fui-option`
      }
    };
    switch (i) {
      case "select":
      case "combobox":
        return {
          ...k,
          "aria-selected": x
        };
    }
    return {};
  }, [h, i]);
  return u.useMemo(() => l ? {
    reference: C,
    floating: T,
    item: y,
    trigger: b
  } : {}, [l, C, T, b, y]);
}
function br(e) {
  const t = u.useRef(""), n = u.useCallback((r) => {
    r.defaultPrevented || (t.current = r.pointerType, e(r, r.pointerType));
  }, [e]);
  return {
    onClick: u.useCallback((r) => {
      if (r.detail === 0) {
        e(r, "keyboard");
        return;
      }
      "pointerType" in r && e(r, r.pointerType), e(r, t.current), t.current = "";
    }, [e]),
    onPointerDown: n
  };
}
function vr(e) {
  const [t, n] = u.useState(null), o = V((l, i) => {
    e || n(i);
  }), r = u.useCallback(() => {
    n(null);
  }, []), {
    onClick: s,
    onPointerDown: a
  } = br(o);
  return u.useMemo(() => ({
    openMethod: t,
    reset: r,
    triggerProps: {
      onClick: s,
      onPointerDown: a
    }
  }), [t, r, s, a]);
}
function Sr(e) {
  const {
    store: t,
    parentContext: n,
    actionsRef: o
  } = e, r = t.useState("open"), s = t.useState("disablePointerDismissal"), a = t.useState("modal"), l = t.useState("popupElement"), {
    openMethod: i,
    triggerProps: c,
    reset: f
  } = vr(r);
  dr(t);
  const {
    forceUnmount: h
  } = fr(r, t, () => {
    f();
  }), p = V((W) => {
    const H = se(W);
    return H.preventUnmountOnClose = () => {
      t.set("preventUnmountingOnClose", !0);
    }, H;
  }), m = u.useCallback(() => {
    t.setOpen(!1, p(Kn));
  }, [t, p]);
  u.useImperativeHandle(o, () => ({
    unmount: h,
    close: m
  }), [h, m]);
  const g = hr({
    popupStore: t,
    onOpenChange: t.setOpen,
    treatPopupAsFloatingElement: !0,
    noEmit: !0
  }), [b, C] = u.useState(0), T = b === 0, y = yr(g), E = Ao(g, {
    outsidePressEvent() {
      return t.context.internalBackdropRef.current || t.context.backdropRef.current ? "intentional" : {
        mouse: a === "trap-focus" ? "sloppy" : "intentional",
        touch: "sloppy"
      };
    },
    outsidePress(W) {
      if ("button" in W && W.button !== 0 || "touches" in W && W.touches.length !== 1)
        return !1;
      const H = re(W);
      if (T && !s) {
        const q = H;
        return a && (t.context.internalBackdropRef.current || t.context.backdropRef.current) ? t.context.internalBackdropRef.current === q || t.context.backdropRef.current === q || $(q, l) && !q?.hasAttribute("data-base-ui-portal") : !0;
      }
      return !1;
    },
    escapeKey: T
  });
  So(r && a === !0, l);
  const {
    getReferenceProps: x,
    getFloatingProps: k,
    getTriggerProps: w
  } = pn([y, E]);
  t.useContextCallback("onNestedDialogOpen", (W) => {
    C(W + 1);
  }), t.useContextCallback("onNestedDialogClose", () => {
    C(0);
  }), u.useEffect(() => (n?.onNestedDialogOpen && r && n.onNestedDialogOpen(b), n?.onNestedDialogClose && !r && n.onNestedDialogClose(), () => {
    n?.onNestedDialogClose && r && n.onNestedDialogClose();
  }), [r, n, b]);
  const D = u.useMemo(() => x(c), [x, c]), I = u.useMemo(() => w(c), [w, c]), B = u.useMemo(() => k(), [k]);
  t.useSyncedValues({
    openMethod: i,
    activeTriggerProps: D,
    inactiveTriggerProps: I,
    popupProps: B,
    floatingRootContext: g,
    nestedOpenDialogCount: b
  });
}
const lt = /* @__PURE__ */ u.createContext(void 0);
process.env.NODE_ENV !== "production" && (lt.displayName = "DialogRootContext");
function de(e) {
  const t = u.useContext(lt);
  if (e === !1 && t === void 0)
    throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: DialogRootContext is missing. Dialog parts must be placed within <Dialog.Root>." : Me(27));
  return t;
}
const Cr = {
  ...mr,
  modal: _((e) => e.modal),
  nested: _((e) => e.nested),
  nestedOpenDialogCount: _((e) => e.nestedOpenDialogCount),
  disablePointerDismissal: _((e) => e.disablePointerDismissal),
  openMethod: _((e) => e.openMethod),
  descriptionElementId: _((e) => e.descriptionElementId),
  titleElementId: _((e) => e.titleElementId),
  viewportElement: _((e) => e.viewportElement),
  role: _((e) => e.role)
};
class Rr extends un {
  constructor(t) {
    super(Tr(t), {
      popupRef: /* @__PURE__ */ u.createRef(),
      backdropRef: /* @__PURE__ */ u.createRef(),
      internalBackdropRef: /* @__PURE__ */ u.createRef(),
      triggerElements: new fn(),
      onOpenChange: void 0,
      onOpenChangeComplete: void 0
    }, Cr);
  }
  setOpen = (t, n) => {
    if (n.preventUnmountOnClose = () => {
      this.set("preventUnmountingOnClose", !0);
    }, !t && n.trigger == null && this.state.activeTriggerId != null && (n.trigger = this.state.activeTriggerElement ?? void 0), this.context.onOpenChange?.(t, n), n.isCanceled)
      return;
    const o = {
      open: t,
      nativeEvent: n.event,
      reason: n.reason,
      nested: this.state.nested
    };
    this.state.floatingRootContext.context.events?.emit("openchange", o);
    const r = {
      open: t
    }, s = n.trigger?.id ?? null;
    (s || t) && (r.activeTriggerId = s, r.activeTriggerElement = n.trigger ?? null), this.update(r);
  };
}
function Tr(e = {}) {
  return {
    ...gr(),
    modal: !0,
    disablePointerDismissal: !1,
    popupElement: null,
    viewportElement: null,
    descriptionElementId: void 0,
    titleElementId: void 0,
    openMethod: null,
    nested: !1,
    nestedOpenDialogCount: 0,
    role: "dialog",
    ...e
  };
}
function Or(e) {
  const {
    children: t,
    open: n,
    defaultOpen: o = !1,
    onOpenChange: r,
    onOpenChangeComplete: s,
    actionsRef: a,
    handle: l,
    triggerId: i,
    defaultTriggerId: c = null
  } = e, f = de(), h = !!f, p = zt(() => l?.store ?? new Rr({
    open: n ?? o,
    activeTriggerId: i !== void 0 ? i : c,
    modal: !0,
    disablePointerDismissal: !0,
    nested: h,
    role: "alertdialog"
  })).current;
  p.useControlledProp("open", n, o), p.useControlledProp("activeTriggerId", i, c), p.useSyncedValue("nested", h), p.useContextCallback("onOpenChange", r), p.useContextCallback("onOpenChangeComplete", s);
  const m = p.useState("payload");
  Sr({
    store: p,
    actionsRef: a,
    parentContext: f?.store.context
  });
  const g = u.useMemo(() => ({
    store: p
  }), [p]);
  return /* @__PURE__ */ K(lt.Provider, {
    value: g,
    children: typeof t == "function" ? t({
      payload: m
    }) : t
  });
}
let ge = (function(e) {
  return e.open = "data-open", e.closed = "data-closed", e[e.startingStyle = gt.startingStyle] = "startingStyle", e[e.endingStyle = gt.endingStyle] = "endingStyle", e.anchorHidden = "data-anchor-hidden", e;
})({}), wr = /* @__PURE__ */ (function(e) {
  return e.popupOpen = "data-popup-open", e.pressed = "data-pressed", e;
})({});
const xr = {
  [wr.popupOpen]: ""
}, Dr = {
  [ge.open]: ""
}, kr = {
  [ge.closed]: ""
}, Ir = {
  [ge.anchorHidden]: ""
}, Nr = {
  open(e) {
    return e ? xr : null;
  }
}, gn = {
  open(e) {
    return e ? Dr : kr;
  },
  anchorHidden(e) {
    return e ? Ir : null;
  }
}, Mr = {
  ...gn,
  ...Kt
}, mn = /* @__PURE__ */ u.forwardRef(function(t, n) {
  const {
    render: o,
    className: r,
    forceRender: s = !1,
    ...a
  } = t, {
    store: l
  } = de(), i = l.useState("open"), c = l.useState("nested"), f = l.useState("mounted"), h = l.useState("transitionStatus"), p = u.useMemo(() => ({
    open: i,
    transitionStatus: h
  }), [i, h]);
  return Re("div", t, {
    state: p,
    ref: [l.context.backdropRef, n],
    stateAttributesMapping: Mr,
    props: [{
      role: "presentation",
      hidden: !f,
      style: {
        userSelect: "none",
        WebkitUserSelect: "none"
      }
    }, a],
    enabled: s || !c
  });
});
process.env.NODE_ENV !== "production" && (mn.displayName = "DialogBackdrop");
const ct = /* @__PURE__ */ u.forwardRef(function(t, n) {
  const {
    render: o,
    className: r,
    disabled: s = !1,
    nativeButton: a = !0,
    ...l
  } = t, {
    store: i
  } = de(), c = i.useState("open");
  function f(g) {
    c && i.setOpen(!1, se(Hn, g.nativeEvent));
  }
  const {
    getButtonProps: h,
    buttonRef: p
  } = Ht({
    disabled: s,
    native: a
  }), m = u.useMemo(() => ({
    disabled: s
  }), [s]);
  return Re("button", t, {
    state: m,
    ref: [n, p],
    props: [{
      onClick: f
    }, l, h]
  });
});
process.env.NODE_ENV !== "production" && (ct.displayName = "DialogClose");
const hn = /* @__PURE__ */ u.forwardRef(function(t, n) {
  const {
    render: o,
    className: r,
    id: s,
    ...a
  } = t, {
    store: l
  } = de(), i = it(s);
  return l.useSyncedValueWithCleanup("descriptionElementId", i), Re("p", t, {
    ref: n,
    props: [{
      id: i
    }, a]
  });
});
process.env.NODE_ENV !== "production" && (hn.displayName = "DialogDescription");
let Pr = /* @__PURE__ */ (function(e) {
  return e.nestedDialogs = "--nested-dialogs", e;
})({}), Ar = (function(e) {
  return e[e.open = ge.open] = "open", e[e.closed = ge.closed] = "closed", e[e.startingStyle = ge.startingStyle] = "startingStyle", e[e.endingStyle = ge.endingStyle] = "endingStyle", e.nested = "data-nested", e.nestedDialogOpen = "data-nested-dialog-open", e;
})({});
const ut = /* @__PURE__ */ u.createContext(void 0);
process.env.NODE_ENV !== "production" && (ut.displayName = "DialogPortalContext");
function Fr() {
  const e = u.useContext(ut);
  if (e === void 0)
    throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: <Dialog.Portal> is missing." : Me(26));
  return e;
}
const _r = {
  ...gn,
  ...Kt,
  nestedDialogOpen(e) {
    return e ? {
      [Ar.nestedDialogOpen]: ""
    } : null;
  }
}, En = /* @__PURE__ */ u.forwardRef(function(t, n) {
  const {
    className: o,
    finalFocus: r,
    initialFocus: s,
    render: a,
    ...l
  } = t, {
    store: i
  } = de(), c = i.useState("descriptionElementId"), f = i.useState("disablePointerDismissal"), h = i.useState("floatingRootContext"), p = i.useState("popupProps"), m = i.useState("modal"), g = i.useState("mounted"), b = i.useState("nested"), C = i.useState("nestedOpenDialogCount"), T = i.useState("open"), y = i.useState("openMethod"), E = i.useState("titleElementId"), x = i.useState("transitionStatus"), k = i.useState("role");
  Fr(), Wt({
    open: T,
    ref: i.context.popupRef,
    onComplete() {
      T && i.context.onOpenChangeComplete?.(!0);
    }
  });
  function w(H) {
    return H === "touch" ? i.context.popupRef.current : !0;
  }
  const D = s === void 0 ? w : s, I = C > 0, B = u.useMemo(() => ({
    open: T,
    nested: b,
    transitionStatus: x,
    nestedDialogOpen: I
  }), [T, b, x, I]), W = Re("div", t, {
    state: B,
    props: [p, {
      "aria-labelledby": E ?? void 0,
      "aria-describedby": c ?? void 0,
      role: k,
      tabIndex: -1,
      hidden: !g,
      onKeyDown(H) {
        fo.has(H.key) && H.stopPropagation();
      },
      style: {
        [Pr.nestedDialogs]: C
      }
    }, l],
    ref: [n, i.context.popupRef, i.useStateSetter("popupElement")],
    stateAttributesMapping: _r
  });
  return /* @__PURE__ */ K(Io, {
    context: h,
    openInteractionType: y,
    disabled: !g,
    closeOnFocusOut: !f,
    initialFocus: D,
    returnFocus: r,
    modal: m !== !1,
    restoreFocus: "popup",
    children: W
  });
});
process.env.NODE_ENV !== "production" && (En.displayName = "DialogPopup");
const yn = /* @__PURE__ */ u.forwardRef(function(t, n) {
  const {
    cutout: o,
    ...r
  } = t;
  let s;
  if (o) {
    const a = o?.getBoundingClientRect();
    s = `polygon(
      0% 0%,
      100% 0%,
      100% 100%,
      0% 100%,
      0% 0%,
      ${a.left}px ${a.top}px,
      ${a.left}px ${a.bottom}px,
      ${a.right}px ${a.bottom}px,
      ${a.right}px ${a.top}px,
      ${a.left}px ${a.top}px
    )`;
  }
  return /* @__PURE__ */ K("div", {
    ref: n,
    role: "presentation",
    "data-base-ui-inert": "",
    ...r,
    style: {
      position: "fixed",
      inset: 0,
      userSelect: "none",
      WebkitUserSelect: "none",
      clipPath: s
    }
  });
});
process.env.NODE_ENV !== "production" && (yn.displayName = "InternalBackdrop");
const bn = /* @__PURE__ */ u.forwardRef(function(t, n) {
  const {
    keepMounted: o = !1,
    ...r
  } = t, {
    store: s
  } = de(), a = s.useState("mounted"), l = s.useState("modal");
  return a || o ? /* @__PURE__ */ K(ut.Provider, {
    value: o,
    children: /* @__PURE__ */ At(oo, {
      ref: n,
      ...r,
      children: [a && l === !0 && /* @__PURE__ */ K(yn, {
        ref: s.context.internalBackdropRef,
        inert: ro(!open)
      }), t.children]
    })
  }) : null;
});
process.env.NODE_ENV !== "production" && (bn.displayName = "DialogPortal");
const vn = /* @__PURE__ */ u.forwardRef(function(t, n) {
  const {
    render: o,
    className: r,
    id: s,
    ...a
  } = t, {
    store: l
  } = de(), i = it(s);
  return l.useSyncedValueWithCleanup("titleElementId", i), Re("h2", t, {
    ref: n,
    props: [{
      id: i
    }, a]
  });
});
process.env.NODE_ENV !== "production" && (vn.displayName = "DialogTitle");
const Sn = /* @__PURE__ */ u.forwardRef(function(t, n) {
  const {
    render: o,
    className: r,
    disabled: s = !1,
    nativeButton: a = !0,
    id: l,
    payload: i,
    handle: c,
    ...f
  } = t, h = de(!0), p = c?.store ?? h?.store;
  if (!p)
    throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: <Dialog.Trigger> must be used within <Dialog.Root> or provided with a handle." : Me(79));
  const m = it(l), g = p.useState("floatingRootContext"), b = p.useState("isOpenedByTrigger", m), C = u.useRef(null), {
    registerTrigger: T,
    isMountedByThisTrigger: y
  } = ur(m, C, p, {
    payload: i
  }), {
    getButtonProps: E,
    buttonRef: x
  } = Ht({
    disabled: s,
    native: a
  }), k = No(g, {
    enabled: g != null
  }), w = pn([k]), D = u.useMemo(() => ({
    disabled: s,
    open: b
  }), [s, b]), I = p.useState("triggerProps", y);
  return Re("button", t, {
    state: D,
    ref: [x, n, T, C],
    props: [w.getReferenceProps(), I, {
      [Xt]: "",
      id: m
    }, f, E],
    stateAttributesMapping: Nr
  });
});
process.env.NODE_ENV !== "production" && (Sn.displayName = "DialogTrigger");
const Cn = Fn(null), Lr = ({
  children: e,
  withFade: t = !1,
  cancelRef: n
}) => /* @__PURE__ */ K(
  Cn.Provider,
  {
    value: {
      cancelRef: n,
      withFade: t
    },
    children: e
  }
), dt = () => {
  const e = _n(Cn);
  if (!e)
    throw Error("useAlertDialog must be used within an AlertDialog provider");
  return e;
}, Rn = ({ onOpenChange: e, withFade: t = !1, ...n }) => {
  const o = _t(null);
  return /* @__PURE__ */ K(Lr, { withFade: t, cancelRef: o, children: /* @__PURE__ */ K(
    Or,
    {
      "data-spark-component": "alert-dialog",
      onOpenChange: e ? (s, a) => {
        e(s);
      } : void 0,
      ...n
    }
  ) });
};
Rn.displayName = "AlertDialog";
function ft(e, t) {
  const n = e ? po : t;
  return e ? ({ ...o }) => /* @__PURE__ */ K(n, { ...o }) : void 0;
}
const Tn = ({ asChild: e = !1, ...t }) => {
  const n = ft(e, "button");
  return /* @__PURE__ */ K(
    ct,
    {
      "data-spark-component": "alert-dialog-action",
      render: n,
      ...t
    }
  );
};
Tn.displayName = "AlertDialog.Action";
const On = ({
  children: e,
  className: t,
  inset: n = !1,
  ref: o,
  ...r
}) => {
  const s = _t(null), a = tn(o, s), { withFade: l } = dt(), { overflow: i } = go(s);
  return /* @__PURE__ */ K(
    "div",
    {
      "data-spark-component": "alert-dialog-body",
      ref: a,
      className: Te(
        "focus-visible:u-outline relative grow overflow-y-auto outline-hidden",
        "transition-all duration-300",
        {
          "px-xl py-lg": !n
        },
        t
      ),
      style: {
        ...l && {
          maskImage: "linear-gradient(to bottom, rgba(0, 0, 0, 0), rgba(0, 0, 0, 1) 44px, rgba(0, 0, 0, 1) calc(100% - 44px), rgba(0, 0, 0, 0))",
          maskSize: `100% calc(100% + ${i.top ? "0px" : "44px"} + ${i.bottom ? "0px" : "44px"})`,
          maskPosition: `0 ${i.top ? "0px" : "-44px"}`
        }
      },
      ...r,
      children: e
    }
  );
};
On.displayName = "AlertDialog.Body";
const wn = ({
  asChild: e = !1,
  ref: t,
  ...n
}) => {
  const { cancelRef: o } = dt(), r = tn(t, o), s = ft(e, "button");
  return /* @__PURE__ */ K(
    ct,
    {
      ref: r,
      "data-spark-component": "alert-dialog-cancel",
      render: s,
      ...n
    }
  );
};
wn.displayName = "AlertDialog.Cancel";
const xn = ({
  className: e,
  ref: t,
  initialFocus: n,
  ...o
}) => {
  const { cancelRef: r } = dt();
  return /* @__PURE__ */ K(
    En,
    {
      ref: t,
      "data-spark-component": "alert-dialog-content",
      role: "alertdialog",
      className: (a) => Te(
        mo({ size: "md", isNarrow: !0 }),
        "min-w-sz-288",
        // Base UI automatically adds data-[starting-style] and data-[ending-style] attributes
        // Transition with opacity and scale for smooth open/close animations
        "transition-all duration-150",
        "data-starting-style:scale-90 data-starting-style:opacity-0",
        "data-ending-style:scale-90 data-ending-style:opacity-0",
        typeof e == "function" ? e(a) : e
      ),
      initialFocus: n !== void 0 ? n : () => r.current,
      ...o
    }
  );
};
xn.displayName = "AlertDialog.Content";
const Dn = (e) => /* @__PURE__ */ K(hn, { "data-spark-component": "alert-dialog-description", ...e });
Dn.displayName = "AlertDialog.Description";
const kn = ({
  children: e,
  className: t,
  ref: n,
  ...o
}) => /* @__PURE__ */ K(
  "footer",
  {
    "data-spark-component": "alert-dialog-footer",
    ref: n,
    className: Te(t, ["px-xl", "py-lg"]),
    ...o,
    children: e
  }
);
kn.displayName = "AlertDialog.Footer";
const In = ({
  children: e,
  className: t,
  ref: n,
  ...o
}) => /* @__PURE__ */ K(
  "header",
  {
    "data-spark-component": "alert-dialog-header",
    ref: n,
    className: Te(t, ["px-xl", "py-lg"]),
    ...o,
    children: e
  }
);
In.displayName = "AlertDialog.Header";
const Nn = ({ className: e, ...t }) => /* @__PURE__ */ K(
  mn,
  {
    "data-spark-component": "alert-dialog-overlay",
    className: (n) => Te(
      "z-overlay fixed top-0 left-0 h-screen w-screen",
      "bg-overlay/dim-1",
      // Base UI automatically adds data-[starting-style] and data-[ending-style] attributes
      "data-[starting-style]:animate-fade-in",
      "data-[ending-style]:animate-fade-out",
      typeof e == "function" ? e(n) : e
    ),
    ...t
  }
);
Nn.displayName = "AlertDialog.Overlay";
const Mn = (e) => /* @__PURE__ */ K(bn, { "data-spark-component": "alert-dialog-portal", ...e });
Mn.displayName = "AlertDialog.Portal";
const Pn = ({ className: e, ...t }) => /* @__PURE__ */ K(
  vn,
  {
    "data-spark-component": "alert-dialog-title",
    className: Te("text-headline-1 text-on-surface", e),
    ...t
  }
);
Pn.displayName = "AlertDialog.Title";
const An = ({ asChild: e = !1, ...t }) => {
  const n = ft(e, "button");
  return /* @__PURE__ */ K(
    Sn,
    {
      "data-spark-component": "alert-dialog-trigger",
      render: n,
      ...t
    }
  );
};
An.displayName = "AlertDialog.Trigger";
const ee = Object.assign(Rn, {
  Action: Tn,
  Body: On,
  Cancel: wn,
  Content: xn,
  Description: Dn,
  Footer: kn,
  Header: In,
  Overlay: Nn,
  Portal: Mn,
  Title: Pn,
  Trigger: An
});
ee.displayName = "AlertDialog";
ee.Action.displayName = "AlertDialog.Action";
ee.Body.displayName = "AlertDialog.Body";
ee.Cancel.displayName = "AlertDialog.Cancel";
ee.Content.displayName = "AlertDialog.Content";
ee.Description.displayName = "AlertDialog.Description";
ee.Footer.displayName = "AlertDialog.Footer";
ee.Header.displayName = "AlertDialog.Header";
ee.Overlay.displayName = "AlertDialog.Overlay";
ee.Portal.displayName = "AlertDialog.Portal";
ee.Title.displayName = "AlertDialog.Title";
ee.Trigger.displayName = "AlertDialog.Trigger";
export {
  ee as AlertDialog,
  dt as useAlertDialog
};
//# sourceMappingURL=index.mjs.map
