"use client";
import * as g from "react";
import ge from "react";
import * as ht from "react-dom";
import { s as $t, k as Yt, a as ie, c as Xt, n as Te, m as Jt, i as Zt, b as Qt } from "./floating-ui.utils.dom-jr2suqy2.js";
import { a as mt } from "./useBaseUiId-C8Dq0BQq.js";
import { u as H } from "./useIsoLayoutEffect-DpJo20by.js";
import { u as D } from "./useStableCallback-CudqoENs.js";
import { c as en } from "./detectBrowser-Dn2N72k1.js";
import { a as tn } from "./visuallyHidden-PuyyGHVF.js";
import { jsx as U, jsxs as Je } from "react/jsx-runtime";
import { c as te, f as nn, e as rn, a as Ze, o as on } from "./createBaseUIEventDetails-CqidROtw.js";
import { E as sn, u as an, a as vt, f as un, i as cn, N as ln } from "./useRenderElement-DNB2vtF1.js";
import { o as q } from "./owner-rKN292Q9.js";
import { c as ne, a as fn, b as G, k as P, l as dn, F as pn, n as gt, S as bt } from "./element-DSo91iOi.js";
import { u as Qe, T as et } from "./useTimeout-DAqPwigF.js";
import { d as hn, c as mn } from "./event-BCa0Un_3.js";
import { T as tt } from "./useOpenChangeComplete-DkeH9FGJ.js";
const Wr = 500, Gr = 500, Ur = {
  style: {
    transition: "none"
  }
}, qr = "data-base-ui-click-trigger", $r = {
  fallbackAxisSide: "none"
}, Yr = {
  fallbackAxisSide: "end"
}, vn = {
  clipPath: "inset(50%)",
  position: "fixed",
  top: 0,
  left: 0
};
function fe(n, e, t = !0) {
  return n.filter((o) => o.parentId === e && (!t || o.context?.open)).flatMap((o) => [o, ...fe(n, o.id, t)]);
}
function Xr(n, e) {
  let t = [], r = n.find((o) => o.id === e)?.parentId;
  for (; r; ) {
    const o = n.find((s) => s.id === r);
    r = o?.parentId, o && (t = t.concat(o));
  }
  return t;
}
var gn = ["input:not([inert]):not([inert] *)", "select:not([inert]):not([inert] *)", "textarea:not([inert]):not([inert] *)", "a[href]:not([inert]):not([inert] *)", "button:not([inert]):not([inert] *)", "[tabindex]:not(slot):not([inert]):not([inert] *)", "audio[controls]:not([inert]):not([inert] *)", "video[controls]:not([inert]):not([inert] *)", '[contenteditable]:not([contenteditable="false"]):not([inert]):not([inert] *)', "details>summary:first-of-type:not([inert]):not([inert] *)", "details:not([inert]):not([inert] *)"], de = /* @__PURE__ */ gn.join(","), Et = typeof Element > "u", $ = Et ? function() {
} : Element.prototype.matches || Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector, pe = !Et && Element.prototype.getRootNode ? function(n) {
  var e;
  return n == null || (e = n.getRootNode) === null || e === void 0 ? void 0 : e.call(n);
} : function(n) {
  return n?.ownerDocument;
}, he = function(e, t) {
  var r;
  t === void 0 && (t = !0);
  var o = e == null || (r = e.getAttribute) === null || r === void 0 ? void 0 : r.call(e, "inert"), s = o === "" || o === "true", i = s || t && e && // closest does not exist on shadow roots, so we fall back to a manual
  // lookup upward, in case it is not defined.
  (typeof e.closest == "function" ? e.closest("[inert]") : he(e.parentNode));
  return i;
}, bn = function(e) {
  var t, r = e == null || (t = e.getAttribute) === null || t === void 0 ? void 0 : t.call(e, "contenteditable");
  return r === "" || r === "true";
}, yt = function(e, t, r) {
  if (he(e))
    return [];
  var o = Array.prototype.slice.apply(e.querySelectorAll(de));
  return t && $.call(e, de) && o.unshift(e), o = o.filter(r), o;
}, me = function(e, t, r) {
  for (var o = [], s = Array.from(e); s.length; ) {
    var i = s.shift();
    if (!he(i, !1))
      if (i.tagName === "SLOT") {
        var u = i.assignedElements(), h = u.length ? u : i.children, a = me(h, !0, r);
        r.flatten ? o.push.apply(o, a) : o.push({
          scopeParent: i,
          candidates: a
        });
      } else {
        var d = $.call(i, de);
        d && r.filter(i) && (t || !e.includes(i)) && o.push(i);
        var f = i.shadowRoot || // check for an undisclosed shadow
        typeof r.getShadowRoot == "function" && r.getShadowRoot(i), b = !he(f, !1) && (!r.shadowRootFilter || r.shadowRootFilter(i));
        if (f && b) {
          var l = me(f === !0 ? i.children : f.children, !0, r);
          r.flatten ? o.push.apply(o, l) : o.push({
            scopeParent: i,
            candidates: l
          });
        } else
          s.unshift.apply(s, i.children);
      }
  }
  return o;
}, St = function(e) {
  return !isNaN(parseInt(e.getAttribute("tabindex"), 10));
}, Ot = function(e) {
  if (!e)
    throw new Error("No node provided");
  return e.tabIndex < 0 && (/^(AUDIO|VIDEO|DETAILS)$/.test(e.tagName) || bn(e)) && !St(e) ? 0 : e.tabIndex;
}, En = function(e, t) {
  var r = Ot(e);
  return r < 0 && t && !St(e) ? 0 : r;
}, yn = function(e, t) {
  return e.tabIndex === t.tabIndex ? e.documentOrder - t.documentOrder : e.tabIndex - t.tabIndex;
}, Rt = function(e) {
  return e.tagName === "INPUT";
}, Sn = function(e) {
  return Rt(e) && e.type === "hidden";
}, On = function(e) {
  var t = e.tagName === "DETAILS" && Array.prototype.slice.apply(e.children).some(function(r) {
    return r.tagName === "SUMMARY";
  });
  return t;
}, Rn = function(e, t) {
  for (var r = 0; r < e.length; r++)
    if (e[r].checked && e[r].form === t)
      return e[r];
}, Tn = function(e) {
  if (!e.name)
    return !0;
  var t = e.form || pe(e), r = function(u) {
    return t.querySelectorAll('input[type="radio"][name="' + u + '"]');
  }, o;
  if (typeof window < "u" && typeof window.CSS < "u" && typeof window.CSS.escape == "function")
    o = r(window.CSS.escape(e.name));
  else
    try {
      o = r(e.name);
    } catch (i) {
      return console.error("Looks like you have a radio button with a name attribute containing invalid CSS selector characters and need the CSS.escape polyfill: %s", i.message), !1;
    }
  var s = Rn(o, e.form);
  return !s || s === e;
}, Cn = function(e) {
  return Rt(e) && e.type === "radio";
}, In = function(e) {
  return Cn(e) && !Tn(e);
}, _n = function(e) {
  var t, r = e && pe(e), o = (t = r) === null || t === void 0 ? void 0 : t.host, s = !1;
  if (r && r !== e) {
    var i, u, h;
    for (s = !!((i = o) !== null && i !== void 0 && (u = i.ownerDocument) !== null && u !== void 0 && u.contains(o) || e != null && (h = e.ownerDocument) !== null && h !== void 0 && h.contains(e)); !s && o; ) {
      var a, d, f;
      r = pe(o), o = (a = r) === null || a === void 0 ? void 0 : a.host, s = !!((d = o) !== null && d !== void 0 && (f = d.ownerDocument) !== null && f !== void 0 && f.contains(o));
    }
  }
  return s;
}, nt = function(e) {
  var t = e.getBoundingClientRect(), r = t.width, o = t.height;
  return r === 0 && o === 0;
}, wn = function(e, t) {
  var r = t.displayCheck, o = t.getShadowRoot;
  if (r === "full-native" && "checkVisibility" in e) {
    var s = e.checkVisibility({
      // Checking opacity might be desirable for some use cases, but natively,
      // opacity zero elements _are_ focusable and tabbable.
      checkOpacity: !1,
      opacityProperty: !1,
      contentVisibilityAuto: !0,
      visibilityProperty: !0,
      // This is an alias for `visibilityProperty`. Contemporary browsers
      // support both. However, this alias has wider browser support (Chrome
      // >= 105 and Firefox >= 106, vs. Chrome >= 121 and Firefox >= 122), so
      // we include it anyway.
      checkVisibilityCSS: !0
    });
    return !s;
  }
  if (getComputedStyle(e).visibility === "hidden")
    return !0;
  var i = $.call(e, "details>summary:first-of-type"), u = i ? e.parentElement : e;
  if ($.call(u, "details:not([open]) *"))
    return !0;
  if (!r || r === "full" || // full-native can run this branch when it falls through in case
  // Element#checkVisibility is unsupported
  r === "full-native" || r === "legacy-full") {
    if (typeof o == "function") {
      for (var h = e; e; ) {
        var a = e.parentElement, d = pe(e);
        if (a && !a.shadowRoot && o(a) === !0)
          return nt(e);
        e.assignedSlot ? e = e.assignedSlot : !a && d !== e.ownerDocument ? e = d.host : e = a;
      }
      e = h;
    }
    if (_n(e))
      return !e.getClientRects().length;
    if (r !== "legacy-full")
      return !0;
  } else if (r === "non-zero-area")
    return nt(e);
  return !1;
}, xn = function(e) {
  if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(e.tagName))
    for (var t = e.parentElement; t; ) {
      if (t.tagName === "FIELDSET" && t.disabled) {
        for (var r = 0; r < t.children.length; r++) {
          var o = t.children.item(r);
          if (o.tagName === "LEGEND")
            return $.call(t, "fieldset[disabled] *") ? !0 : !o.contains(e);
        }
        return !0;
      }
      t = t.parentElement;
    }
  return !1;
}, Ne = function(e, t) {
  return !(t.disabled || Sn(t) || wn(t, e) || // For a details element with a summary, the summary element gets the focus
  On(t) || xn(t));
}, Le = function(e, t) {
  return !(In(t) || Ot(t) < 0 || !Ne(e, t));
}, Nn = function(e) {
  var t = parseInt(e.getAttribute("tabindex"), 10);
  return !!(isNaN(t) || t >= 0);
}, Tt = function(e) {
  var t = [], r = [];
  return e.forEach(function(o, s) {
    var i = !!o.scopeParent, u = i ? o.scopeParent : o, h = En(u, i), a = i ? Tt(o.candidates) : u;
    h === 0 ? i ? t.push.apply(t, a) : t.push(u) : r.push({
      documentOrder: s,
      tabIndex: h,
      item: o,
      isScope: i,
      content: a
    });
  }), r.sort(yn).reduce(function(o, s) {
    return s.isScope ? o.push.apply(o, s.content) : o.push(s.content), o;
  }, []).concat(t);
}, Me = function(e, t) {
  t = t || {};
  var r;
  return t.getShadowRoot ? r = me([e], t.includeContainer, {
    filter: Le.bind(null, t),
    flatten: !1,
    getShadowRoot: t.getShadowRoot,
    shadowRootFilter: Nn
  }) : r = yt(e, t.includeContainer, Le.bind(null, t)), Tt(r);
}, Jr = function(e, t) {
  t = t || {};
  var r;
  return t.getShadowRoot ? r = me([e], t.includeContainer, {
    filter: Ne.bind(null, t),
    flatten: !0,
    getShadowRoot: t.getShadowRoot
  }) : r = yt(e, t.includeContainer, Ne.bind(null, t)), r;
}, Zr = function(e, t) {
  if (t = t || {}, !e)
    throw new Error("No node provided");
  return $.call(e, de) === !1 ? !1 : Le(t, e);
};
const Ve = () => ({
  getShadowRoot: !0,
  displayCheck: (
    // JSDOM does not support the `tabbable` library. To solve this we can
    // check if `ResizeObserver` is a real function (not polyfilled), which
    // determines if the current environment is JSDOM-like.
    typeof ResizeObserver == "function" && ResizeObserver.toString().includes("[native code]") ? "full" : "none"
  )
});
function Ct(n, e) {
  const t = Me(n, Ve()), r = t.length;
  if (r === 0)
    return;
  const o = fn(q(n)), s = t.indexOf(o), i = s === -1 ? e === 1 ? 0 : r - 1 : s + e;
  return t[i];
}
function Ln(n) {
  return Ct(q(n).body, 1) || n;
}
function kn(n) {
  return Ct(q(n).body, -1) || n;
}
function It(n, e) {
  if (!n)
    return null;
  const t = Me(q(n).body, Ve()), r = t.length;
  if (r === 0)
    return null;
  const o = t.indexOf(n);
  if (o === -1)
    return null;
  const s = (o + e + r) % r;
  return t[s];
}
function Qr(n) {
  return It(n, 1);
}
function eo(n) {
  return It(n, -1);
}
function Ce(n, e) {
  const t = e || n.currentTarget, r = n.relatedTarget;
  return !r || !ne(t, r);
}
function Pn(n) {
  Me(n, Ve()).forEach((t) => {
    t.dataset.tabindex = t.getAttribute("tabindex") || "", t.setAttribute("tabindex", "-1");
  });
}
function rt(n) {
  n.querySelectorAll("[data-tabindex]").forEach((t) => {
    const r = t.dataset.tabindex;
    delete t.dataset.tabindex, r ? t.setAttribute("tabindex", r) : t.removeAttribute("tabindex");
  });
}
const ke = /* @__PURE__ */ g.forwardRef(function(e, t) {
  const [r, o] = g.useState();
  return H(() => {
    en && o("button");
  }, []), /* @__PURE__ */ U("span", {
    ...e,
    ref: t,
    style: tn,
    "aria-hidden": r ? void 0 : !0,
    ...{
      tabIndex: 0,
      // Role is only for VoiceOver
      role: r
    },
    "data-base-ui-focus-guard": ""
  });
});
process.env.NODE_ENV !== "production" && (ke.displayName = "FocusGuard");
function _t(n) {
  return `data-base-ui-${n}`;
}
const Fe = /* @__PURE__ */ g.createContext(null);
process.env.NODE_ENV !== "production" && (Fe.displayName = "PortalContext");
const An = () => g.useContext(Fe), Dn = _t("portal");
function Mn(n = {}) {
  const {
    ref: e,
    container: t,
    componentProps: r = sn,
    elementProps: o
  } = n, s = mt(), u = An()?.portalNode, [h, a] = g.useState(null), [d, f] = g.useState(null), b = D((E) => {
    E !== null && f(E);
  }), l = g.useRef(null);
  H(() => {
    if (t === null) {
      l.current && (l.current = null, f(null), a(null));
      return;
    }
    if (s == null)
      return;
    const E = (t && ($t(t) ? t : t.current)) ?? u ?? document.body;
    if (E == null) {
      l.current && (l.current = null, f(null), a(null));
      return;
    }
    l.current !== E && (l.current = E, f(null), a(E));
  }, [t, u, s]);
  const p = an("div", r, {
    ref: [e, b],
    props: [{
      id: s,
      [Dn]: ""
    }, o]
  });
  return {
    portalNode: d,
    portalSubtree: h && p ? /* @__PURE__ */ ht.createPortal(p, h) : null
  };
}
const Vn = /* @__PURE__ */ g.forwardRef(function(e, t) {
  const {
    children: r,
    container: o,
    className: s,
    render: i,
    renderGuards: u,
    ...h
  } = e, {
    portalNode: a,
    portalSubtree: d
  } = Mn({
    container: o,
    ref: t,
    componentProps: e,
    elementProps: h
  }), f = g.useRef(null), b = g.useRef(null), l = g.useRef(null), p = g.useRef(null), [m, E] = g.useState(null), T = m?.modal, N = m?.open, w = typeof u == "boolean" ? u : !!m && !m.modal && m.open && !!a;
  g.useEffect(() => {
    if (!a || T)
      return;
    function S(y) {
      a && y.relatedTarget && Ce(y) && (y.type === "focusin" ? rt : Pn)(a);
    }
    return a.addEventListener("focusin", S, !0), a.addEventListener("focusout", S, !0), () => {
      a.removeEventListener("focusin", S, !0), a.removeEventListener("focusout", S, !0);
    };
  }, [a, T]), g.useEffect(() => {
    !a || N || rt(a);
  }, [N, a]);
  const x = g.useMemo(() => ({
    beforeOutsideRef: f,
    afterOutsideRef: b,
    beforeInsideRef: l,
    afterInsideRef: p,
    portalNode: a,
    setFocusManagerState: E
  }), [a]);
  return /* @__PURE__ */ Je(g.Fragment, {
    children: [d, /* @__PURE__ */ Je(Fe.Provider, {
      value: x,
      children: [w && a && /* @__PURE__ */ U(ke, {
        "data-type": "outside",
        ref: f,
        onFocus: (S) => {
          if (Ce(S, a))
            l.current?.focus();
          else {
            const y = m ? m.domReference : null;
            kn(y)?.focus();
          }
        }
      }), w && a && /* @__PURE__ */ U("span", {
        "aria-owns": a.id,
        style: vn
      }), a && /* @__PURE__ */ ht.createPortal(r, a), w && a && /* @__PURE__ */ U(ke, {
        "data-type": "outside",
        ref: b,
        onFocus: (S) => {
          if (Ce(S, a))
            p.current?.focus();
          else {
            const y = m ? m.domReference : null;
            Ln(y)?.focus(), m?.closeOnFocusOut && m?.onOpenChange(!1, te(nn, S.nativeEvent));
          }
        }
      })]
    })]
  });
});
process.env.NODE_ENV !== "production" && (Vn.displayName = "FloatingPortal");
function wt() {
  const n = /* @__PURE__ */ new Map();
  return {
    emit(e, t) {
      n.get(e)?.forEach((r) => r(t));
    },
    on(e, t) {
      n.has(e) || n.set(e, /* @__PURE__ */ new Set()), n.get(e).add(t);
    },
    off(e, t) {
      n.get(e)?.delete(t);
    }
  };
}
class Fn {
  nodesRef = {
    current: []
  };
  events = wt();
  addNode(e) {
    this.nodesRef.current.push(e);
  }
  removeNode(e) {
    const t = this.nodesRef.current.findIndex((r) => r === e);
    t !== -1 && this.nodesRef.current.splice(t, 1);
  }
}
const je = /* @__PURE__ */ g.createContext(null);
process.env.NODE_ENV !== "production" && (je.displayName = "FloatingNodeContext");
const Ke = /* @__PURE__ */ g.createContext(null);
process.env.NODE_ENV !== "production" && (Ke.displayName = "FloatingTreeContext");
const xt = () => g.useContext(je)?.id || null, Nt = (n) => {
  const e = g.useContext(Ke);
  return n ?? e;
};
function to(n) {
  const e = mt(), t = Nt(n), r = xt();
  return H(() => {
    if (!e)
      return;
    const o = {
      id: e,
      parentId: r
    };
    return t?.addNode(o), () => {
      t?.removeNode(o);
    };
  }, [t, e, r]), e;
}
function no(n) {
  const {
    children: e,
    id: t
  } = n, r = xt();
  return /* @__PURE__ */ U(je.Provider, {
    value: g.useMemo(() => ({
      id: t,
      parentId: r
    }), [t, r]),
    children: e
  });
}
function ro(n) {
  const {
    children: e,
    externalTree: t
  } = n, r = vt(() => t ?? new Fn()).current;
  return /* @__PURE__ */ U(Ke.Provider, {
    value: r,
    children: e
  });
}
const jn = {
  intentional: "onClick",
  sloppy: "onPointerDown"
};
function Kn() {
  return !1;
}
function Hn(n) {
  return {
    escapeKey: typeof n == "boolean" ? n : n?.escapeKey ?? !1,
    outsidePress: typeof n == "boolean" ? n : n?.outsidePress ?? !0
  };
}
function oo(n, e = {}) {
  const t = "rootStore" in n ? n.rootStore : n, r = t.useState("open"), o = t.useState("floatingElement"), {
    dataRef: s
  } = t.context, {
    enabled: i = !0,
    escapeKey: u = !0,
    outsidePress: h = !0,
    outsidePressEvent: a = "sloppy",
    referencePress: d = Kn,
    referencePressEvent: f = "sloppy",
    bubbles: b,
    externalTree: l
  } = e, p = Nt(l), m = D(typeof h == "function" ? h : () => !1), E = typeof h == "function" ? m : h, T = E !== !1, N = D(() => a), w = g.useRef(!1), x = g.useRef(!1), S = g.useRef(!1), {
    escapeKey: y,
    outsidePress: C
  } = Hn(b), O = g.useRef(null), M = Qe(), re = Qe(), V = D(() => {
    re.clear(), s.current.insideReactTree = !1;
  }), be = g.useRef(!1), Ee = g.useRef(""), ye = D(d), j = D((I) => {
    if (!r || !i || !u || I.key !== "Escape" || be.current)
      return;
    const F = s.current.floatingContext?.nodeId, Y = p ? fe(p.nodesRef.current, F) : [];
    if (!y && Y.length > 0) {
      let J = !0;
      if (Y.forEach((A) => {
        A.context?.open && !A.context.dataRef.current.__escapeKeyBubbles && (J = !1);
      }), !J)
        return;
    }
    const oe = hn(I) ? I.nativeEvent : I, X = te(rn, oe);
    t.setOpen(!1, X), !y && !X.isPropagationAllowed && I.stopPropagation();
  }), K = D(() => {
    s.current.insideReactTree = !0, re.start(0, V);
  });
  g.useEffect(() => {
    if (!r || !i)
      return;
    s.current.__escapeKeyBubbles = y, s.current.__outsidePressBubbles = C;
    const I = new et(), F = new et();
    function Y() {
      I.clear(), be.current = !0;
    }
    function oe() {
      I.start(
        // 0ms or 1ms don't work in Safari. 5ms appears to consistently work.
        // Only apply to WebKit for the test to remain 0ms.
        Yt() ? 5 : 0,
        () => {
          be.current = !1;
        }
      );
    }
    function X() {
      S.current = !0, F.start(0, () => {
        S.current = !1;
      });
    }
    function J() {
      w.current = !1, x.current = !1;
    }
    function A() {
      const c = Ee.current, v = c === "pen" || !c ? "mouse" : c, _ = N(), L = typeof _ == "function" ? _() : _;
      return typeof L == "string" ? L : L[v];
    }
    function Dt(c) {
      const v = A();
      return v === "intentional" && c.type !== "click" || v === "sloppy" && c.type === "click";
    }
    function We(c) {
      const v = s.current.floatingContext?.nodeId, _ = p && fe(p.nodesRef.current, v).some((L) => P(c, L.context?.elements.floating));
      return P(c, t.select("floatingElement")) || P(c, t.select("domReferenceElement")) || _;
    }
    function se(c) {
      if (Dt(c)) {
        V();
        return;
      }
      if (s.current.insideReactTree) {
        V();
        return;
      }
      const v = G(c), _ = `[${_t("inert")}]`;
      let L = Array.from(q(t.select("floatingElement")).querySelectorAll(_));
      const Z = ie(v) ? v.getRootNode() : null;
      Xt(Z) && (L = L.concat(Array.from(Z.querySelectorAll(_))));
      const $e = t.context.triggerElements;
      if (v && ($e.hasElement(v) || $e.hasMatchingElement((k) => ne(k, v))))
        return;
      let Q = ie(v) ? v : null;
      for (; Q && !Te(Q); ) {
        const k = Jt(Q);
        if (Te(k) || !ie(k))
          break;
        Q = k;
      }
      if (L.length && ie(v) && !dn(v) && // Clicked on a direct ancestor (e.g. FloatingOverlay).
      !ne(v, t.select("floatingElement")) && // If the target root element contains none of the markers, then the
      // element was injected after the floating element rendered.
      L.every((k) => !ne(Q, k)))
        return;
      if (Zt(v) && !("touches" in c)) {
        const k = Te(v), W = Qt(v), Xe = /auto|scroll/, Ht = k || Xe.test(W.overflowX), zt = k || Xe.test(W.overflowY), Bt = Ht && v.clientWidth > 0 && v.scrollWidth > v.clientWidth, Wt = zt && v.clientHeight > 0 && v.scrollHeight > v.clientHeight, Gt = W.direction === "rtl", Ut = Wt && (Gt ? c.offsetX <= v.offsetWidth - v.clientWidth : c.offsetX > v.clientWidth), qt = Bt && c.offsetY > v.clientHeight;
        if (Ut || qt)
          return;
      }
      if (We(c))
        return;
      if (A() === "intentional" && S.current) {
        F.clear(), S.current = !1;
        return;
      }
      if (typeof E == "function" && !E(c))
        return;
      const Kt = s.current.floatingContext?.nodeId, Ye = p ? fe(p.nodesRef.current, Kt) : [];
      if (Ye.length > 0) {
        let k = !0;
        if (Ye.forEach((W) => {
          W.context?.open && !W.context.dataRef.current.__outsidePressBubbles && (k = !1);
        }), !k)
          return;
      }
      t.setOpen(!1, te(on, c)), V();
    }
    function Mt(c) {
      A() !== "sloppy" || c.pointerType === "touch" || !t.select("open") || !i || P(c, t.select("floatingElement")) || P(c, t.select("domReferenceElement")) || se(c);
    }
    function Vt(c) {
      if (A() !== "sloppy" || !t.select("open") || !i || P(c, t.select("floatingElement")) || P(c, t.select("domReferenceElement")))
        return;
      const v = c.touches[0];
      v && (O.current = {
        startTime: Date.now(),
        startX: v.clientX,
        startY: v.clientY,
        dismissOnTouchEnd: !1,
        dismissOnMouseDown: !0
      }, M.start(1e3, () => {
        O.current && (O.current.dismissOnTouchEnd = !1, O.current.dismissOnMouseDown = !1);
      }));
    }
    function Ge(c) {
      Ee.current = "touch";
      const v = G(c);
      function _() {
        Vt(c), v?.removeEventListener(c.type, _);
      }
      v?.addEventListener(c.type, _);
    }
    function z(c) {
      if (M.clear(), c.type === "pointerdown" && (Ee.current = c.pointerType), c.type === "mousedown" && O.current && !O.current.dismissOnMouseDown)
        return;
      const v = G(c);
      function _() {
        c.type === "pointerdown" ? Mt(c) : se(c), v?.removeEventListener(c.type, _);
      }
      v?.addEventListener(c.type, _);
    }
    function B(c) {
      if (!w.current)
        return;
      const v = x.current;
      if (J(), A() === "intentional") {
        if (c.type === "pointercancel") {
          v && X();
          return;
        }
        if (!We(c)) {
          if (v) {
            X();
            return;
          }
          typeof E == "function" && !E(c) || (F.clear(), S.current = !0, V());
        }
      }
    }
    function Ft(c) {
      if (A() !== "sloppy" || !O.current || P(c, t.select("floatingElement")) || P(c, t.select("domReferenceElement")))
        return;
      const v = c.touches[0];
      if (!v)
        return;
      const _ = Math.abs(v.clientX - O.current.startX), L = Math.abs(v.clientY - O.current.startY), Z = Math.sqrt(_ * _ + L * L);
      Z > 5 && (O.current.dismissOnTouchEnd = !0), Z > 10 && (se(c), M.clear(), O.current = null);
    }
    function Ue(c) {
      const v = G(c);
      function _() {
        Ft(c), v?.removeEventListener(c.type, _);
      }
      v?.addEventListener(c.type, _);
    }
    function jt(c) {
      A() !== "sloppy" || !O.current || P(c, t.select("floatingElement")) || P(c, t.select("domReferenceElement")) || (O.current.dismissOnTouchEnd && se(c), M.clear(), O.current = null);
    }
    function qe(c) {
      const v = G(c);
      function _() {
        jt(c), v?.removeEventListener(c.type, _);
      }
      v?.addEventListener(c.type, _);
    }
    const R = q(o);
    return u && (R.addEventListener("keydown", j), R.addEventListener("compositionstart", Y), R.addEventListener("compositionend", oe)), T && (R.addEventListener("click", z, !0), R.addEventListener("pointerdown", z, !0), R.addEventListener("pointerup", B, !0), R.addEventListener("pointercancel", B, !0), R.addEventListener("mousedown", z, !0), R.addEventListener("mouseup", B, !0), R.addEventListener("touchstart", Ge, !0), R.addEventListener("touchmove", Ue, !0), R.addEventListener("touchend", qe, !0)), () => {
      u && (R.removeEventListener("keydown", j), R.removeEventListener("compositionstart", Y), R.removeEventListener("compositionend", oe)), T && (R.removeEventListener("click", z, !0), R.removeEventListener("pointerdown", z, !0), R.removeEventListener("pointerup", B, !0), R.removeEventListener("pointercancel", B, !0), R.removeEventListener("mousedown", z, !0), R.removeEventListener("mouseup", B, !0), R.removeEventListener("touchstart", Ge, !0), R.removeEventListener("touchmove", Ue, !0), R.removeEventListener("touchend", qe, !0)), I.clear(), F.clear(), J(), S.current = !1;
    };
  }, [s, o, u, T, E, r, i, y, C, j, V, N, p, t, M]), g.useEffect(V, [E, V]);
  const Se = g.useMemo(() => ({
    onKeyDown: j,
    [jn[f]]: (I) => {
      ye() && t.setOpen(!1, te(Ze, I.nativeEvent));
    },
    ...f !== "intentional" && {
      onClick(I) {
        ye() && t.setOpen(!1, te(Ze, I.nativeEvent));
      }
    }
  }), [j, t, f, ye]), Oe = D((I) => {
    if (!r || !i || I.button !== 0)
      return;
    const F = G(I.nativeEvent);
    ne(t.select("floatingElement"), F) && (w.current || (w.current = !0, x.current = !1));
  }), Re = D((I) => {
    !r || !i || (I.defaultPrevented || I.nativeEvent.defaultPrevented) && w.current && (x.current = !0);
  }), Be = g.useMemo(() => ({
    onKeyDown: j,
    // `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: Re,
    onMouseDown: Re,
    onClickCapture: K,
    onMouseDownCapture(I) {
      K(), Oe(I);
    },
    onPointerDownCapture(I) {
      K(), Oe(I);
    },
    onMouseUpCapture: K,
    onTouchEndCapture: K,
    onTouchMoveCapture: K
  }), [j, K, Oe, Re]);
  return g.useMemo(() => i ? {
    reference: Se,
    floating: Be,
    trigger: Se
  } : {}, [i, Se, Be]);
}
var zn = (n, e, t) => {
  if (e.length === 1 && e[0] === t) {
    let r = !1;
    try {
      const o = {};
      n(o) === o && (r = !0);
    } catch {
    }
    if (r) {
      let o;
      try {
        throw new Error();
      } catch (s) {
        ({ stack: o } = 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: o }
      );
    }
  }
}, Bn = (n, e, t) => {
  const { memoize: r, memoizeOptions: o } = e, { inputSelectorResults: s, inputSelectorResultsCopy: i } = n, u = r(() => ({}), ...o);
  if (!(u.apply(null, s) === u.apply(null, i))) {
    let a;
    try {
      throw new Error();
    } catch (d) {
      ({ stack: a } = d);
    }
    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: t,
        firstInputs: s,
        secondInputs: i,
        stack: a
      }
    );
  }
}, Wn = {
  inputStabilityCheck: "once",
  identityFunctionCheck: "once"
}, ve = /* @__PURE__ */ Symbol("NOT_FOUND");
function Gn(n, e = `expected a function, instead received ${typeof n}`) {
  if (typeof n != "function")
    throw new TypeError(e);
}
function Un(n, e = `expected an object, instead received ${typeof n}`) {
  if (typeof n != "object")
    throw new TypeError(e);
}
function qn(n, e = "expected all items to be functions, instead received the following types: ") {
  if (!n.every((t) => typeof t == "function")) {
    const t = n.map(
      (r) => typeof r == "function" ? `function ${r.name || "unnamed"}()` : typeof r
    ).join(", ");
    throw new TypeError(`${e}[${t}]`);
  }
}
var ot = (n) => Array.isArray(n) ? n : [n];
function $n(n) {
  const e = Array.isArray(n[0]) ? n[0] : n;
  return qn(
    e,
    "createSelector expects all input-selectors to be functions, but received the following types: "
  ), e;
}
function st(n, e) {
  const t = [], { length: r } = n;
  for (let o = 0; o < r; o++)
    t.push(n[o].apply(null, e));
  return t;
}
var Yn = (n, e) => {
  const { identityFunctionCheck: t, inputStabilityCheck: r } = {
    ...Wn,
    ...e
  };
  return {
    identityFunctionCheck: {
      shouldRun: t === "always" || t === "once" && n,
      run: zn
    },
    inputStabilityCheck: {
      shouldRun: r === "always" || r === "once" && n,
      run: Bn
    }
  };
};
function Xn(n) {
  let e;
  return {
    get(t) {
      return e && n(e.key, t) ? e.value : ve;
    },
    put(t, r) {
      e = { key: t, value: r };
    },
    getEntries() {
      return e ? [e] : [];
    },
    clear() {
      e = void 0;
    }
  };
}
function Jn(n, e) {
  let t = [];
  function r(u) {
    const h = t.findIndex((a) => e(u, a.key));
    if (h > -1) {
      const a = t[h];
      return h > 0 && (t.splice(h, 1), t.unshift(a)), a.value;
    }
    return ve;
  }
  function o(u, h) {
    r(u) === ve && (t.unshift({ key: u, value: h }), t.length > n && t.pop());
  }
  function s() {
    return t;
  }
  function i() {
    t = [];
  }
  return { get: r, put: o, getEntries: s, clear: i };
}
var Zn = (n, e) => n === e;
function Qn(n) {
  return function(t, r) {
    if (t === null || r === null || t.length !== r.length)
      return !1;
    const { length: o } = t;
    for (let s = 0; s < o; s++)
      if (!n(t[s], r[s]))
        return !1;
    return !0;
  };
}
function er(n, e) {
  const t = typeof e == "object" ? e : { equalityCheck: e }, {
    equalityCheck: r = Zn,
    maxSize: o = 1,
    resultEqualityCheck: s
  } = t, i = Qn(r);
  let u = 0;
  const h = o <= 1 ? Xn(i) : Jn(o, i);
  function a() {
    let d = h.get(arguments);
    if (d === ve) {
      if (d = n.apply(null, arguments), u++, s) {
        const b = h.getEntries().find(
          (l) => s(l.value, d)
        );
        b && (d = b.value, u !== 0 && u--);
      }
      h.put(arguments, d);
    }
    return d;
  }
  return a.clearCache = () => {
    h.clear(), a.resetResultsCount();
  }, a.resultsCount = () => u, a.resetResultsCount = () => {
    u = 0;
  }, a;
}
var tr = class {
  constructor(n) {
    this.value = n;
  }
  deref() {
    return this.value;
  }
}, nr = typeof WeakRef < "u" ? WeakRef : tr, rr = 0, it = 1;
function ae() {
  return {
    s: rr,
    v: void 0,
    o: null,
    p: null
  };
}
function Lt(n, e = {}) {
  let t = ae();
  const { resultEqualityCheck: r } = e;
  let o, s = 0;
  function i() {
    let u = t;
    const { length: h } = arguments;
    for (let f = 0, b = h; f < b; f++) {
      const l = arguments[f];
      if (typeof l == "function" || typeof l == "object" && l !== null) {
        let p = u.o;
        p === null && (u.o = p = /* @__PURE__ */ new WeakMap());
        const m = p.get(l);
        m === void 0 ? (u = ae(), p.set(l, u)) : u = m;
      } else {
        let p = u.p;
        p === null && (u.p = p = /* @__PURE__ */ new Map());
        const m = p.get(l);
        m === void 0 ? (u = ae(), p.set(l, u)) : u = m;
      }
    }
    const a = u;
    let d;
    if (u.s === it)
      d = u.v;
    else if (d = n.apply(null, arguments), s++, r) {
      const f = o?.deref?.() ?? o;
      f != null && r(f, d) && (d = f, s !== 0 && s--), o = typeof d == "object" && d !== null || typeof d == "function" ? new nr(d) : d;
    }
    return a.s = it, a.v = d, d;
  }
  return i.clearCache = () => {
    t = ae(), i.resetResultsCount();
  }, i.resultsCount = () => s, i.resetResultsCount = () => {
    s = 0;
  }, i;
}
function kt(n, ...e) {
  const t = typeof n == "function" ? {
    memoize: n,
    memoizeOptions: e
  } : n, r = (...o) => {
    let s = 0, i = 0, u, h = {}, a = o.pop();
    typeof a == "object" && (h = a, a = o.pop()), Gn(
      a,
      `createSelector expects an output function after the inputs, but received: [${typeof a}]`
    );
    const d = {
      ...t,
      ...h
    }, {
      memoize: f,
      memoizeOptions: b = [],
      argsMemoize: l = Lt,
      argsMemoizeOptions: p = [],
      devModeChecks: m = {}
    } = d, E = ot(b), T = ot(p), N = $n(o), w = f(function() {
      return s++, a.apply(
        null,
        arguments
      );
    }, ...E);
    let x = !0;
    const S = l(function() {
      i++;
      const C = st(
        N,
        arguments
      );
      if (u = w.apply(null, C), process.env.NODE_ENV !== "production") {
        const { identityFunctionCheck: O, inputStabilityCheck: M } = Yn(x, m);
        if (O.shouldRun && O.run(
          a,
          C,
          u
        ), M.shouldRun) {
          const re = st(
            N,
            arguments
          );
          M.run(
            { inputSelectorResults: C, inputSelectorResultsCopy: re },
            { memoize: f, memoizeOptions: E },
            arguments
          );
        }
        x && (x = !1);
      }
      return u;
    }, ...T);
    return Object.assign(S, {
      resultFunc: a,
      memoizedResultFunc: w,
      dependencies: N,
      dependencyRecomputations: () => i,
      resetDependencyRecomputations: () => {
        i = 0;
      },
      lastResult: () => u,
      recomputations: () => s,
      resetRecomputations: () => {
        s = 0;
      },
      memoize: f,
      argsMemoize: l
    });
  };
  return Object.assign(r, {
    withTypes: () => r
  }), r;
}
var or = /* @__PURE__ */ kt(Lt), sr = Object.assign(
  (n, e = or) => {
    Un(
      n,
      `createStructuredSelector expects first argument to be an object where each property is a selector, instead received a ${typeof n}`
    );
    const t = Object.keys(n), r = t.map(
      (s) => n[s]
    );
    return e(
      r,
      (...s) => s.reduce((i, u, h) => (i[t[h]] = u, i), {})
    );
  },
  { withTypes: () => sr }
);
kt({
  memoize: er,
  memoizeOptions: {
    maxSize: 1,
    equalityCheck: Object.is
  }
});
const ee = (n, e, t, r, o, s, ...i) => {
  if (i.length > 0)
    throw new Error(process.env.NODE_ENV !== "production" ? "Unsupported number of selectors" : un(1));
  let u;
  if (n)
    u = n;
  else
    throw (
      /* minify-error-disabled */
      new Error("Missing arguments")
    );
  return u;
};
var ue = { exports: {} }, Ie = {};
var at;
function ir() {
  if (at) return Ie;
  at = 1;
  var n = ge;
  function e(f, b) {
    return f === b && (f !== 0 || 1 / f === 1 / b) || f !== f && b !== b;
  }
  var t = typeof Object.is == "function" ? Object.is : e, r = n.useState, o = n.useEffect, s = n.useLayoutEffect, i = n.useDebugValue;
  function u(f, b) {
    var l = b(), p = r({ inst: { value: l, getSnapshot: b } }), m = p[0].inst, E = p[1];
    return s(
      function() {
        m.value = l, m.getSnapshot = b, h(m) && E({ inst: m });
      },
      [f, l, b]
    ), o(
      function() {
        return h(m) && E({ inst: m }), f(function() {
          h(m) && E({ inst: m });
        });
      },
      [f]
    ), i(l), l;
  }
  function h(f) {
    var b = f.getSnapshot;
    f = f.value;
    try {
      var l = b();
      return !t(f, l);
    } catch {
      return !0;
    }
  }
  function a(f, b) {
    return b();
  }
  var d = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? a : u;
  return Ie.useSyncExternalStore = n.useSyncExternalStore !== void 0 ? n.useSyncExternalStore : d, Ie;
}
var _e = {};
var ut;
function ar() {
  return ut || (ut = 1, process.env.NODE_ENV !== "production" && (function() {
    function n(l, p) {
      return l === p && (l !== 0 || 1 / l === 1 / p) || l !== l && p !== p;
    }
    function e(l, p) {
      d || o.startTransition === void 0 || (d = !0, console.error(
        "You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."
      ));
      var m = p();
      if (!f) {
        var E = p();
        s(m, E) || (console.error(
          "The result of getSnapshot should be cached to avoid an infinite loop"
        ), f = !0);
      }
      E = i({
        inst: { value: m, getSnapshot: p }
      });
      var T = E[0].inst, N = E[1];
      return h(
        function() {
          T.value = m, T.getSnapshot = p, t(T) && N({ inst: T });
        },
        [l, m, p]
      ), u(
        function() {
          return t(T) && N({ inst: T }), l(function() {
            t(T) && N({ inst: T });
          });
        },
        [l]
      ), a(m), m;
    }
    function t(l) {
      var p = l.getSnapshot;
      l = l.value;
      try {
        var m = p();
        return !s(l, m);
      } catch {
        return !0;
      }
    }
    function r(l, p) {
      return p();
    }
    typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
    var o = ge, s = typeof Object.is == "function" ? Object.is : n, i = o.useState, u = o.useEffect, h = o.useLayoutEffect, a = o.useDebugValue, d = !1, f = !1, b = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? r : e;
    _e.useSyncExternalStore = o.useSyncExternalStore !== void 0 ? o.useSyncExternalStore : b, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
  })()), _e;
}
var ct;
function He() {
  return ct || (ct = 1, process.env.NODE_ENV === "production" ? ue.exports = ir() : ue.exports = ar()), ue.exports;
}
var Pt = He(), ce = { exports: {} }, we = {};
var lt;
function ur() {
  if (lt) return we;
  lt = 1;
  var n = ge, e = He();
  function t(a, d) {
    return a === d && (a !== 0 || 1 / a === 1 / d) || a !== a && d !== d;
  }
  var r = typeof Object.is == "function" ? Object.is : t, o = e.useSyncExternalStore, s = n.useRef, i = n.useEffect, u = n.useMemo, h = n.useDebugValue;
  return we.useSyncExternalStoreWithSelector = function(a, d, f, b, l) {
    var p = s(null);
    if (p.current === null) {
      var m = { hasValue: !1, value: null };
      p.current = m;
    } else m = p.current;
    p = u(
      function() {
        function T(y) {
          if (!N) {
            if (N = !0, w = y, y = b(y), l !== void 0 && m.hasValue) {
              var C = m.value;
              if (l(C, y))
                return x = C;
            }
            return x = y;
          }
          if (C = x, r(w, y)) return C;
          var O = b(y);
          return l !== void 0 && l(C, O) ? (w = y, C) : (w = y, x = O);
        }
        var N = !1, w, x, S = f === void 0 ? null : f;
        return [
          function() {
            return T(d());
          },
          S === null ? void 0 : function() {
            return T(S());
          }
        ];
      },
      [d, f, b, l]
    );
    var E = o(a, p[0], p[1]);
    return i(
      function() {
        m.hasValue = !0, m.value = E;
      },
      [E]
    ), h(E), E;
  }, we;
}
var xe = {};
var ft;
function cr() {
  return ft || (ft = 1, process.env.NODE_ENV !== "production" && (function() {
    function n(a, d) {
      return a === d && (a !== 0 || 1 / a === 1 / d) || a !== a && d !== d;
    }
    typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
    var e = ge, t = He(), r = typeof Object.is == "function" ? Object.is : n, o = t.useSyncExternalStore, s = e.useRef, i = e.useEffect, u = e.useMemo, h = e.useDebugValue;
    xe.useSyncExternalStoreWithSelector = function(a, d, f, b, l) {
      var p = s(null);
      if (p.current === null) {
        var m = { hasValue: !1, value: null };
        p.current = m;
      } else m = p.current;
      p = u(
        function() {
          function T(y) {
            if (!N) {
              if (N = !0, w = y, y = b(y), l !== void 0 && m.hasValue) {
                var C = m.value;
                if (l(C, y))
                  return x = C;
              }
              return x = y;
            }
            if (C = x, r(w, y))
              return C;
            var O = b(y);
            return l !== void 0 && l(C, O) ? (w = y, C) : (w = y, x = O);
          }
          var N = !1, w, x, S = f === void 0 ? null : f;
          return [
            function() {
              return T(d());
            },
            S === null ? void 0 : function() {
              return T(S());
            }
          ];
        },
        [d, f, b, l]
      );
      var E = o(a, p[0], p[1]);
      return i(
        function() {
          m.hasValue = !0, m.value = E;
        },
        [E]
      ), h(E), E;
    }, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
  })()), xe;
}
var dt;
function lr() {
  return dt || (dt = 1, process.env.NODE_ENV === "production" ? ce.exports = ur() : ce.exports = cr()), ce.exports;
}
var fr = lr();
const Pe = [];
let Ae;
function dr() {
  return Ae;
}
function pr(n) {
  Pe.push(n);
}
function hr(n) {
  const e = (t, r) => {
    const o = vt(mr).current;
    let s;
    try {
      Ae = o;
      for (const i of Pe)
        i.before(o);
      s = n(t, r);
      for (const i of Pe)
        i.after(o);
      o.didInitialize = !0;
    } finally {
      Ae = void 0;
    }
    return s;
  };
  return e.displayName = n.displayName || n.name, e;
}
function so(n) {
  return /* @__PURE__ */ g.forwardRef(hr(n));
}
function mr() {
  return {
    didInitialize: !1
  };
}
const vr = cn(19), gr = vr ? Er : yr;
function At(n, e, t, r, o) {
  return gr(n, e, t, r, o);
}
function br(n, e, t, r, o) {
  const s = g.useCallback(() => e(n.getSnapshot(), t, r, o), [n, e, t, r, o]);
  return Pt.useSyncExternalStore(n.subscribe, s, s);
}
pr({
  before(n) {
    n.syncIndex = 0, n.didInitialize || (n.syncTick = 1, n.syncHooks = [], n.didChangeStore = !0, n.getSnapshot = () => {
      let e = !1;
      for (let t = 0; t < n.syncHooks.length; t += 1) {
        const r = n.syncHooks[t], o = r.selector(r.store.state, r.a1, r.a2, r.a3);
        (r.didChange || !Object.is(r.value, o)) && (e = !0, r.value = o, r.didChange = !1);
      }
      return e && (n.syncTick += 1), n.syncTick;
    });
  },
  after(n) {
    n.syncHooks.length > 0 && (n.didChangeStore && (n.didChangeStore = !1, n.subscribe = (e) => {
      const t = /* @__PURE__ */ new Set();
      for (const o of n.syncHooks)
        t.add(o.store);
      const r = [];
      for (const o of t)
        r.push(o.subscribe(e));
      return () => {
        for (const o of r)
          o();
      };
    }), Pt.useSyncExternalStore(n.subscribe, n.getSnapshot, n.getSnapshot));
  }
});
function Er(n, e, t, r, o) {
  const s = dr();
  if (!s)
    return br(n, e, t, r, o);
  const i = s.syncIndex;
  s.syncIndex += 1;
  let u;
  return s.didInitialize ? (u = s.syncHooks[i], (u.store !== n || u.selector !== e || !Object.is(u.a1, t) || !Object.is(u.a2, r) || !Object.is(u.a3, o)) && (u.store !== n && (s.didChangeStore = !0), u.store = n, u.selector = e, u.a1 = t, u.a2 = r, u.a3 = o, u.didChange = !0)) : (u = {
    store: n,
    selector: e,
    a1: t,
    a2: r,
    a3: o,
    value: e(n.getSnapshot(), t, r, o),
    didChange: !1
  }, s.syncHooks.push(u)), u.value;
}
function yr(n, e, t, r, o) {
  return fr.useSyncExternalStoreWithSelector(n.subscribe, n.getSnapshot, n.getSnapshot, (s) => e(s, t, r, o));
}
class Sr {
  /**
   * 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(e) {
    this.state = e, 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 = (e) => (this.listeners.add(e), () => {
    this.listeners.delete(e);
  });
  /**
   * 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(e) {
    if (this.state === e)
      return;
    this.state = e, this.updateTick += 1;
    const t = this.updateTick;
    for (const r of this.listeners) {
      if (t !== this.updateTick)
        return;
      r(e);
    }
  }
  /**
   * 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(e) {
    for (const t in e)
      if (!Object.is(this.state[t], e[t])) {
        this.setState({
          ...this.state,
          ...e
        });
        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(e, t) {
    Object.is(this.state[e], t) || this.setState({
      ...this.state,
      [e]: t
    });
  }
  /**
   * Gives the state a new reference and updates all registered listeners.
   */
  notifyAll() {
    const e = {
      ...this.state
    };
    this.setState(e);
  }
  use(e, t, r, o) {
    return At(this, e, t, r, o);
  }
}
class Or extends Sr {
  /**
   * 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(e, t = {}, r) {
    super(e), this.context = t, this.selectors = r;
  }
  /**
   * Non-reactive values such as refs, callbacks, etc.
   */
  /**
   * 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(e, t) {
    g.useDebugValue(e), H(() => {
      this.state[e] !== t && this.set(e, t);
    }, [e, t]);
  }
  /**
   * 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(e, t) {
    const r = this;
    H(() => (r.state[e] !== t && r.set(e, t), () => {
      r.set(e, void 0);
    }), [r, e, t]);
  }
  /**
   * 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(e) {
    const t = this;
    if (process.env.NODE_ENV !== "production") {
      g.useDebugValue(e, (i) => Object.keys(i));
      const o = g.useRef(Object.keys(e)).current, s = Object.keys(e);
      (o.length !== s.length || o.some((i, u) => i !== s[u])) && console.error("ReactStore.useSyncedValues expects the same prop keys on every render. Keys should be stable.");
    }
    const r = Object.values(e);
    H(() => {
      t.update(e);
    }, [t, ...r]);
  }
  /**
   * Registers a controllable prop pair (`controlled`, `defaultValue`) for a specific key. If `controlled`
   * is non-undefined, the store's state at `key` is updated to match `controlled`.
   */
  useControlledProp(e, t) {
    g.useDebugValue(e);
    const r = t !== void 0;
    if (H(() => {
      r && !Object.is(this.state[e], t) && super.setState({
        ...this.state,
        [e]: t
      });
    }, [e, t, r]), process.env.NODE_ENV !== "production") {
      const o = this.controlledValues ??= /* @__PURE__ */ new Map();
      o.has(e) || o.set(e, r);
      const s = o.get(e);
      s !== void 0 && s !== r && console.error(`A component is changing the ${r ? "" : "un"}controlled state of ${e.toString()} to be ${r ? "un" : ""}controlled. Elements should not switch from uncontrolled to controlled (or vice versa).`);
    }
  }
  /** Gets the current value from the store using a selector with the provided key.
   *
   * @param key Key of the selector to use.
   */
  select(e, t, r, o) {
    const s = this.selectors[e];
    return s(this.state, t, r, o);
  }
  /**
   * 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(e, t, r, o) {
    return g.useDebugValue(e), At(this, this.selectors[e], t, r, o);
  }
  /**
   * 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(e, t) {
    g.useDebugValue(e);
    const r = D(t ?? ln);
    this.context[e] = r;
  }
  /**
   * 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(e) {
    const t = g.useRef(void 0);
    return t.current === void 0 && (t.current = (r) => {
      this.set(e, r);
    }), t.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(e, t) {
    let r;
    typeof e == "function" ? r = e : r = this.selectors[e];
    let o = r(this.state);
    return t(o, o, this), this.subscribe((s) => {
      const i = r(s);
      if (!Object.is(o, i)) {
        const u = o;
        o = i, t(i, u, this);
      }
    });
  }
}
const Rr = {
  open: ee((n) => n.open),
  domReferenceElement: ee((n) => n.domReferenceElement),
  referenceElement: ee((n) => n.positionReference ?? n.referenceElement),
  floatingElement: ee((n) => n.floatingElement),
  floatingId: ee((n) => n.floatingId)
};
class io extends Or {
  constructor(e) {
    const {
      nested: t,
      noEmit: r,
      onOpenChange: o,
      triggerElements: s,
      ...i
    } = e;
    super({
      ...i,
      positionReference: i.referenceElement,
      domReferenceElement: i.referenceElement
    }, {
      onOpenChange: o,
      dataRef: {
        current: {}
      },
      events: wt(),
      nested: t,
      noEmit: r,
      triggerElements: s
    }, Rr);
  }
  /**
   * 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 = (e, t) => {
    if ((!e || !this.state.open || // Prevent a pending hover-open from overwriting a click-open event, while allowing
    // click events to upgrade a hover-open.
    mn(t.event)) && (this.context.dataRef.current.openEvent = e ? t.event : void 0), !this.context.noEmit) {
      const r = {
        open: e,
        reason: t.reason,
        nativeEvent: t.event,
        nested: this.context.nested,
        triggerElement: t.trigger
      };
      this.context.events.emit("openchange", r);
    }
    this.context.onOpenChange?.(e, t);
  };
}
class ao {
  constructor() {
    this.elementsSet = /* @__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(e, t) {
    const r = this.idMap.get(e);
    if (r !== t && (r !== void 0 && this.elementsSet.delete(r), this.elementsSet.add(t), this.idMap.set(e, t), process.env.NODE_ENV !== "production" && this.elementsSet.size !== this.idMap.size))
      throw new Error("Base UI: A trigger element cannot be registered under multiple IDs in PopupTriggerMap.");
  }
  /**
   * Removes the trigger element with the given ID.
   */
  delete(e) {
    const t = this.idMap.get(e);
    t && (this.elementsSet.delete(t), this.idMap.delete(e));
  }
  /**
   * Whether the given element is registered as a trigger.
   */
  hasElement(e) {
    return this.elementsSet.has(e);
  }
  /**
   * Whether there is a registered trigger element matching the given predicate.
   */
  hasMatchingElement(e) {
    for (const t of this.elementsSet)
      if (e(t))
        return !0;
    return !1;
  }
  /**
   * Returns the trigger element associated with the given ID, or undefined if no such element exists.
   */
  getById(e) {
    return this.idMap.get(e);
  }
  /**
   * Returns an iterable of all registered trigger entries, where each entry is a tuple of [id, element].
   */
  entries() {
    return this.idMap.entries();
  }
  /**
   * Returns an iterable of all registered trigger elements.
   */
  elements() {
    return this.elementsSet.values();
  }
  /**
   * Returns the number of registered trigger elements.
   */
  get size() {
    return this.idMap.size;
  }
}
function uo(n = []) {
  const e = n.map((a) => a?.reference), t = n.map((a) => a?.floating), r = n.map((a) => a?.item), o = n.map((a) => a?.trigger), s = g.useCallback(
    (a) => le(a, n, "reference"),
    // eslint-disable-next-line react-hooks/exhaustive-deps
    e
  ), i = g.useCallback(
    (a) => le(a, n, "floating"),
    // eslint-disable-next-line react-hooks/exhaustive-deps
    t
  ), u = g.useCallback(
    (a) => le(a, n, "item"),
    // eslint-disable-next-line react-hooks/exhaustive-deps
    r
  ), h = g.useCallback(
    (a) => le(a, n, "trigger"),
    // eslint-disable-next-line react-hooks/exhaustive-deps
    o
  );
  return g.useMemo(() => ({
    getReferenceProps: s,
    getFloatingProps: i,
    getItemProps: u,
    getTriggerProps: h
  }), [s, i, u, h]);
}
function le(n, e, t) {
  const r = /* @__PURE__ */ new Map(), o = t === "item", s = {};
  t === "floating" && (s.tabIndex = -1, s[pn] = "");
  for (const i in n)
    o && n && (i === gt || i === bt) || (s[i] = n[i]);
  for (let i = 0; i < e.length; i += 1) {
    let u;
    const h = e[i]?.[t];
    typeof h == "function" ? u = n ? h(n) : null : u = h, u && pt(s, u, o, r);
  }
  return pt(s, n, o, r), s;
}
function pt(n, e, t, r) {
  for (const o in e) {
    const s = e[o];
    t && (o === gt || o === bt) || (o.startsWith("on") ? (r.has(o) || r.set(o, []), typeof s == "function" && (r.get(o)?.push(s), n[o] = (...i) => r.get(o)?.map((u) => u(...i)).find((u) => u !== void 0))) : n[o] = s);
  }
}
let ze = (function(n) {
  return n.open = "data-open", n.closed = "data-closed", n[n.startingStyle = tt.startingStyle] = "startingStyle", n[n.endingStyle = tt.endingStyle] = "endingStyle", n.anchorHidden = "data-anchor-hidden", n.side = "data-side", n.align = "data-align", n;
})({}), De = /* @__PURE__ */ (function(n) {
  return n.popupOpen = "data-popup-open", n.pressed = "data-pressed", n;
})({});
const Tr = {
  [De.popupOpen]: ""
}, Cr = {
  [De.popupOpen]: "",
  [De.pressed]: ""
}, Ir = {
  [ze.open]: ""
}, _r = {
  [ze.closed]: ""
}, wr = {
  [ze.anchorHidden]: ""
}, co = {
  open(n) {
    return n ? Tr : null;
  }
}, lo = {
  open(n) {
    return n ? Cr : null;
  }
}, fo = {
  open(n) {
    return n ? Ir : _r;
  },
  anchorHidden(n) {
    return n ? wr : null;
  }
};
export {
  Gr as A,
  lo as B,
  qr as C,
  Ur as D,
  eo as E,
  io as F,
  Qr as G,
  hr as H,
  De as I,
  so as J,
  At as K,
  $r as L,
  Fn as M,
  ao as P,
  Or as R,
  Sr as S,
  Wr as T,
  Mn as a,
  Nt as b,
  _t as c,
  ee as d,
  An as e,
  Ve as f,
  fe as g,
  Xr as h,
  ke as i,
  Ce as j,
  Ln as k,
  kn as l,
  Zr as m,
  Jr as n,
  ro as o,
  oo as p,
  uo as q,
  co as r,
  Yr as s,
  Me as t,
  xt as u,
  to as v,
  no as w,
  fo as x,
  ze as y,
  Vn as z
};
