import { o as Ve } from "./rolldown-runtime.js";
import { i as Ct, r as vt, t as xt } from "./vendor/react.js";
import { _ as Ke, b as Pt, f as se, h as _t, l as Nt, m as Ee, n as We, o as F, p as Q } from "./safeReact.js";
import { a as wt, i as Mt, r as kt, s as Ft, t as At, u as Be } from "./useRenderElement.js";
import { n as _, t as V } from "./useIsoLayoutEffect.js";
import { Et as Dt, Tt as Ht } from "./vendor/recharts.js";
import { i as ke } from "./useTransitionStatus.js";
import { n as Fe, t as Ae } from "./useTimeout.js";
import { n as Le } from "./useBaseUiId.js";
import { o as jt } from "./detectBrowser.js";
import { o as Vt } from "./constants.js";
import { n as G, r as be, t as Kt } from "./shadowDom.js";
import { i as Wt, n as C } from "./element.js";
import { r as Bt, t as Lt } from "./event.js";
import { c as Gt } from "./composite.js";
import { t as Y } from "./owner.js";
import { t as S } from "./addEventListener.js";
import { C as Yt, _ as Ut, s as Xt, t as J } from "./createBaseUIEventDetails.js";
import { t as qt } from "./visuallyHidden.js";
var c = /* @__PURE__ */ Ve(Ct()), Ge = /* @__PURE__ */ Ve(vt()), k = xt();
function ie(e, t, n = !0) {
  return e.filter((r) => r.parentId === t).flatMap((r) => [...!n || r.context?.open ? [r] : [], ...ie(e, r.id, n)]);
}
function er(e, t) {
  let n = [], r = e.find((s) => s.id === t)?.parentId;
  for (; r; ) {
    const s = e.find((o) => o.id === r);
    r = s?.parentId, s && (n = n.concat(s));
  }
  return n;
}
var $t = 'a[href],button,input,select,textarea,summary,details,iframe,object,embed,[tabindex],[contenteditable]:not([contenteditable="false"]),audio[controls],video[controls]';
function zt(e) {
  const t = e.assignedSlot;
  if (t) return t;
  if (e.parentElement) return e.parentElement;
  const n = e.getRootNode();
  return Ke(n) ? n.host : null;
}
function Re(e) {
  for (const t of Array.from(e.children)) if (F(t) === "summary") return t;
  return null;
}
function Jt(e, t) {
  const n = Re(t);
  return !!n && (e === n || G(n, e));
}
function Ye(e) {
  const t = e ? F(e) : "";
  return e != null && e.matches($t) && (t !== "summary" || e.parentElement != null && F(e.parentElement) === "details" && Re(e.parentElement) === e) && (t !== "details" || Re(e) == null) && (t !== "input" || e.type !== "hidden");
}
function Ue(e) {
  if (!Ye(e) || !e.isConnected || e.matches(":disabled")) return !1;
  for (let t = e; t; t = zt(t)) {
    const n = t !== e, r = F(t) === "slot";
    if (t.hasAttribute("inert") || n && F(t) === "details" && !t.open && !Jt(e, t) || t.hasAttribute("hidden") || !r && !Qt(t, n)) return !1;
  }
  return !0;
}
function Qt(e, t) {
  const n = We(e);
  return t ? n.display !== "none" : Gt(e, n);
}
function Xe(e) {
  const t = e.tabIndex;
  if (t < 0) {
    const n = F(e);
    if (n === "details" || n === "audio" || n === "video" || Q(e) && e.isContentEditable) return 0;
  }
  return t;
}
function Se(e) {
  if (F(e) !== "input") return null;
  const t = e;
  return t.type === "radio" && t.name !== "" ? t : null;
}
function Zt(e, t) {
  const n = Se(e);
  if (!n) return !0;
  const r = t.find((s) => {
    const o = Se(s);
    return o?.name === n.name && o.form === n.form && o.checked;
  });
  return r ? r === n : t.find((s) => {
    const o = Se(s);
    return o?.name === n.name && o.form === n.form;
  }) === n;
}
function qe(e) {
  if (Q(e) && F(e) === "slot") {
    const t = e.assignedElements({ flatten: !0 });
    if (t.length > 0) return t;
  }
  return Q(e) && e.shadowRoot ? Array.from(e.shadowRoot.children) : Array.from(e.children);
}
function $e(e, t) {
  qe(e).forEach((n) => {
    Ye(n) && t.push(n), $e(n, t);
  });
}
function ze(e, t, n) {
  qe(e).forEach((r) => {
    Q(r) && r.matches(t) && n.push(r), ze(r, t, n);
  });
}
function tr(e) {
  return Ue(e) && Xe(e) >= 0;
}
function en(e) {
  const t = [];
  return $e(e, t), t.filter(Ue);
}
function Ce(e) {
  const t = en(e);
  return t.filter((n) => Xe(n) >= 0 && Zt(n, t));
}
function Je(e, t) {
  const n = Ce(e), r = n.length;
  if (r === 0) return;
  const s = Kt(Y(e)), o = n.indexOf(s);
  return n[o === -1 ? t === 1 ? 0 : r - 1 : o + t];
}
function tn(e) {
  return Je(Y(e).body, 1) || e;
}
function nn(e) {
  return Je(Y(e).body, -1) || e;
}
function Qe(e, t) {
  if (!e) return null;
  const n = Ce(Y(e).body), r = n.length;
  if (r === 0) return null;
  const s = n.indexOf(e);
  return s === -1 ? null : n[(s + t + r) % r];
}
function nr(e) {
  return Qe(e, 1);
}
function rr(e) {
  return Qe(e, -1);
}
function ye(e, t) {
  const n = t || e.currentTarget, r = e.relatedTarget;
  return !r || !G(n, r);
}
function rn(e) {
  Ce(e).forEach((t) => {
    t.dataset.tabindex = t.getAttribute("tabindex") || "", t.setAttribute("tabindex", "-1");
  });
}
function De(e) {
  const t = [];
  ze(e, "[data-tabindex]", t), t.forEach((n) => {
    const r = n.dataset.tabindex;
    delete n.dataset.tabindex, r ? n.setAttribute("tabindex", r) : n.removeAttribute("tabindex");
  });
}
var Te = [], Ie = void 0;
function sn() {
  return Ie;
}
function on(e) {
  Te.push(e);
}
function an(e) {
  const t = (n, r) => {
    const s = Be(un).current;
    let o;
    try {
      Ie = s;
      for (const d of Te) d.before(s);
      o = e(n, r);
      for (const d of Te) d.after(s);
      s.didInitialize = !0;
    } finally {
      Ie = void 0;
    }
    return o;
  };
  return t.displayName = e.displayName || e.name, t;
}
function sr(e) {
  return /* @__PURE__ */ c.forwardRef(an(e));
}
function un() {
  return { didInitialize: !1 };
}
function or(e) {
  const t = c.useRef(!0);
  t.current && (t.current = !1, e());
}
function ae(...e) {
  return () => {
    for (let t = 0; t < e.length; t += 1) {
      const n = e[t];
      n && n();
    }
  };
}
var He = /* @__PURE__ */ c.forwardRef(function(t, n) {
  const [r, s] = c.useState();
  V(() => {
    jt && s("button");
  }, []);
  const o = {
    tabIndex: 0,
    role: r
  };
  return /* @__PURE__ */ (0, k.jsx)("span", {
    ...t,
    ref: n,
    style: qt,
    "aria-hidden": r ? void 0 : !0,
    ...o,
    "data-base-ui-focus-guard": ""
  });
});
function Ze(e) {
  return `data-base-ui-${e}`;
}
var ir = { style: { transition: "none" } }, ar = "data-base-ui-click-trigger", cn = "data-base-ui-swipe-ignore", ln = "data-swipe-ignore", ur = `[${cn}]`, cr = `[${ln}]`, lr = { fallbackAxisSide: "none" }, fr = { fallbackAxisSide: "end" }, fn = {
  clipPath: "inset(50%)",
  position: "fixed",
  top: 0,
  left: 0
}, et = /* @__PURE__ */ c.createContext(null), dn = () => c.useContext(et), pn = Ze("portal");
function hn(e = {}) {
  const { ref: t, container: n, componentProps: r = kt, elementProps: s } = e, o = Le(), d = dn()?.portalNode, [l, p] = c.useState(null), [f, a] = c.useState(null), h = _((E) => {
    E !== null && a(E);
  }), O = c.useRef(null);
  V(() => {
    if (n === null) {
      O.current && (O.current = null, a(null), p(null));
      return;
    }
    if (o == null) return;
    const E = (n && (_t(n) ? n : n.current)) ?? d ?? document.body;
    if (E == null) {
      O.current && (O.current = null, a(null), p(null));
      return;
    }
    O.current !== E && (O.current = E, a(null), p(E));
  }, [
    n,
    d,
    o
  ]);
  const A = At("div", r, {
    ref: [t, h],
    props: [{
      id: o,
      [pn]: ""
    }, s]
  });
  return {
    portalNode: f,
    portalSubtree: l && A ? /* @__PURE__ */ Ge.createPortal(A, l) : null
  };
}
var dr = /* @__PURE__ */ c.forwardRef(function(t, n) {
  const { children: r, container: s, className: o, render: d, renderGuards: l, style: p, ...f } = t, { portalNode: a, portalSubtree: h } = hn({
    container: s,
    ref: n,
    componentProps: t,
    elementProps: f
  }), O = c.useRef(null), A = c.useRef(null), E = c.useRef(null), Z = c.useRef(null), [m, ee] = c.useState(null), D = c.useRef(!1), N = m?.modal, H = m?.open, v = typeof l == "boolean" ? l : !!m && !m.modal && m.open && !!a;
  c.useEffect(() => {
    if (!a || N) return;
    function x(b) {
      a && b.relatedTarget && ye(b) && (b.type === "focusin" ? D.current && (De(a), D.current = !1) : (rn(a), D.current = !0));
    }
    return ae(S(a, "focusin", x, !0), S(a, "focusout", x, !0));
  }, [a, N]), c.useEffect(() => {
    !a || H !== !1 || (De(a), D.current = !1);
  }, [H, a]);
  const K = c.useMemo(() => ({
    beforeOutsideRef: O,
    afterOutsideRef: A,
    beforeInsideRef: E,
    afterInsideRef: Z,
    portalNode: a,
    setFocusManagerState: ee
  }), [a]);
  return /* @__PURE__ */ (0, k.jsxs)(c.Fragment, { children: [h, /* @__PURE__ */ (0, k.jsxs)(et.Provider, {
    value: K,
    children: [
      v && a && /* @__PURE__ */ (0, k.jsx)(He, {
        "data-type": "outside",
        ref: O,
        onFocus: (x) => {
          ye(x, a) ? E.current?.focus() : nn(m ? m.domReference : null)?.focus();
        }
      }),
      v && a && /* @__PURE__ */ (0, k.jsx)("span", {
        "aria-owns": a.id,
        style: fn
      }),
      a && /* @__PURE__ */ Ge.createPortal(r, a),
      v && a && /* @__PURE__ */ (0, k.jsx)(He, {
        "data-type": "outside",
        ref: A,
        onFocus: (x) => {
          ye(x, a) ? Z.current?.focus() : (tn(m ? m.domReference : null)?.focus(), m?.closeOnFocusOut && m?.onOpenChange(!1, J("focus-out", x.nativeEvent)));
        }
      })
    ]
  })] });
});
function tt() {
  const e = /* @__PURE__ */ new Map();
  return {
    emit(t, n) {
      e.get(t)?.forEach((r) => r(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);
    }
  };
}
var gn = class {
  nodesRef = { current: [] };
  events = tt();
  addNode(e) {
    this.nodesRef.current.push(e);
  }
  removeNode(e) {
    const t = this.nodesRef.current.findIndex((n) => n === e);
    t !== -1 && this.nodesRef.current.splice(t, 1);
  }
}, nt = /* @__PURE__ */ c.createContext(null), rt = /* @__PURE__ */ c.createContext(null), st = () => c.useContext(nt)?.id || null, ot = (e) => {
  const t = c.useContext(rt);
  return e ?? t;
};
function pr(e) {
  const t = Le(), n = ot(e), r = st();
  return V(() => {
    if (!t) return;
    const s = {
      id: t,
      parentId: r
    };
    return n?.addNode(s), () => {
      n?.removeNode(s);
    };
  }, [
    n,
    t,
    r
  ]), t;
}
function hr(e) {
  const { children: t, id: n } = e, r = st();
  return /* @__PURE__ */ (0, k.jsx)(nt.Provider, {
    value: c.useMemo(() => ({
      id: n,
      parentId: r
    }), [n, r]),
    children: t
  });
}
function gr(e) {
  const { children: t, externalTree: n } = e, r = Be(() => n ?? new gn()).current;
  return /* @__PURE__ */ (0, k.jsx)(rt.Provider, {
    value: r,
    children: t
  });
}
var mn = {
  intentional: "onClick",
  sloppy: "onPointerDown"
};
function En() {
  return !1;
}
function bn(e) {
  return {
    escapeKey: typeof e == "boolean" ? e : e?.escapeKey ?? !1,
    outsidePress: typeof e == "boolean" ? e : e?.outsidePress ?? !0
  };
}
function mr(e, t = {}) {
  const n = "rootStore" in e ? e.rootStore : e, r = n.useState("open"), s = n.useState("floatingElement"), { dataRef: o } = n.context, { enabled: d = !0, escapeKey: l = !0, outsidePress: p = !0, outsidePressEvent: f = "sloppy", referencePress: a = En, referencePressEvent: h = "sloppy", bubbles: O, externalTree: A } = t, E = ot(A), Z = _(typeof p == "function" ? p : () => !1), m = typeof p == "function" ? Z : p, ee = m !== !1, D = _(() => f), N = c.useRef(!1), H = c.useRef(!1), v = c.useRef(!1), { escapeKey: K, outsidePress: x } = bn(O), b = c.useRef(null), U = Fe(), xe = Fe(), w = _(() => {
    xe.clear(), o.current.insideReactTree = !1;
  }), ue = c.useRef(!1), ce = c.useRef(""), le = _(a), W = _((g) => {
    if (!r || !d || !l || g.key !== "Escape" || ue.current) return;
    const M = o.current.floatingContext?.nodeId, te = E ? ie(E.nodesRef.current, M) : [];
    if (!K && te.length > 0) {
      let q = !0;
      if (te.forEach((P) => {
        P.context?.open && !P.context.dataRef.current.__escapeKeyBubbles && (q = !1);
      }), !q) return;
    }
    const he = Bt(g) ? g.nativeEvent : g, X = J(Xt, he);
    n.setOpen(!1, X), !K && !X.isPropagationAllowed && g.stopPropagation();
  }), j = _(() => {
    o.current.insideReactTree = !0, xe.start(0, w);
  });
  c.useEffect(() => {
    if (!r || !d) return;
    o.current.__escapeKeyBubbles = K, o.current.__outsidePressBubbles = x;
    const g = new Ae(), M = new Ae();
    function te() {
      g.clear(), ue.current = !0;
    }
    function he() {
      g.start(Pt() ? 5 : 0, () => {
        ue.current = !1;
      });
    }
    function X() {
      v.current = !0, M.start(0, () => {
        v.current = !1;
      });
    }
    function q() {
      N.current = !1, H.current = !1;
    }
    function P() {
      const i = ce.current, u = i === "pen" || !i ? "mouse" : i, y = D(), R = typeof y == "function" ? y() : y;
      return typeof R == "string" ? R : R[u];
    }
    function ut(i) {
      const u = P();
      return u === "intentional" && i.type !== "click" || u === "sloppy" && i.type === "click";
    }
    function _e(i) {
      const u = o.current.floatingContext?.nodeId, y = E && ie(E.nodesRef.current, u).some((R) => C(i, R.context?.elements.floating));
      return C(i, n.select("floatingElement")) || C(i, n.select("domReferenceElement")) || y;
    }
    function ne(i) {
      if (ut(i)) {
        w();
        return;
      }
      if (o.current.insideReactTree) {
        w();
        return;
      }
      const u = be(i), y = `[${Ze("inert")}]`, R = se(u) ? u.getRootNode() : null, $ = Array.from((Ke(R) ? R : Y(n.select("floatingElement"))).querySelectorAll(y)), Ne = n.context.triggerElements;
      if (u && (Ne.hasElement(u) || Ne.hasMatchingElement((T) => G(T, u)))) return;
      let z = se(u) ? u : null;
      for (; z && !Ee(z); ) {
        const T = Nt(z);
        if (Ee(T) || !se(T)) break;
        z = T;
      }
      if ($.length && se(u) && !Wt(u) && !G(u, n.select("floatingElement")) && $.every((T) => !G(z, T))) return;
      if (Q(u) && !("touches" in i)) {
        const T = Ee(u), B = We(u), Me = /auto|scroll/, bt = T || Me.test(B.overflowX), St = T || Me.test(B.overflowY), yt = bt && u.clientWidth > 0 && u.scrollWidth > u.clientWidth, Rt = St && u.clientHeight > 0 && u.scrollHeight > u.clientHeight, Tt = B.direction === "rtl", It = Rt && (Tt ? i.offsetX <= u.offsetWidth - u.clientWidth : i.offsetX > u.clientWidth), Ot = yt && i.offsetY > u.clientHeight;
        if (It || Ot) return;
      }
      if (_e(i)) return;
      if (P() === "intentional" && v.current) {
        M.clear(), v.current = !1;
        return;
      }
      if (typeof m == "function" && !m(i)) return;
      const Et = o.current.floatingContext?.nodeId, we = E ? ie(E.nodesRef.current, Et) : [];
      if (we.length > 0) {
        let T = !0;
        if (we.forEach((B) => {
          B.context?.open && !B.context.dataRef.current.__outsidePressBubbles && (T = !1);
        }), !T) return;
      }
      n.setOpen(!1, J(Ut, i)), w();
    }
    function ct(i) {
      P() !== "sloppy" || i.pointerType === "touch" || !n.select("open") || !d || C(i, n.select("floatingElement")) || C(i, n.select("domReferenceElement")) || ne(i);
    }
    function lt(i) {
      if (P() !== "sloppy" || !n.select("open") || !d || C(i, n.select("floatingElement")) || C(i, n.select("domReferenceElement"))) return;
      const u = i.touches[0];
      u && (b.current = {
        startTime: Date.now(),
        startX: u.clientX,
        startY: u.clientY,
        dismissOnTouchEnd: !1,
        dismissOnMouseDown: !0
      }, U.start(1e3, () => {
        b.current && (b.current.dismissOnTouchEnd = !1, b.current.dismissOnMouseDown = !1);
      }));
    }
    function re(i, u) {
      const y = be(i);
      if (!y) return;
      const R = S(y, i.type, () => {
        u(i), R();
      });
    }
    function ft(i) {
      ce.current = "touch", re(i, lt);
    }
    function ge(i) {
      U.clear(), i.type === "pointerdown" && (ce.current = i.pointerType), !(i.type === "mousedown" && b.current && !b.current.dismissOnMouseDown) && re(i, (u) => {
        u.type === "pointerdown" ? ct(u) : ne(u);
      });
    }
    function me(i) {
      if (!N.current) return;
      const u = H.current;
      if (q(), P() === "intentional") {
        if (i.type === "pointercancel") {
          u && X();
          return;
        }
        if (!_e(i)) {
          if (u) {
            X();
            return;
          }
          typeof m == "function" && !m(i) || (M.clear(), v.current = !0, w());
        }
      }
    }
    function dt(i) {
      if (P() !== "sloppy" || !b.current || C(i, n.select("floatingElement")) || C(i, n.select("domReferenceElement"))) return;
      const u = i.touches[0];
      if (!u) return;
      const y = Math.abs(u.clientX - b.current.startX), R = Math.abs(u.clientY - b.current.startY), $ = Math.sqrt(y * y + R * R);
      $ > 5 && (b.current.dismissOnTouchEnd = !0), $ > 10 && (ne(i), U.clear(), b.current = null);
    }
    function pt(i) {
      re(i, dt);
    }
    function ht(i) {
      P() !== "sloppy" || !b.current || C(i, n.select("floatingElement")) || C(i, n.select("domReferenceElement")) || (b.current.dismissOnTouchEnd && ne(i), U.clear(), b.current = null);
    }
    function gt(i) {
      re(i, ht);
    }
    const I = Y(s), mt = ae(l && ae(S(I, "keydown", W), S(I, "compositionstart", te), S(I, "compositionend", he)), ee && ae(S(I, "click", ge, !0), S(I, "pointerdown", ge, !0), S(I, "pointerup", me, !0), S(I, "pointercancel", me, !0), S(I, "mousedown", ge, !0), S(I, "mouseup", me, !0), S(I, "touchstart", ft, !0), S(I, "touchmove", pt, !0), S(I, "touchend", gt, !0)));
    return () => {
      mt(), g.clear(), M.clear(), q(), v.current = !1;
    };
  }, [
    o,
    s,
    l,
    ee,
    m,
    r,
    d,
    K,
    x,
    W,
    w,
    D,
    E,
    n,
    U
  ]), c.useEffect(w, [m, w]);
  const fe = c.useMemo(() => ({
    onKeyDown: W,
    [mn[h]]: (g) => {
      le() && n.setOpen(!1, J(Yt, g.nativeEvent));
    },
    ...h !== "intentional" && { onClick(g) {
      le() && n.setOpen(!1, J("trigger-press", g.nativeEvent));
    } }
  }), [
    W,
    n,
    h,
    le
  ]), de = _((g) => {
    if (!r || !d || g.button !== 0) return;
    const M = be(g.nativeEvent);
    G(n.select("floatingElement"), M) && (N.current || (N.current = !0, H.current = !1));
  }), pe = _((g) => {
    !r || !d || (g.defaultPrevented || g.nativeEvent.defaultPrevented) && N.current && (H.current = !0);
  }), Pe = c.useMemo(() => ({
    onKeyDown: W,
    onPointerDown: pe,
    onMouseDown: pe,
    onClickCapture: j,
    onMouseDownCapture(g) {
      j(), de(g);
    },
    onPointerDownCapture(g) {
      j(), de(g);
    },
    onMouseUpCapture: j,
    onTouchEndCapture: j,
    onTouchMoveCapture: j
  }), [
    W,
    j,
    de,
    pe
  ]);
  return c.useMemo(() => d ? {
    reference: fe,
    floating: Pe,
    trigger: fe
  } : {}, [
    d,
    fe,
    Pe
  ]);
}
var L = (e, t, n, r, s, o, ...d) => {
  if (d.length > 0) throw new Error(Ft(1));
  let l;
  if (e && t && n && r && s && o) l = (p, f, a, h) => o(e(p, f, a, h), t(p, f, a, h), n(p, f, a, h), r(p, f, a, h), s(p, f, a, h), f, a, h);
  else if (e && t && n && r && s) l = (p, f, a, h) => s(e(p, f, a, h), t(p, f, a, h), n(p, f, a, h), r(p, f, a, h), f, a, h);
  else if (e && t && n && r) l = (p, f, a, h) => r(e(p, f, a, h), t(p, f, a, h), n(p, f, a, h), f, a, h);
  else if (e && t && n) l = (p, f, a, h) => n(e(p, f, a, h), t(p, f, a, h), f, a, h);
  else if (e && t) l = (p, f, a, h) => t(e(p, f, a, h), f, a, h);
  else if (e) l = e;
  else throw new Error("Missing arguments");
  return l;
}, it = Dt(), Sn = Ht(), yn = wt(19) ? Tn : In;
function at(e, t, n, r, s) {
  return yn(e, t, n, r, s);
}
function Rn(e, t, n, r, s) {
  const o = c.useCallback(() => t(e.getSnapshot(), n, r, s), [
    e,
    t,
    n,
    r,
    s
  ]);
  return (0, it.useSyncExternalStore)(e.subscribe, o, o);
}
on({
  before(e) {
    e.syncIndex = 0, e.didInitialize || (e.syncTick = 1, e.syncHooks = [], e.didChangeStore = !0, e.getSnapshot = () => {
      let t = !1;
      for (let n = 0; n < e.syncHooks.length; n += 1) {
        const r = e.syncHooks[n], s = r.selector(r.store.state, r.a1, r.a2, r.a3);
        (r.didChange || !Object.is(r.value, s)) && (t = !0, r.value = s, r.didChange = !1);
      }
      return t && (e.syncTick += 1), e.syncTick;
    });
  },
  after(e) {
    e.syncHooks.length > 0 && (e.didChangeStore && (e.didChangeStore = !1, e.subscribe = (t) => {
      const n = /* @__PURE__ */ new Set();
      for (const s of e.syncHooks) n.add(s.store);
      const r = [];
      for (const s of n) r.push(s.subscribe(t));
      return () => {
        for (const s of r) s();
      };
    }), (0, it.useSyncExternalStore)(e.subscribe, e.getSnapshot, e.getSnapshot));
  }
});
function Tn(e, t, n, r, s) {
  const o = sn();
  if (!o) return Rn(e, t, n, r, s);
  const d = o.syncIndex;
  o.syncIndex += 1;
  let l;
  return o.didInitialize ? (l = o.syncHooks[d], (l.store !== e || l.selector !== t || !Object.is(l.a1, n) || !Object.is(l.a2, r) || !Object.is(l.a3, s)) && (l.store !== e && (o.didChangeStore = !0), l.store = e, l.selector = t, l.a1 = n, l.a2 = r, l.a3 = s, l.didChange = !0)) : (l = {
    store: e,
    selector: t,
    a1: n,
    a2: r,
    a3: s,
    value: t(e.getSnapshot(), n, r, s),
    didChange: !1
  }, o.syncHooks.push(l)), l.value;
}
function In(e, t, n, r, s) {
  return (0, Sn.useSyncExternalStoreWithSelector)(e.subscribe, e.getSnapshot, e.getSnapshot, (o) => t(o, n, r, s));
}
var On = class {
  constructor(e) {
    this.state = e, this.listeners = /* @__PURE__ */ new Set(), this.updateTick = 0;
  }
  subscribe = (e) => (this.listeners.add(e), () => {
    this.listeners.delete(e);
  });
  getSnapshot = () => this.state;
  setState(e) {
    if (this.state === e) return;
    this.state = e, this.updateTick += 1;
    const t = this.updateTick;
    for (const n of this.listeners) {
      if (t !== this.updateTick) return;
      n(e);
    }
  }
  update(e) {
    for (const t in e) if (!Object.is(this.state[t], e[t])) {
      this.setState({
        ...this.state,
        ...e
      });
      return;
    }
  }
  set(e, t) {
    Object.is(this.state[e], t) || this.setState({
      ...this.state,
      [e]: t
    });
  }
  notifyAll() {
    const e = { ...this.state };
    this.setState(e);
  }
  use(e, t, n, r) {
    return at(this, e, t, n, r);
  }
}, Cn = class extends On {
  constructor(e, t = {}, n) {
    super(e), this.context = t, this.selectors = n;
  }
  useSyncedValue(e, t) {
    c.useDebugValue(e), V(() => {
      this.state[e] !== t && this.set(e, t);
    }, [e, t]);
  }
  useSyncedValueWithCleanup(e, t) {
    const n = this;
    V(() => (n.state[e] !== t && n.set(e, t), () => {
      n.set(e, void 0);
    }), [
      n,
      e,
      t
    ]);
  }
  useSyncedValues(e) {
    const t = this;
    V(() => {
      t.update(e);
    }, [t, ...Object.values(e)]);
  }
  useControlledProp(e, t) {
    c.useDebugValue(e);
    const n = t !== void 0;
    V(() => {
      n && !Object.is(this.state[e], t) && super.setState({
        ...this.state,
        [e]: t
      });
    }, [
      e,
      t,
      n
    ]);
  }
  select(e, t, n, r) {
    const s = this.selectors[e];
    return s(this.state, t, n, r);
  }
  useState(e, t, n, r) {
    return c.useDebugValue(e), at(this, this.selectors[e], t, n, r);
  }
  useContextCallback(e, t) {
    c.useDebugValue(e);
    const n = _(t ?? Mt);
    this.context[e] = n;
  }
  useStateSetter(e) {
    const t = c.useRef(void 0);
    return t.current === void 0 && (t.current = (n) => {
      this.set(e, n);
    }), t.current;
  }
  observe(e, t) {
    let n;
    typeof e == "function" ? n = e : n = this.selectors[e];
    let r = n(this.state);
    return t(r, r, this), this.subscribe((s) => {
      const o = n(s);
      if (!Object.is(r, o)) {
        const d = r;
        r = o, t(o, d, this);
      }
    });
  }
}, vn = {
  open: L((e) => e.open),
  transitionStatus: L((e) => e.transitionStatus),
  domReferenceElement: L((e) => e.domReferenceElement),
  referenceElement: L((e) => e.positionReference ?? e.referenceElement),
  floatingElement: L((e) => e.floatingElement),
  floatingId: L((e) => e.floatingId)
}, Er = class extends Cn {
  constructor(e) {
    const { syncOnly: t, nested: n, onOpenChange: r, triggerElements: s, ...o } = e;
    super({
      ...o,
      positionReference: o.referenceElement,
      domReferenceElement: o.referenceElement
    }, {
      onOpenChange: r,
      dataRef: { current: {} },
      events: tt(),
      nested: n,
      triggerElements: s
    }, vn), this.syncOnly = t;
  }
  syncOpenEvent = (e, t) => {
    (!e || !this.state.open || t != null && Lt(t)) && (this.context.dataRef.current.openEvent = e ? t : void 0);
  };
  dispatchOpenChange = (e, t) => {
    this.syncOpenEvent(e, t.event);
    const n = {
      open: e,
      reason: t.reason,
      nativeEvent: t.event,
      nested: this.context.nested,
      triggerElement: t.trigger
    };
    this.context.events.emit("openchange", n);
  };
  setOpen = (e, t) => {
    if (this.syncOnly) {
      this.context.onOpenChange?.(e, t);
      return;
    }
    this.dispatchOpenChange(e, t), this.context.onOpenChange?.(e, t);
  };
}, br = class {
  constructor() {
    this.elementsSet = /* @__PURE__ */ new Set(), this.idMap = /* @__PURE__ */ new Map();
  }
  add(e, t) {
    const n = this.idMap.get(e);
    n !== t && (n !== void 0 && this.elementsSet.delete(n), this.elementsSet.add(t), this.idMap.set(e, t));
  }
  delete(e) {
    const t = this.idMap.get(e);
    t && (this.elementsSet.delete(t), this.idMap.delete(e));
  }
  hasElement(e) {
    return this.elementsSet.has(e);
  }
  hasMatchingElement(e) {
    for (const t of this.elementsSet) if (e(t)) return !0;
    return !1;
  }
  getById(e) {
    return this.idMap.get(e);
  }
  entries() {
    return this.idMap.entries();
  }
  elements() {
    return this.elementsSet.values();
  }
  get size() {
    return this.idMap.size;
  }
};
function Sr(e = []) {
  const t = e.map((f) => f?.reference), n = e.map((f) => f?.floating), r = e.map((f) => f?.item), s = e.map((f) => f?.trigger), o = c.useCallback((f) => oe(f, e, "reference"), t), d = c.useCallback((f) => oe(f, e, "floating"), n), l = c.useCallback((f) => oe(f, e, "item"), r), p = c.useCallback((f) => oe(f, e, "trigger"), s);
  return c.useMemo(() => ({
    getReferenceProps: o,
    getFloatingProps: d,
    getItemProps: l,
    getTriggerProps: p
  }), [
    o,
    d,
    l,
    p
  ]);
}
function oe(e, t, n) {
  const r = /* @__PURE__ */ new Map(), s = n === "item", o = {};
  n === "floating" && (o.tabIndex = -1, o[Vt] = "");
  for (const d in e)
    s && e && (d === "active" || d === "selected") || (o[d] = e[d]);
  for (let d = 0; d < t.length; d += 1) {
    let l;
    const p = t[d]?.[n];
    typeof p == "function" ? l = e ? p(e) : null : l = p, l && je(o, l, s, r);
  }
  return je(o, e, s, r), o;
}
function je(e, t, n, r) {
  for (const s in t) {
    const o = t[s];
    n && (s === "active" || s === "selected") || (s.startsWith("on") ? (r.has(s) || r.set(s, []), typeof o == "function" && (r.get(s)?.push(o), e[s] = (...d) => r.get(s)?.map((l) => l(...d)).find((l) => l !== void 0))) : e[s] = o);
  }
}
var ve = (function(e) {
  return e.open = "data-open", e.closed = "data-closed", e[e.startingStyle = ke.startingStyle] = "startingStyle", e[e.endingStyle = ke.endingStyle] = "endingStyle", e.anchorHidden = "data-anchor-hidden", e.side = "data-side", e.align = "data-align", e;
})({}), Oe = /* @__PURE__ */ (function(e) {
  return e.popupOpen = "data-popup-open", e.pressed = "data-pressed", e;
})({}), xn = { [Oe.popupOpen]: "" }, Pn = {
  [Oe.popupOpen]: "",
  [Oe.pressed]: ""
}, _n = { [ve.open]: "" }, Nn = { [ve.closed]: "" }, wn = { [ve.anchorHidden]: "" }, yr = { open(e) {
  return e ? xn : null;
} }, Rr = { open(e) {
  return e ? Pn : null;
} }, Tr = {
  open(e) {
    return e ? _n : Nn;
  },
  anchorHidden(e) {
    return e ? wn : null;
  }
};
export {
  or as A,
  Ce as B,
  ar as C,
  Ze as D,
  fr as E,
  nn as F,
  ie as H,
  nr as I,
  rr as L,
  sr as M,
  en as N,
  He as O,
  tn as P,
  ye as R,
  dn as S,
  lr as T,
  er as V,
  st as _,
  yr as a,
  dr as b,
  Er as c,
  at as d,
  L as f,
  pr as g,
  gr as h,
  Rr as i,
  an as j,
  ae as k,
  Cn as l,
  hr as m,
  Oe as n,
  Sr as o,
  mr as p,
  Tr as r,
  br as s,
  ve as t,
  On as u,
  ot as v,
  ir as w,
  hn as x,
  gn as y,
  tr as z
};

//# sourceMappingURL=popupStateMapping.js.map