import { o as ot } from "./rolldown-runtime.js";
import { i as st, t as rt } from "./vendor/react.js";
import { l as Ie, n as at, o as it, r as ut, s as W, t as J, u as lt } from "./useRenderElement.js";
import { n as ce, t as ge } from "./useIsoLayoutEffect.js";
import { t as ct } from "./useButton.js";
import { a as Ve, n as Se, r as dt, t as je } from "./useTransitionStatus.js";
import { n as Pe } from "./useTimeout.js";
import { n as pt, t as de } from "./useBaseUiId.js";
import { a as ft } from "./detectBrowser.js";
import { A as gt, E as mt, T as vt, _ as ht, a as xt, b as bt, f as T, g as Ct, h as Rt, j as yt, l as Mt, m as It, o as De, p as Pt, r as St, s as Et, y as Tt } from "./popupStateMapping.js";
import { n as kt } from "./DirectionContext.js";
import { n as Ot, r as wt, t as Nt } from "./safePolygon.js";
import { l as At, p as Ee, t as ee, y as Me } from "./createBaseUIEventDetails.js";
import { a as Ft, i as Lt, r as Vt, t as jt } from "./useOpenInteractionType.js";
import { i as Dt, n as _t, r as Ut, t as Gt } from "./usePositioner.js";
import { a as Bt, i as Ht, n as Kt, r as Yt, s as qt, t as Wt } from "./useSyncedFloatingRootContext.js";
import { n as Jt, t as Xt } from "./useTypeahead.js";
import { t as $t } from "./useRole.js";
import { t as zt } from "./inertValue.js";
import { t as _e } from "./useControlled.js";
import { n as me } from "./useCompositeListItem.js";
import { t as Qt } from "./CompositeList.js";
import { s as Zt } from "./composite2.js";
import { t as en } from "./ToolbarRootContext.js";
import { t as tn } from "./useAnchoredPopupScrollLock.js";
var o = /* @__PURE__ */ ot(st()), Ue = /* @__PURE__ */ o.createContext(void 0);
function pe(e) {
  const s = o.useContext(Ue);
  if (s === void 0 && !e) throw new Error(W(33));
  return s;
}
var Ge = /* @__PURE__ */ o.createContext(void 0);
function $(e) {
  const s = o.useContext(Ge);
  if (s === void 0 && !e) throw new Error(W(36));
  return s;
}
var nn = /* @__PURE__ */ o.createContext(void 0);
function Te(e = !0) {
  const s = o.useContext(nn);
  if (s === void 0 && !e) throw new Error(W(25));
  return s;
}
var Be = /* @__PURE__ */ o.createContext(void 0);
function on() {
  const e = o.useContext(Be);
  if (e === void 0) throw new Error(W(30));
  return e;
}
function sn(e) {
  const { closeOnClick: s, highlighted: a, id: v, nodeId: R, store: h, typingRef: f, itemRef: l, itemMetadata: n } = e, { events: c } = h.useState("floatingTreeRoot"), d = Te(!0), b = d !== void 0;
  return o.useMemo(() => ({
    id: v,
    role: "menuitem",
    tabIndex: a ? 0 : -1,
    onKeyDown(g) {
      g.key === " " && f?.current && g.preventDefault();
    },
    onMouseMove(g) {
      R && c.emit("itemhover", {
        nodeId: R,
        target: g.currentTarget
      });
    },
    onClick(g) {
      s && c.emit("close", {
        domEvent: g,
        reason: Ee
      });
    },
    onMouseUp(g) {
      if (d) {
        const M = d.initialCursorPointRef.current;
        if (d.initialCursorPointRef.current = null, b && M && Math.abs(g.clientX - M.x) <= 1 && Math.abs(g.clientY - M.y) <= 1 || b && !ft && g.button === 2) return;
      }
      l.current && h.context.allowMouseUpTriggerRef.current && (!b || g.button === 2) && (!n || n.type === "regular-item") && l.current.click();
    }
  }), [
    s,
    a,
    v,
    c,
    R,
    h,
    f,
    l,
    d,
    b,
    n
  ]);
}
var ke = { type: "regular-item" };
function ve(e) {
  const { closeOnClick: s, disabled: a = !1, highlighted: v, id: R, store: h, typingRef: f = h.context.typingRef, nativeButton: l, itemMetadata: n, nodeId: c } = e, d = o.useRef(null), { getButtonProps: b, buttonRef: g } = ct({
    disabled: a,
    focusableWhenDisabled: !0,
    native: l,
    composite: !0
  }), M = sn({
    closeOnClick: s,
    highlighted: v,
    id: R,
    nodeId: c,
    store: h,
    typingRef: f,
    itemRef: d,
    itemMetadata: n
  }), I = o.useCallback((i) => Ie(M, { onMouseEnter() {
    n.type === "submenu-trigger" && n.setActive();
  } }, i, b), [
    M,
    b,
    n
  ]), P = it(d, g);
  return o.useMemo(() => ({
    getItemProps: I,
    itemRef: P
  }), [I, P]);
}
var Le = /* @__PURE__ */ (function(e) {
  return e.checked = "data-checked", e.unchecked = "data-unchecked", e.disabled = "data-disabled", e.highlighted = "data-highlighted", e;
})({}), he = {
  checked(e) {
    return e ? { [Le.checked]: "" } : { [Le.unchecked]: "" };
  },
  ...Ve
}, F = rt(), Xn = /* @__PURE__ */ o.forwardRef(function(s, a) {
  const { render: v, className: R, id: h, label: f, nativeButton: l = !1, disabled: n = !1, closeOnClick: c = !1, checked: d, defaultChecked: b, onCheckedChange: g, style: M, ...I } = s, P = me({ label: f }), i = pe(!0), C = de(h), { store: p } = $(), r = p.useState("isActive", P.index), _ = p.useState("itemProps"), [k, t] = _e({
    controlled: d,
    default: b ?? !1,
    name: "MenuCheckboxItem",
    state: "checked"
  }), { getItemProps: O, itemRef: y } = ve({
    closeOnClick: c,
    disabled: n,
    highlighted: r,
    id: C,
    store: p,
    nativeButton: l,
    nodeId: i?.context.nodeId,
    itemMetadata: ke
  }), E = o.useMemo(() => ({
    disabled: n,
    highlighted: r,
    checked: k
  }), [
    n,
    r,
    k
  ]), u = J("div", s, {
    state: E,
    stateAttributesMapping: he,
    props: [
      _,
      {
        role: "menuitemcheckbox",
        "aria-checked": k,
        onClick: ce((D) => {
          const A = {
            ...ee(Ee, D.nativeEvent),
            preventUnmountOnClose: () => {
            }
          };
          g?.(!k, A), !A.isCanceled && t((L) => !L);
        })
      },
      I,
      O
    ],
    ref: [
      y,
      a,
      P.ref
    ]
  });
  return /* @__PURE__ */ (0, F.jsx)(Be.Provider, {
    value: E,
    children: u
  });
}), $n = /* @__PURE__ */ o.forwardRef(function(s, a) {
  const { render: v, className: R, style: h, keepMounted: f = !1, ...l } = s, n = on(), c = o.useRef(null), { transitionStatus: d, setMounted: b } = je(n.checked);
  return Se({
    open: n.checked,
    ref: c,
    onComplete() {
      n.checked || b(!1);
    }
  }), J("span", s, {
    state: {
      checked: n.checked,
      disabled: n.disabled,
      highlighted: n.highlighted,
      transitionStatus: d
    },
    ref: [a, c],
    stateAttributesMapping: he,
    props: {
      "aria-hidden": !0,
      ...l
    },
    enabled: f || n.checked
  });
}), He = /* @__PURE__ */ o.createContext(void 0);
function rn() {
  const e = o.useContext(He);
  if (e === void 0) throw new Error(W(31));
  return e;
}
var zn = /* @__PURE__ */ o.forwardRef(function(s, a) {
  const { render: v, className: R, style: h, ...f } = s, [l, n] = o.useState(void 0), c = o.useMemo(() => ({ setLabelId: n }), [n]), d = J("div", s, {
    ref: a,
    props: {
      role: "group",
      "aria-labelledby": l,
      ...f
    }
  });
  return /* @__PURE__ */ (0, F.jsx)(He.Provider, {
    value: c,
    children: d
  });
}), Qn = /* @__PURE__ */ o.forwardRef(function(s, a) {
  const { className: v, render: R, id: h, style: f, ...l } = s, n = de(h), { setLabelId: c } = rn();
  return ge(() => (c(n), () => {
    c(void 0);
  }), [c, n]), J("div", s, {
    ref: a,
    props: {
      id: n,
      role: "presentation",
      ...l
    }
  });
}), Zn = /* @__PURE__ */ o.forwardRef(function(s, a) {
  const { render: v, className: R, id: h, label: f, nativeButton: l = !1, disabled: n = !1, closeOnClick: c = !0, style: d, ...b } = s, g = me({ label: f }), M = pe(!0), I = de(h), { store: P } = $(), i = P.useState("isActive", g.index), C = P.useState("itemProps"), { getItemProps: p, itemRef: r } = ve({
    closeOnClick: c,
    disabled: n,
    highlighted: i,
    id: I,
    store: P,
    nativeButton: l,
    nodeId: M?.context.nodeId,
    itemMetadata: ke
  });
  return J("div", s, {
    state: {
      disabled: n,
      highlighted: i
    },
    props: [
      C,
      b,
      p
    ],
    ref: [
      r,
      a,
      g.ref
    ]
  });
}), an = {
  ...St,
  ...Ve
}, eo = /* @__PURE__ */ o.forwardRef(function(s, a) {
  const { render: v, className: R, style: h, finalFocus: f, ...l } = s, { store: n } = $(), { side: c, align: d } = pe(), b = en(!0) != null, g = n.useState("open"), M = n.useState("transitionStatus"), I = n.useState("popupProps"), P = n.useState("mounted"), i = n.useState("instantType"), C = n.useState("activeTriggerElement"), p = n.useState("parent"), r = n.useState("lastOpenChangeReason"), _ = n.useState("rootId"), k = n.useState("floatingRootContext"), t = n.useState("floatingTreeRoot"), O = n.useState("closeDelay"), y = n.useState("activeTriggerElement"), E = p.type === "context-menu";
  Se({
    open: g,
    ref: n.context.popupRef,
    onComplete() {
      g && n.context.onOpenChangeComplete?.(!0);
    }
  }), o.useEffect(() => {
    function x(G) {
      n.setOpen(!1, ee(G.reason, G.domEvent));
    }
    return t.events.on("close", x), () => {
      t.events.off("close", x);
    };
  }, [t.events, n]);
  const u = n.useState("hoverEnabled"), D = n.useState("disabled");
  wt(k, {
    enabled: u && !D && !E && p.type !== "menubar",
    closeDelay: O
  });
  const A = {
    transitionStatus: M,
    side: c,
    align: d,
    open: g,
    nested: p.type === "menu",
    instant: i
  }, L = o.useCallback((x) => {
    n.set("popupElement", x);
  }, [n]), z = J("div", s, {
    state: A,
    ref: [
      a,
      n.context.popupRef,
      L
    ],
    stateAttributesMapping: an,
    props: [
      I,
      { onKeyDown(x) {
        b && Zt.has(x.key) && x.stopPropagation();
      } },
      _t(M),
      l,
      { "data-rootownerid": _ }
    ]
  });
  let U = p.type === void 0 || E;
  return (C || p.type === "menubar" && r !== "outside-press") && (U = !0), /* @__PURE__ */ (0, F.jsx)(Ft, {
    context: k,
    modal: E,
    disabled: !P,
    returnFocus: f === void 0 ? U : f,
    initialFocus: p.type !== "menu",
    restoreFocus: !0,
    externalTree: p.type !== "menubar" ? t : void 0,
    previousFocusableElement: y,
    nextFocusableElement: p.type === void 0 ? n.context.triggerFocusTargetRef : void 0,
    beforeContentFocusGuardRef: p.type === void 0 ? n.context.beforeContentFocusGuardRef : void 0,
    children: z
  });
}), Ke = /* @__PURE__ */ o.createContext(void 0);
function un() {
  const e = o.useContext(Ke);
  if (e === void 0) throw new Error(W(32));
  return e;
}
var to = /* @__PURE__ */ o.forwardRef(function(s, a) {
  const { keepMounted: v = !1, ...R } = s, { store: h } = $();
  return h.useState("mounted") || v ? /* @__PURE__ */ (0, F.jsx)(Ke.Provider, {
    value: v,
    children: /* @__PURE__ */ (0, F.jsx)(bt, {
      ref: a,
      ...R
    })
  }) : null;
}), no = /* @__PURE__ */ o.forwardRef(function(s, a) {
  const { anchor: v, positionMethod: R = "absolute", className: h, render: f, side: l, align: n, sideOffset: c = 0, alignOffset: d = 0, collisionBoundary: b = "clipping-ancestors", collisionPadding: g = 5, arrowPadding: M = 5, sticky: I = !1, disableAnchorTracking: P = !1, collisionAvoidance: i = vt, style: C, ...p } = s, { store: r } = $(), _ = un(), k = Te(!0), t = r.useState("parent"), O = r.useState("floatingRootContext"), y = r.useState("floatingTreeRoot"), E = r.useState("mounted"), u = r.useState("open"), D = r.useState("modal"), A = r.useState("openMethod"), L = r.useState("activeTriggerElement"), z = r.useState("transitionStatus"), U = r.useState("positionerElement"), x = r.useState("instantType"), G = r.useState("hasViewport"), re = r.useState("lastOpenChangeReason"), H = r.useState("floatingNodeId"), Q = r.useState("floatingParentNodeId"), te = O.useState("domReferenceElement"), ne = o.useRef(null), V = dt(U, !1, !1);
  let oe = v, ae = c, ie = d, X = n, se = i;
  t.type === "context-menu" && (oe = v ?? t.context?.anchor, X = X ?? "start", !l && X !== "center" && (ie = s.alignOffset ?? 2, ae = s.sideOffset ?? -5));
  let K = l, Z = X;
  t.type === "menu" ? (K = K ?? "inline-end", Z = Z ?? "start", se = s.collisionAvoidance ?? mt) : t.type === "menubar" && (K = K ?? "bottom", Z = Z ?? "start");
  const ue = t.type === "context-menu", B = Ut({
    anchor: oe,
    floatingRootContext: O,
    positionMethod: k ? "fixed" : R,
    mounted: E,
    side: K,
    sideOffset: ae,
    align: Z,
    alignOffset: ie,
    arrowPadding: ue ? 0 : M,
    collisionBoundary: b,
    collisionPadding: g,
    sticky: I,
    nodeId: H,
    keepMounted: _,
    disableAnchorTracking: P,
    collisionAvoidance: se,
    shiftCrossAxis: ue && !("side" in se && se.side === "flip"),
    externalTree: y,
    adaptiveOrigin: G ? Dt : void 0
  });
  o.useEffect(() => {
    function w(N) {
      N.open && (N.parentNodeId === H && r.set("hoverEnabled", !1), N.nodeId !== H && N.parentNodeId === r.select("floatingParentNodeId") && r.setOpen(!1, ee(Me)));
    }
    return y.events.on("menuopenchange", w), () => {
      y.events.off("menuopenchange", w);
    };
  }, [
    r,
    y.events,
    H
  ]), o.useEffect(() => {
    if (r.select("floatingParentNodeId") == null) return;
    function w(N) {
      if (N.open || N.nodeId !== r.select("floatingParentNodeId")) return;
      const q = N.reason ?? "sibling-open";
      r.setOpen(!1, ee(q));
    }
    return y.events.on("menuopenchange", w), () => {
      y.events.off("menuopenchange", w);
    };
  }, [y.events, r]);
  const Y = Pe();
  o.useEffect(() => {
    u || Y.clear();
  }, [u, Y]), o.useEffect(() => {
    function w(N) {
      if (!(!u || N.nodeId !== r.select("floatingParentNodeId")))
        if (N.target && L && L !== N.target) {
          const q = r.select("closeDelay");
          q > 0 ? Y.isStarted() || Y.start(q, () => {
            r.setOpen(!1, ee(Me));
          }) : r.setOpen(!1, ee(Me));
        } else Y.clear();
    }
    return y.events.on("itemhover", w), () => {
      y.events.off("itemhover", w);
    };
  }, [
    y.events,
    u,
    L,
    r,
    Y
  ]), o.useEffect(() => {
    const w = {
      open: u,
      nodeId: H,
      parentNodeId: Q,
      reason: r.select("lastOpenChangeReason")
    };
    y.events.emit("menuopenchange", w);
  }, [
    y.events,
    u,
    r,
    H,
    Q
  ]), ge(() => {
    const w = te, N = ne.current;
    if (w && (ne.current = w), N && w && w !== N) {
      r.set("instantType", void 0);
      const q = new AbortController();
      return V(() => {
        r.set("instantType", "trigger-change");
      }, q.signal), () => {
        q.abort();
      };
    }
  }, [
    te,
    V,
    r
  ]);
  const xe = {
    open: u,
    side: B.side,
    align: B.align,
    anchorHidden: B.anchorHidden,
    nested: t.type === "menu",
    instant: x
  }, be = t.type === "menubar" && t.context.modal;
  tn(u && (be || D && re !== "trigger-hover"), A === "touch", U, L);
  const Ce = Gt(s, xe, {
    styles: B.positionerStyles,
    transitionStatus: z,
    props: p,
    refs: [a, r.useStateSetter("positionerElement")],
    hidden: !E,
    inert: !u
  }), Re = E && t.type !== "menu" && (t.type !== "menubar" && D && re !== "trigger-hover" || t.type === "menubar" && t.context.modal);
  let le = null;
  return t.type === "menubar" ? le = t.context.contentElement : t.type === void 0 && (le = L), /* @__PURE__ */ (0, F.jsxs)(Ue.Provider, {
    value: B,
    children: [Re && /* @__PURE__ */ (0, F.jsx)(Vt, {
      ref: t.type === "context-menu" || t.type === "nested-context-menu" ? t.context.internalBackdropRef : null,
      inert: zt(!u),
      cutout: le
    }), /* @__PURE__ */ (0, F.jsx)(It, {
      id: H,
      children: /* @__PURE__ */ (0, F.jsx)(Qt, {
        elementsRef: r.context.itemDomElements,
        labelsRef: r.context.itemLabels,
        children: Ce
      })
    })]
  });
}), Ye = /* @__PURE__ */ o.createContext(void 0);
function ln() {
  const e = o.useContext(Ye);
  if (e === void 0) throw new Error(W(34));
  return e;
}
var oo = /* @__PURE__ */ o.memo(/* @__PURE__ */ o.forwardRef(function(s, a) {
  const { render: v, className: R, value: h, defaultValue: f, onValueChange: l, disabled: n = !1, style: c, ...d } = s, [b, g] = _e({
    controlled: h,
    default: f,
    name: "MenuRadioGroup"
  }), M = ce(l), I = ce((C, p) => {
    M?.(C, p), !p.isCanceled && g(C);
  }), P = J("div", s, {
    state: { disabled: n },
    ref: a,
    props: {
      role: "group",
      "aria-disabled": n || void 0,
      ...d
    }
  }), i = o.useMemo(() => ({
    value: b,
    setValue: I,
    disabled: n
  }), [
    b,
    I,
    n
  ]);
  return /* @__PURE__ */ (0, F.jsx)(Ye.Provider, {
    value: i,
    children: P
  });
})), qe = /* @__PURE__ */ o.createContext(void 0);
function cn() {
  const e = o.useContext(qe);
  if (e === void 0) throw new Error(W(35));
  return e;
}
var so = /* @__PURE__ */ o.forwardRef(function(s, a) {
  const { render: v, className: R, id: h, label: f, nativeButton: l = !1, disabled: n = !1, closeOnClick: c = !1, value: d, style: b, ...g } = s, M = me({ label: f }), I = pe(!0), P = de(h), { store: i } = $(), C = i.useState("isActive", M.index), p = i.useState("itemProps"), { value: r, setValue: _, disabled: k } = ln(), t = k || n, O = r === d, { getItemProps: y, itemRef: E } = ve({
    closeOnClick: c,
    disabled: t,
    highlighted: C,
    id: P,
    store: i,
    nativeButton: l,
    nodeId: I?.context.nodeId,
    itemMetadata: ke
  }), u = o.useMemo(() => ({
    disabled: t,
    highlighted: C,
    checked: O
  }), [
    t,
    C,
    O
  ]), D = J("div", s, {
    state: u,
    stateAttributesMapping: he,
    props: [
      p,
      {
        role: "menuitemradio",
        "aria-checked": O,
        onClick: ce((A) => {
          _(d, {
            ...ee(Ee, A.nativeEvent),
            preventUnmountOnClose: () => {
            }
          });
        })
      },
      g,
      y
    ],
    ref: [
      E,
      a,
      M.ref
    ]
  });
  return /* @__PURE__ */ (0, F.jsx)(qe.Provider, {
    value: u,
    children: D
  });
}), ro = /* @__PURE__ */ o.forwardRef(function(s, a) {
  const { render: v, className: R, style: h, keepMounted: f = !1, ...l } = s, n = cn(), c = o.useRef(null), { transitionStatus: d, setMounted: b } = je(n.checked);
  return Se({
    open: n.checked,
    ref: c,
    onComplete() {
      n.checked || b(!1);
    }
  }), J("span", s, {
    state: {
      checked: n.checked,
      disabled: n.disabled,
      highlighted: n.highlighted,
      transitionStatus: d
    },
    stateAttributesMapping: he,
    ref: [a, c],
    props: {
      "aria-hidden": !0,
      ...l
    },
    enabled: f || n.checked
  });
}), dn = /* @__PURE__ */ o.createContext(null);
function pn(e) {
  const s = o.useContext(dn);
  if (s === null && !e) throw new Error(W(5));
  return s;
}
var fn = {
  ...Yt,
  disabled: T((e) => e.parent.type === "menubar" && e.parent.context.disabled || e.disabled),
  modal: T((e) => (e.parent.type === void 0 || e.parent.type === "context-menu") && (e.modal ?? !0)),
  openMethod: T((e) => e.openMethod),
  allowMouseEnter: T((e) => e.allowMouseEnter),
  stickIfOpen: T((e) => e.stickIfOpen),
  parent: T((e) => e.parent),
  rootId: T((e) => e.parent.type === "menu" ? e.parent.store.select("rootId") : e.parent.type !== void 0 ? e.parent.context.rootId : e.rootId),
  activeIndex: T((e) => e.activeIndex),
  isActive: T((e, s) => e.activeIndex === s),
  hoverEnabled: T((e) => e.hoverEnabled),
  instantType: T((e) => e.instantType),
  lastOpenChangeReason: T((e) => e.openChangeReason),
  floatingTreeRoot: T((e) => e.parent.type === "menu" ? e.parent.store.select("floatingTreeRoot") : e.floatingTreeRoot),
  floatingNodeId: T((e) => e.floatingNodeId),
  floatingParentNodeId: T((e) => e.floatingParentNodeId),
  itemProps: T((e) => e.itemProps),
  closeDelay: T((e) => e.closeDelay),
  hasViewport: T((e) => e.hasViewport),
  keyboardEventRelay: T((e) => {
    if (e.keyboardEventRelay) return e.keyboardEventRelay;
    if (e.parent.type === "menu") return e.parent.store.select("keyboardEventRelay");
  })
}, gn = class We extends Mt {
  constructor(s) {
    super({
      ...mn(),
      ...s
    }, {
      positionerRef: /* @__PURE__ */ o.createRef(),
      popupRef: /* @__PURE__ */ o.createRef(),
      typingRef: { current: !1 },
      itemDomElements: { current: [] },
      itemLabels: { current: [] },
      allowMouseUpTriggerRef: { current: !1 },
      triggerFocusTargetRef: /* @__PURE__ */ o.createRef(),
      beforeContentFocusGuardRef: /* @__PURE__ */ o.createRef(),
      onOpenChangeComplete: void 0,
      triggerElements: new Et()
    }, fn), this.unsubscribeParentListener = this.observe("parent", (a) => {
      if (this.unsubscribeParentListener?.(), a.type === "menu") {
        let v = a.store.select("rootId"), R = a.store.select("floatingTreeRoot"), h = a.store.select("keyboardEventRelay");
        this.unsubscribeParentListener = a.store.subscribe(() => {
          const f = a.store.select("rootId"), l = a.store.select("floatingTreeRoot"), n = a.store.select("keyboardEventRelay");
          v === f && R === l && h === n || (v = f, R = l, h = n, this.notifyAll());
        }), this.context.allowMouseUpTriggerRef = a.store.context.allowMouseUpTriggerRef;
        return;
      }
      a.type !== void 0 && (this.context.allowMouseUpTriggerRef = a.context.allowMouseUpTriggerRef), this.unsubscribeParentListener = null;
    });
  }
  setOpen(s, a) {
    this.state.floatingRootContext.context.events.emit("setOpen", {
      open: s,
      eventDetails: a
    });
  }
  static useStore(s, a) {
    const v = lt(() => new We(a)).current;
    return s ?? v;
  }
  unsubscribeParentListener = null;
};
function mn() {
  return {
    ...Kt(),
    disabled: !1,
    modal: !0,
    openMethod: null,
    allowMouseEnter: !1,
    stickIfOpen: !0,
    parent: { type: void 0 },
    rootId: void 0,
    activeIndex: null,
    hoverEnabled: !0,
    instantType: void 0,
    openChangeReason: null,
    floatingTreeRoot: new Tt(),
    floatingNodeId: void 0,
    floatingParentNodeId: null,
    itemProps: ut,
    keyboardEventRelay: void 0,
    closeDelay: 0,
    hasViewport: !1
  };
}
var Je = /* @__PURE__ */ o.createContext(void 0);
function Xe() {
  return o.useContext(Je);
}
var vn = yt(function(s) {
  const { children: a, open: v, onOpenChange: R, onOpenChangeComplete: h, defaultOpen: f = !1, disabled: l = !1, modal: n, loopFocus: c = !0, orientation: d = "vertical", actionsRef: b, closeParentOnEsc: g = !1, handle: M, triggerId: I, defaultTriggerId: P = null, highlightItemOnHover: i = !0 } = s, C = Te(!0), p = $(!0), r = pn(!0), _ = Xe(), k = o.useMemo(() => _ && p ? {
    type: "menu",
    store: p.store
  } : r ? {
    type: "menubar",
    context: r
  } : C && !p ? {
    type: "context-menu",
    context: C
  } : { type: void 0 }, [
    C,
    p,
    r,
    _
  ]), t = gn.useStore(M?.store, {
    open: f,
    openProp: v,
    activeTriggerId: P,
    triggerIdProp: I,
    parent: k
  });
  gt(() => {
    v === void 0 && t.state.open === !1 && f === !0 && t.update({
      open: !0,
      activeTriggerId: P
    });
  }), t.useControlledProp("openProp", v), t.useControlledProp("triggerIdProp", I), t.useContextCallback("onOpenChangeComplete", h);
  const O = t.useState("floatingTreeRoot"), y = Ct(O), E = ht();
  ge(() => {
    C && !p ? t.update({
      parent: {
        type: "context-menu",
        context: C
      },
      floatingNodeId: y,
      floatingParentNodeId: E
    }) : p && t.update({
      floatingNodeId: y,
      floatingParentNodeId: E
    });
  }, [
    C,
    p,
    y,
    E,
    t
  ]);
  const u = t.useState("open"), D = t.useState("activeTriggerElement"), A = t.useState("positionerElement"), L = t.useState("hoverEnabled"), z = t.useState("disabled"), U = t.useState("lastOpenChangeReason"), x = t.useState("parent"), G = t.useState("activeIndex"), re = t.useState("payload"), H = t.useState("floatingParentNodeId"), Q = o.useRef(null), te = H != null, { openMethod: ne, triggerProps: V } = jt(u);
  t.useSyncedValues({
    disabled: l,
    modal: x.type === void 0 ? n : void 0,
    openMethod: ne,
    rootId: pt()
  }), Ht(t);
  const { forceUnmount: oe } = Bt(u, t, () => {
    t.update({
      allowMouseEnter: !1,
      stickIfOpen: !0
    });
  }), ae = o.useRef(x.type !== "context-menu"), ie = Pe();
  o.useEffect(() => {
    if (u || (Q.current = null), x.type === "context-menu") {
      if (!u) {
        ie.clear(), ae.current = !1;
        return;
      }
      ie.start(500, () => {
        ae.current = !0;
      });
    }
  }, [
    ie,
    u,
    x.type
  ]), ge(() => {
    !u && !L && t.set("hoverEnabled", !0);
  }, [
    u,
    L,
    t
  ]);
  const X = o.useRef(!0), se = Pe(), K = ce((m, S) => {
    const j = S.reason;
    if (u === m && S.trigger === D && U === j || (S.preventUnmountOnClose = () => {
      t.set("preventUnmountingOnClose", !0);
    }, !m && S.trigger == null && (S.trigger = D ?? void 0), R?.(m, S), S.isCanceled)) return;
    t.state.floatingRootContext.dispatchOpenChange(m, S);
    const fe = S.event;
    if (m === !1 && fe?.type === "click" && fe.pointerType === "touch" && !X.current) return;
    if (!m && G !== null) {
      const nt = t.context.itemDomElements.current[G];
      queueMicrotask(() => {
        nt?.setAttribute("tabindex", "-1");
      });
    }
    m && j === "trigger-focus" ? (X.current = !1, se.start(300, () => {
      X.current = !0;
    })) : (X.current = !0, se.clear());
    const Ae = (j === "trigger-press" || j === "item-press") && fe.detail === 0 && fe?.isTrusted, tt = !m && (j === "escape-key" || j == null), ye = {
      open: m,
      openChangeReason: j
    };
    Q.current = S.event ?? null;
    const Fe = S.trigger?.id ?? null;
    (Fe || m) && (ye.activeTriggerId = Fe, ye.activeTriggerElement = S.trigger ?? null), t.update(ye), x.type === "menubar" && (j === "trigger-focus" || j === "focus-out" || j === "trigger-hover" || j === "list-navigation" || j === "sibling-open") ? t.set("instantType", "group") : Ae || tt ? t.set("instantType", Ae ? "click" : "dismiss") : t.set("instantType", void 0);
  }), Z = o.useCallback(() => {
    t.setOpen(!1, ee(At));
  }, [t]);
  o.useImperativeHandle(b, () => ({
    unmount: oe,
    close: Z
  }), [oe, Z]);
  let ue;
  x.type === "context-menu" && (ue = x.context), o.useImperativeHandle(ue?.positionerRef, () => A, [A]), o.useImperativeHandle(ue?.actionsRef, () => ({ setOpen: K }), [K]);
  const B = Wt({
    popupStore: t,
    onOpenChange: K
  }), Y = B.context.events;
  o.useEffect(() => {
    const m = ({ open: S, eventDetails: j }) => K(S, j);
    return Y.on("setOpen", m), () => {
      Y?.off("setOpen", m);
    };
  }, [Y, K]);
  const xe = Pt(B, {
    enabled: !z,
    bubbles: { escapeKey: g && x.type === "menu" },
    outsidePress() {
      return x.type !== "context-menu" || Q.current?.type === "contextmenu" ? !0 : ae.current;
    },
    externalTree: te ? O : void 0
  }), be = $t(B, { role: "menu" }), Oe = kt(), Ce = o.useCallback((m) => {
    t.select("activeIndex") !== m && t.set("activeIndex", m);
  }, [t]), Re = Jt(B, {
    enabled: !z,
    listRef: t.context.itemDomElements,
    activeIndex: G,
    nested: x.type !== void 0,
    loopFocus: c,
    orientation: d,
    parentOrientation: x.type === "menubar" ? x.context.orientation : void 0,
    rtl: Oe === "rtl",
    disabledIndices: at,
    onNavigate: Ce,
    openOnArrowKeyDown: x.type !== "context-menu",
    externalTree: te ? O : void 0,
    focusItemOnHover: i
  }), le = o.useCallback((m) => {
    t.context.typingRef.current = m;
  }, [t]), { getReferenceProps: w, getFloatingProps: N, getItemProps: q, getTriggerProps: we } = De([
    xe,
    be,
    Re,
    Xt(B, {
      listRef: t.context.itemLabels,
      elementsRef: t.context.itemDomElements,
      activeIndex: G,
      resetMs: 500,
      onMatch: (m) => {
        u && m !== G && t.set("activeIndex", m);
      },
      onTypingChange: le
    })
  ]), $e = o.useMemo(() => {
    const m = Ie(w(), { onMouseMove() {
      t.set("allowMouseEnter", !0);
    } }, V);
    return delete m.role, m;
  }, [
    w,
    t,
    V
  ]), ze = o.useMemo(() => {
    const m = we();
    if (!m) return m;
    const S = Ie(m, V);
    return delete S.role, delete S["aria-controls"], S;
  }, [we, V]), Qe = o.useMemo(() => N({
    onMouseMove() {
      t.set("allowMouseEnter", !0), x.type === "menu" && t.set("hoverEnabled", !1);
    },
    onClick() {
      t.select("hoverEnabled") && t.set("hoverEnabled", !1);
    },
    onKeyDown(m) {
      const S = t.select("keyboardEventRelay");
      S && !m.isPropagationStopped() && S(m);
    }
  }), [
    N,
    x.type,
    t
  ]), Ze = o.useMemo(() => q(), [q]);
  t.useSyncedValues({
    floatingRootContext: B,
    activeTriggerProps: $e,
    inactiveTriggerProps: ze,
    popupProps: Qe,
    itemProps: Ze
  });
  const et = o.useMemo(() => ({
    store: t,
    parent: k
  }), [t, k]), Ne = /* @__PURE__ */ (0, F.jsx)(Ge.Provider, {
    value: et,
    children: typeof a == "function" ? a({ payload: re }) : a
  });
  return x.type === void 0 || x.type === "context-menu" ? /* @__PURE__ */ (0, F.jsx)(Rt, {
    externalTree: O,
    children: Ne
  }) : Ne;
});
function ao(e) {
  const s = $().store, a = o.useMemo(() => ({ parentMenu: s }), [s]);
  return /* @__PURE__ */ (0, F.jsx)(Je.Provider, {
    value: a,
    children: /* @__PURE__ */ (0, F.jsx)(vn, { ...e })
  });
}
var io = /* @__PURE__ */ o.forwardRef(function(s, a) {
  const { render: v, className: R, label: h, id: f, nativeButton: l = !1, openOnHover: n = !0, delay: c = 100, closeDelay: d = 0, disabled: b = !1, style: g, ...M } = s, I = me(), P = pe(), { store: i } = $(), C = de(f), p = i.useState("open"), r = i.useState("floatingRootContext"), _ = i.useState("floatingTreeRoot"), k = qt(C, i), t = o.useCallback((V) => {
    const oe = k(V);
    return V !== null && i.select("open") && i.select("activeTriggerId") == null && i.update({
      activeTriggerId: C,
      activeTriggerElement: V,
      closeDelay: d
    }), oe;
  }, [
    k,
    d,
    i,
    C
  ]), O = o.useRef(null), y = o.useCallback((V) => {
    O.current = V, i.set("activeTriggerElement", V);
  }, [i]), E = Xe();
  if (!E?.parentMenu) throw new Error(W(37));
  i.useSyncedValue("closeDelay", d);
  const u = E.parentMenu, D = u.useState("itemProps"), A = u.useState("isActive", I.index), L = o.useMemo(() => ({
    type: "submenu-trigger",
    setActive() {
      u.set("activeIndex", I.index);
    }
  }), [u, I.index]), z = i.useState("disabled"), U = b || z, { getItemProps: x, itemRef: G } = ve({
    closeOnClick: !1,
    disabled: U,
    highlighted: A,
    id: C,
    store: i,
    typingRef: u.context.typingRef,
    nativeButton: l,
    itemMetadata: L,
    nodeId: P?.context.nodeId
  }), re = i.useState("hoverEnabled"), H = u.useState("allowMouseEnter"), Q = Ot(r, {
    enabled: re && n && !U,
    handleClose: Nt({ blockPointerEvents: !0 }),
    mouseOnly: !0,
    move: !0,
    restMs: c,
    delay: H ? {
      open: c,
      close: d
    } : 0,
    triggerElementRef: O,
    externalTree: _,
    isClosing: () => i.select("transitionStatus") === "ending"
  }), te = De([Lt(r, {
    enabled: !U,
    event: "mousedown",
    toggle: !n,
    ignoreMouse: n,
    stickIfOpen: !1
  })]), ne = i.useState("triggerProps", !0);
  return delete ne.id, J("div", s, {
    state: {
      disabled: U,
      highlighted: A,
      open: p
    },
    stateAttributesMapping: xt,
    props: [
      te.getReferenceProps(),
      Q,
      ne,
      D,
      {
        tabIndex: p || A ? 0 : -1,
        onBlur() {
          A && u.set("activeIndex", null);
        }
      },
      M,
      x
    ],
    ref: [
      a,
      I.ref,
      G,
      t,
      y
    ]
  });
});
export {
  $ as _,
  ro as a,
  no as c,
  Zn as d,
  Qn as f,
  Te as g,
  Xn as h,
  pn as i,
  to as l,
  $n as m,
  ao as n,
  so as o,
  zn as p,
  vn as r,
  oo as s,
  io as t,
  eo as u
};

//# sourceMappingURL=MenuSubmenuTrigger.js.map