import { o as _e } from "./rolldown-runtime.js";
import { i as Oe, t as Fe } from "./vendor/react.js";
import { t as Y } from "./check.js";
import { t as ze } from "./chevron-right.js";
import { l as Ee, m as Be, p as Ge } from "./safeReact.js";
import { r as K, s as He, t as Ae } from "./useRenderElement.js";
import { n as Le, t as Ue } from "./useIsoLayoutEffect.js";
import { r as qe, t as Ye } from "./useButton.js";
import { t as u } from "./utils.js";
import { n as X } from "./useTimeout.js";
import { t as Ke } from "./useBaseUiId.js";
import { n as L } from "./shadowDom.js";
import { M as Xe, O as U, _ as $e, g as Je, i as q, o as We, v as Qe, y as Ve } from "./popupStateMapping.js";
import { t as k } from "./owner.js";
import { n as Ze, t as et } from "./safePolygon.js";
import { r as tt } from "./createBaseUIEventDetails.js";
import { i as ot } from "./useOpenInteractionType.js";
import { o as nt } from "./useSyncedFloatingRootContext.js";
import { t as rt } from "./useFocus.js";
import { t as st } from "./CompositeItem.js";
import { t as at } from "./Separator.js";
import { t as it } from "./getPseudoElementBounds.js";
import { t as ut } from "./useTriggerFocusGuards.js";
import { t as dt } from "./Kbd.js";
import { _ as $, a as ct, c as pt, d as lt, f as mt, g as ft, h as gt, i as xt, l as J, m as bt, n as wt, o as Mt, p as vt, r as ht, s as yt, t as Nt, u as Dt } from "./MenuSubmenuTrigger.js";
var d = /* @__PURE__ */ _e(Oe());
function W(e) {
  if (Ge(e) && e.hasAttribute("data-rootownerid")) return e.getAttribute("data-rootownerid") ?? void 0;
  if (!Be(e))
    return W(Ee(e));
}
function jt(e) {
  const { enabled: o = !0, mouseDownAction: n, open: r } = e, a = d.useRef(!1);
  return d.useMemo(() => o ? {
    onMouseDown: (i) => {
      (n === "open" && !r || n === "close" && r) && (a.current = !0, k(i.currentTarget).addEventListener("click", () => {
        a.current = !1;
      }, { once: !0 }));
    },
    onClick: (i) => {
      a.current && (a.current = !1, i.preventBaseUIHandler());
    }
  } : K, [
    o,
    n,
    r
  ]);
}
var t = Fe(), N = 2, Tt = Xe(function(o, n) {
  const { render: r, className: a, disabled: i = !1, nativeButton: g = !0, id: j, openOnHover: T, delay: b = 100, closeDelay: O = 0, handle: le, payload: me, style: fe, ...ge } = o, xe = $(!0), s = le?.store ?? xe?.store;
  if (!s) throw new Error(He(85));
  const m = Ke(j), be = s.useState("isTriggerActive", m), R = s.useState("floatingRootContext"), p = s.useState("isOpenedByTrigger", m), v = d.useRef(null), c = St(), we = qe(!0), F = Qe(), h = d.useMemo(() => F ?? new Ve(), [F]), { registerTrigger: Me, isMountedByThisTrigger: z } = nt(m, v, s, {
    payload: me,
    closeDelay: O,
    parent: c,
    floatingTreeRoot: h,
    floatingNodeId: Je(h),
    floatingParentNodeId: $e(),
    keyboardEventRelay: we?.relayKeyboardEvent
  }), l = c.type === "menubar", ve = s.useState("disabled"), w = i || ve || l && c.context.disabled, { getButtonProps: he, buttonRef: ye } = Ye({
    disabled: w,
    native: g
  });
  d.useEffect(() => {
    !p && c.type === void 0 && (s.context.allowMouseUpTriggerRef.current = !1);
  }, [
    s,
    p,
    c.type
  ]);
  const x = d.useRef(null), E = X(), S = Le((f) => {
    if (!x.current) return;
    E.clear(), s.context.allowMouseUpTriggerRef.current = !1;
    const M = f.target;
    if (L(x.current, M) || L(s.select("positionerElement"), M) || M === x.current || M != null && W(M) === s.select("rootId")) return;
    const y = it(x.current);
    f.clientX >= y.left - N && f.clientX <= y.right + N && f.clientY >= y.top - N && f.clientY <= y.bottom + N || h.events.emit("close", {
      domEvent: f,
      reason: tt
    });
  });
  d.useEffect(() => {
    p && s.select("lastOpenChangeReason") === "trigger-hover" && k(x.current).addEventListener("mouseup", S, { once: !0 });
  }, [
    p,
    S,
    s
  ]);
  const I = l && c.context.hasSubmenuOpen, Ne = Ze(R, {
    enabled: (T ?? I) && !w && c.type !== "context-menu" && (!l || I && !z),
    handleClose: et({ blockPointerEvents: !l }),
    mouseOnly: !0,
    move: !1,
    restMs: c.type === void 0 ? b : void 0,
    delay: { close: O },
    triggerElementRef: v,
    externalTree: h,
    isActiveTrigger: be,
    isClosing: () => s.select("transitionStatus") === "ending"
  }), De = Rt(p, s.select("lastOpenChangeReason")), je = ot(R, {
    enabled: !w && c.type !== "context-menu",
    event: p && l ? "click" : "mousedown",
    toggle: !0,
    ignoreMouse: !1,
    stickIfOpen: c.type === void 0 ? De : !1
  }), Te = rt(R, { enabled: !w && I }), Re = jt({
    open: p,
    enabled: l,
    mouseDownAction: "open"
  }), Se = We([je, Te]), B = {
    disabled: w,
    open: p
  }, Ie = s.useState("triggerProps", z), G = [
    x,
    n,
    ye,
    Me,
    v
  ], H = [
    Se.getReferenceProps(),
    Ne ?? K,
    Ie,
    {
      "aria-haspopup": "menu",
      id: m,
      onMouseDown: (f) => {
        s.select("open") || (E.start(200, () => {
          s.context.allowMouseUpTriggerRef.current = !0;
        }), k(f.currentTarget).addEventListener("mouseup", S, { once: !0 }));
      }
    },
    l ? { role: "menuitem" } : {},
    Re,
    ge,
    he
  ], { preFocusGuardRef: ke, handlePreFocusGuardFocus: Ce, handleFocusTargetFocus: Pe } = ut(s, v), A = Ae("button", o, {
    enabled: !l,
    stateAttributesMapping: q,
    state: B,
    ref: G,
    props: H
  });
  return l ? /* @__PURE__ */ (0, t.jsx)(st, {
    tag: "button",
    render: r,
    className: a,
    style: fe,
    state: B,
    refs: G,
    props: H,
    stateAttributesMapping: q
  }) : p ? /* @__PURE__ */ (0, t.jsxs)(d.Fragment, { children: [
    /* @__PURE__ */ (0, t.jsx)(U, {
      ref: ke,
      onFocus: Ce
    }, `${m}-pre-focus-guard`),
    /* @__PURE__ */ (0, t.jsx)(d.Fragment, { children: A }, m),
    /* @__PURE__ */ (0, t.jsx)(U, {
      ref: s.context.triggerFocusTargetRef,
      onFocus: Pe
    }, `${m}-post-focus-guard`)
  ] }) : /* @__PURE__ */ (0, t.jsx)(d.Fragment, { children: A }, m);
});
function Rt(e, o) {
  const n = X(), [r, a] = d.useState(!1);
  return Ue(() => {
    e && o === "trigger-hover" ? (a(!0), n.start(500, () => {
      a(!1);
    })) : e || (n.clear(), a(!1));
  }, [
    e,
    o,
    n
  ]), r;
}
function St() {
  const e = ft(!0), o = $(!0), n = xt(!0);
  return d.useMemo(() => n ? {
    type: "menubar",
    context: n
  } : e && !o ? {
    type: "context-menu",
    context: e
  } : { type: void 0 }, [
    e,
    o,
    n
  ]);
}
function D({ ...e }) {
  return /* @__PURE__ */ (0, t.jsx)(ht, {
    "data-slot": "dropdown-menu-root",
    ...e
  });
}
D.displayName = "DropdownMenu.Root";
function Q({ ...e }) {
  return /* @__PURE__ */ (0, t.jsx)(J, {
    "data-slot": "dropdown-menu-portal",
    ...e
  });
}
Q.displayName = "DropdownMenu.Portal";
function C({ ...e }) {
  return /* @__PURE__ */ (0, t.jsx)(Tt, {
    "data-slot": "dropdown-menu-trigger",
    ...e
  });
}
C.displayName = "DropdownMenu.Trigger";
function V({ ...e }) {
  return /* @__PURE__ */ (0, t.jsx)(vt, {
    "data-slot": "dropdown-menu-group",
    ...e
  });
}
V.displayName = "DropdownMenu.Group";
function Z({ ...e }) {
  return /* @__PURE__ */ (0, t.jsx)(wt, {
    "data-slot": "dropdown-menu-sub",
    ...e
  });
}
Z.displayName = "DropdownMenu.Sub";
function ee({ className: e, inset: o, children: n, ...r }) {
  return /* @__PURE__ */ (0, t.jsxs)(Nt, {
    "data-slot": "dropdown-menu-sub-trigger",
    "data-inset": o,
    className: u("focus:bg-accent focus:text-accent-foreground data-open:bg-accent data-open:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground gap-2 rounded-sm px-2 py-2 text-sm [&_svg:not([class*='size-'])]:size-4 group/dd-sub flex cursor-default items-center outline-hidden select-none data-[inset]:ps-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 transition-[color,background-color,transform] duration-150 active:scale-[0.99]", e),
    ...r,
    children: [n, /* @__PURE__ */ (0, t.jsx)(ze, { className: "ms-auto rtl:rotate-180 transition-transform duration-150 group-data-open/dd-sub:translate-x-0.5" })]
  });
}
ee.displayName = "DropdownMenu.SubTrigger";
function te({ ...e }) {
  return /* @__PURE__ */ (0, t.jsx)(yt, {
    "data-slot": "dropdown-menu-radio-group",
    ...e
  });
}
te.displayName = "DropdownMenu.RadioGroup";
function oe({ className: e, children: o, ...n }) {
  return /* @__PURE__ */ (0, t.jsxs)(Mt, {
    "data-slot": "dropdown-menu-radio-item",
    className: u("focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground gap-2 rounded-sm py-2 pe-8 ps-2 text-sm [&_svg:not([class*='size-'])]:size-4 relative flex cursor-default items-center outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 transition-colors duration-150", e),
    ...n,
    children: [/* @__PURE__ */ (0, t.jsx)("span", {
      className: "pointer-events-none absolute end-2 flex items-center justify-center",
      "data-slot": "dropdown-menu-radio-item-indicator",
      children: /* @__PURE__ */ (0, t.jsx)(ct, {
        className: "animate-in zoom-in-75 duration-150 motion-reduce:animate-none",
        children: /* @__PURE__ */ (0, t.jsx)(Y, {})
      })
    }), o]
  });
}
oe.displayName = "DropdownMenu.RadioItem";
function ne({ className: e, children: o, checked: n, ...r }) {
  return /* @__PURE__ */ (0, t.jsxs)(gt, {
    "data-slot": "dropdown-menu-checkbox-item",
    className: u("focus:bg-accent focus:text-accent-foreground focus:**:text-accent-foreground gap-2 rounded-sm py-2 pe-8 ps-2 text-sm [&_svg:not([class*='size-'])]:size-4 relative flex cursor-default items-center outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 transition-colors duration-150", e),
    checked: n,
    ...r,
    children: [/* @__PURE__ */ (0, t.jsx)("span", {
      className: "pointer-events-none absolute end-2 flex items-center justify-center",
      "data-slot": "dropdown-menu-checkbox-item-indicator",
      children: /* @__PURE__ */ (0, t.jsx)(bt, {
        className: "animate-in zoom-in-75 duration-150 motion-reduce:animate-none",
        children: /* @__PURE__ */ (0, t.jsx)(Y, {})
      })
    }), o]
  });
}
ne.displayName = "DropdownMenu.CheckboxItem";
function re({ className: e, ...o }) {
  return /* @__PURE__ */ (0, t.jsx)("span", {
    "data-slot": "dropdown-menu-shortcut",
    className: u("text-muted-foreground group-focus/dropdown-menu-item:text-accent-foreground ms-auto text-xs tracking-widest", e),
    ...o
  });
}
re.displayName = "DropdownMenu.Shortcut";
var It = {
  auto: "",
  sm: "w-48",
  md: "w-56",
  lg: "w-64"
};
function P({ align: e = "start", alignOffset: o = 0, side: n = "bottom", sideOffset: r = 4, width: a = "auto", className: i, ...g }) {
  return /* @__PURE__ */ (0, t.jsx)(J, { children: /* @__PURE__ */ (0, t.jsx)(pt, {
    className: "isolate z-50 outline-none",
    align: e,
    alignOffset: o,
    side: n,
    sideOffset: r,
    children: /* @__PURE__ */ (0, t.jsx)(Dt, {
      "data-slot": "dropdown-menu-popup",
      className: u("data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", "ring-1 ring-foreground/10 bg-background text-popover-foreground min-w-32 rounded-lg p-1 shadow-lg z-50 max-h-(--available-height) w-(--anchor-width) origin-(--transform-origin) overflow-x-hidden overflow-y-auto outline-none data-closed:overflow-hidden", "duration-200 motion-reduce:animate-none", It[a], i),
      ...g
    })
  }) });
}
P.displayName = "DropdownMenu.Popup";
function se({ align: e = "start", alignOffset: o = -3, side: n = "right", sideOffset: r = 0, className: a, ...i }) {
  return /* @__PURE__ */ (0, t.jsx)(P, {
    "data-slot": "dropdown-menu-sub-popup",
    className: u("min-w-[96px] w-auto", a),
    align: e,
    alignOffset: o,
    side: n,
    sideOffset: r,
    ...i
  });
}
se.displayName = "DropdownMenu.SubPopup";
function ae({ className: e, avatar: o, title: n, subtitle: r, children: a, ...i }) {
  return a ? /* @__PURE__ */ (0, t.jsx)("div", {
    "data-slot": "dropdown-menu-header",
    className: u("border-b border-border px-4 py-3", e),
    ...i,
    children: a
  }) : /* @__PURE__ */ (0, t.jsx)("div", {
    "data-slot": "dropdown-menu-header",
    className: u("border-b border-border px-4 py-3", e),
    ...i,
    children: /* @__PURE__ */ (0, t.jsxs)("div", {
      className: "flex items-center gap-3",
      children: [o, /* @__PURE__ */ (0, t.jsxs)("div", {
        className: "flex flex-col min-w-0",
        children: [n && /* @__PURE__ */ (0, t.jsx)("span", {
          className: "text-sm font-semibold text-foreground truncate",
          children: n
        }), r && /* @__PURE__ */ (0, t.jsx)("span", {
          className: "text-sm text-muted-foreground truncate",
          children: r
        })]
      })]
    })
  });
}
ae.displayName = "DropdownMenu.Header";
function ie({ className: e, inset: o, ...n }) {
  return /* @__PURE__ */ (0, t.jsx)(mt, {
    "data-slot": "dropdown-menu-label",
    "data-inset": o,
    className: u("px-4 py-2 text-xs font-medium text-quaternary-foreground uppercase tracking-wider", "data-[inset]:ps-8", e),
    ...n
  });
}
ie.displayName = "DropdownMenu.Label";
function ue({ className: e, icon: o, shortcut: n, destructive: r = !1, render: a, inset: i, variant: g = "default", children: j, ...T }) {
  const b = r || g === "destructive";
  return /* @__PURE__ */ (0, t.jsxs)(lt, {
    "data-slot": "dropdown-menu-item",
    "data-inset": i,
    "data-variant": b ? "destructive" : g,
    className: u("group/dropdown-menu-item relative flex items-center gap-2 mx-1.5 px-2.5 py-2 rounded-md cursor-pointer outline-none", "text-sm font-semibold text-secondary-foreground", "focus:bg-muted focus:text-secondary-foreground", "data-[disabled]:pointer-events-none data-[disabled]:opacity-50", "data-[inset]:ps-8", "[&_svg:not([class*='size-'])]:size-4 [&_svg]:pointer-events-none [&_svg]:shrink-0", "transition-[color,background-color,transform] duration-150 active:scale-[0.99]", b && "text-destructive focus:text-destructive focus:bg-destructive/10", e),
    render: a,
    ...T,
    children: [
      o && /* @__PURE__ */ (0, t.jsx)("span", {
        className: u("size-4 shrink-0 transition-colors duration-150", b ? "text-destructive" : "text-quaternary-foreground group-focus/dropdown-menu-item:text-secondary-foreground"),
        children: o
      }),
      /* @__PURE__ */ (0, t.jsx)("span", {
        className: "flex-1",
        children: j
      }),
      n && /* @__PURE__ */ (0, t.jsx)(_, {
        className: "transition-colors duration-150 group-focus/dropdown-menu-item:bg-brand-500/10 group-focus/dropdown-menu-item:text-brand-600",
        children: n
      })
    ]
  });
}
ue.displayName = "DropdownMenu.Item";
function de({ className: e, ...o }) {
  return /* @__PURE__ */ (0, t.jsx)(at, {
    "data-slot": "dropdown-menu-separator",
    className: u("my-1 h-px bg-surface-2", e),
    ...o
  });
}
de.displayName = "DropdownMenu.Separator";
function ce({ className: e, children: o, ...n }) {
  return /* @__PURE__ */ (0, t.jsx)("div", {
    "data-slot": "dropdown-menu-items",
    className: u("py-1", e),
    ...n,
    children: o
  });
}
ce.displayName = "DropdownMenu.Items";
function _({ className: e, children: o, ...n }) {
  return /* @__PURE__ */ (0, t.jsx)(dt, {
    variant: "outline",
    size: "xs",
    className: e,
    ...n,
    children: o
  });
}
_.displayName = "DropdownMenu.ShortcutBadge";
function pe({ trigger: e, open: o, onOpenChange: n, children: r }) {
  return /* @__PURE__ */ (0, t.jsxs)(D, {
    open: o,
    onOpenChange: n,
    children: [/* @__PURE__ */ (0, t.jsx)(C, { render: e }), r]
  });
}
pe.displayName = "DropdownMenu.Simple";
var oo = Object.assign(D, {
  Root: D,
  Portal: Q,
  Trigger: C,
  Popup: P,
  Group: V,
  Label: ie,
  Item: ue,
  CheckboxItem: ne,
  RadioGroup: te,
  RadioItem: oe,
  Separator: de,
  Shortcut: re,
  ShortcutBadge: _,
  Sub: Z,
  SubTrigger: ee,
  SubPopup: se,
  Header: ae,
  Items: ce,
  Simple: pe
});
export {
  oo as t
};

//# sourceMappingURL=DropdownMenu.js.map