import s from "../../../@babel/runtime/helpers/esm/extends.js";
import { createElement as p, forwardRef as i, useRef as m, useCallback as h } from "react";
import { composeEventHandlers as l } from "../../primitive/dist/index.js";
import { composeRefs as v } from "../../react-compose-refs/dist/index.js";
import { createContextScope as C } from "../../react-context/dist/index.js";
import { useControllableState as O } from "../../react-use-controllable-state/dist/index.js";
import { Primitive as P } from "../../react-primitive/dist/index.js";
import { createMenuScope as w, Portal as R, Content as S, Label as I, Item as E, Separator as y, Root as T, Anchor as A } from "../../react-menu/dist/index.js";
import { useId as x } from "../../react-id/dist/index.js";
const D = "DropdownMenu", [N, oe] = C(D, [
  w
]), $ = w(), [k, M] = N(D), K = (e) => {
  const { __scopeDropdownMenu: t, children: n, dir: o, open: a, defaultOpen: c, onOpenChange: f, modal: r = !0 } = e, d = $(t), g = m(null), [u = !1, b] = O({
    prop: a,
    defaultProp: c,
    onChange: f
  });
  return /* @__PURE__ */ p(k, {
    scope: t,
    triggerId: x(),
    triggerRef: g,
    contentId: x(),
    open: u,
    onOpenChange: b,
    onOpenToggle: h(
      () => b(
        (_) => !_
      ),
      [
        b
      ]
    ),
    modal: r
  }, /* @__PURE__ */ p(T, s({}, d, {
    open: u,
    onOpenChange: b,
    dir: o,
    modal: r
  }), n));
}, L = "DropdownMenuTrigger", F = /* @__PURE__ */ i((e, t) => {
  const { __scopeDropdownMenu: n, disabled: o = !1, ...a } = e, c = M(L, n), f = $(n);
  return /* @__PURE__ */ p(A, s({
    asChild: !0
  }, f), /* @__PURE__ */ p(P.button, s({
    type: "button",
    id: c.triggerId,
    "aria-haspopup": "menu",
    "aria-expanded": c.open,
    "aria-controls": c.open ? c.contentId : void 0,
    "data-state": c.open ? "open" : "closed",
    "data-disabled": o ? "" : void 0,
    disabled: o
  }, a, {
    ref: v(t, c.triggerRef),
    onPointerDown: l(e.onPointerDown, (r) => {
      !o && r.button === 0 && r.ctrlKey === !1 && (c.onOpenToggle(), c.open || r.preventDefault());
    }),
    onKeyDown: l(e.onKeyDown, (r) => {
      o || ([
        "Enter",
        " "
      ].includes(r.key) && c.onOpenToggle(), r.key === "ArrowDown" && c.onOpenChange(!0), [
        "Enter",
        " ",
        "ArrowDown"
      ].includes(r.key) && r.preventDefault());
    })
  })));
}), G = (e) => {
  const { __scopeDropdownMenu: t, ...n } = e, o = $(t);
  return /* @__PURE__ */ p(R, s({}, o, n));
}, H = "DropdownMenuContent", U = /* @__PURE__ */ i((e, t) => {
  const { __scopeDropdownMenu: n, ...o } = e, a = M(H, n), c = $(n), f = m(!1);
  return /* @__PURE__ */ p(S, s({
    id: a.contentId,
    "aria-labelledby": a.triggerId
  }, c, o, {
    ref: t,
    onCloseAutoFocus: l(e.onCloseAutoFocus, (r) => {
      var d;
      f.current || (d = a.triggerRef.current) === null || d === void 0 || d.focus(), f.current = !1, r.preventDefault();
    }),
    onInteractOutside: l(e.onInteractOutside, (r) => {
      const d = r.detail.originalEvent, g = d.button === 0 && d.ctrlKey === !0, u = d.button === 2 || g;
      (!a.modal || u) && (f.current = !0);
    }),
    style: {
      ...e.style,
      "--radix-dropdown-menu-content-transform-origin": "var(--radix-popper-transform-origin)",
      "--radix-dropdown-menu-content-available-width": "var(--radix-popper-available-width)",
      "--radix-dropdown-menu-content-available-height": "var(--radix-popper-available-height)",
      "--radix-dropdown-menu-trigger-width": "var(--radix-popper-anchor-width)",
      "--radix-dropdown-menu-trigger-height": "var(--radix-popper-anchor-height)"
    }
  }));
}), W = /* @__PURE__ */ i((e, t) => {
  const { __scopeDropdownMenu: n, ...o } = e, a = $(n);
  return /* @__PURE__ */ p(I, s({}, a, o, {
    ref: t
  }));
}), j = /* @__PURE__ */ i((e, t) => {
  const { __scopeDropdownMenu: n, ...o } = e, a = $(n);
  return /* @__PURE__ */ p(E, s({}, a, o, {
    ref: t
  }));
}), q = /* @__PURE__ */ i((e, t) => {
  const { __scopeDropdownMenu: n, ...o } = e, a = $(n);
  return /* @__PURE__ */ p(y, s({}, a, o, {
    ref: t
  }));
}), ne = K, re = F, te = G, ae = U, ce = W, de = j, pe = q;
export {
  ae as Content,
  K as DropdownMenu,
  U as DropdownMenuContent,
  j as DropdownMenuItem,
  W as DropdownMenuLabel,
  G as DropdownMenuPortal,
  q as DropdownMenuSeparator,
  F as DropdownMenuTrigger,
  de as Item,
  ce as Label,
  te as Portal,
  ne as Root,
  pe as Separator,
  re as Trigger,
  oe as createDropdownMenuScope
};
