import d from "../../../@babel/runtime/helpers/esm/extends.js";
import { createElement as c, forwardRef as $, useRef as m, useCallback as C } from "react";
import { composeEventHandlers as l } from "../../primitive/dist/index.js";
import { composeRefs as S } from "../../react-compose-refs/dist/index.js";
import { createContextScope as v } from "../../react-context/dist/index.js";
import { useControllableState as g } from "../../react-use-controllable-state/dist/index.js";
import { Primitive as I } from "../../react-primitive/dist/index.js";
import { createMenuScope as _, Portal as P, Content as O, Label as R, Item as y, CheckboxItem as T, RadioItem as E, ItemIndicator as k, Separator as G, SubTrigger as A, SubContent as N, Root as K, Anchor as L, Group as F, RadioGroup as H, Sub as U } from "../../react-menu/dist/index.js";
import { useId as w } from "../../react-id/dist/index.js";
const D = "DropdownMenu", [W, we] = v(D, [
  _
]), s = _(), [j, M] = W(D), q = (e) => {
  const { __scopeDropdownMenu: r, children: n, dir: o, open: t, defaultOpen: p, onOpenChange: u, modal: a = !0 } = e, f = s(r), x = m(null), [i = !1, b] = g({
    prop: t,
    defaultProp: p,
    onChange: u
  });
  return /* @__PURE__ */ c(j, {
    scope: r,
    triggerId: w(),
    triggerRef: x,
    contentId: w(),
    open: i,
    onOpenChange: b,
    onOpenToggle: C(
      () => b(
        (h) => !h
      ),
      [
        b
      ]
    ),
    modal: a
  }, /* @__PURE__ */ c(K, d({}, f, {
    open: i,
    onOpenChange: b,
    dir: o,
    modal: a
  }), n));
}, z = "DropdownMenuTrigger", B = /* @__PURE__ */ $((e, r) => {
  const { __scopeDropdownMenu: n, disabled: o = !1, ...t } = e, p = M(z, n), u = s(n);
  return /* @__PURE__ */ c(L, d({
    asChild: !0
  }, u), /* @__PURE__ */ c(I.button, d({
    type: "button",
    id: p.triggerId,
    "aria-haspopup": "menu",
    "aria-expanded": p.open,
    "aria-controls": p.open ? p.contentId : void 0,
    "data-state": p.open ? "open" : "closed",
    "data-disabled": o ? "" : void 0,
    disabled: o
  }, t, {
    ref: S(r, p.triggerRef),
    onPointerDown: l(e.onPointerDown, (a) => {
      !o && a.button === 0 && a.ctrlKey === !1 && (p.onOpenToggle(), p.open || a.preventDefault());
    }),
    onKeyDown: l(e.onKeyDown, (a) => {
      o || ([
        "Enter",
        " "
      ].includes(a.key) && p.onOpenToggle(), a.key === "ArrowDown" && p.onOpenChange(!0), [
        "Enter",
        " ",
        "ArrowDown"
      ].includes(a.key) && a.preventDefault());
    })
  })));
}), J = (e) => {
  const { __scopeDropdownMenu: r, ...n } = e, o = s(r);
  return /* @__PURE__ */ c(P, d({}, o, n));
}, Q = "DropdownMenuContent", V = /* @__PURE__ */ $((e, r) => {
  const { __scopeDropdownMenu: n, ...o } = e, t = M(Q, n), p = s(n), u = m(!1);
  return /* @__PURE__ */ c(O, d({
    id: t.contentId,
    "aria-labelledby": t.triggerId
  }, p, o, {
    ref: r,
    onCloseAutoFocus: l(e.onCloseAutoFocus, (a) => {
      var f;
      u.current || (f = t.triggerRef.current) === null || f === void 0 || f.focus(), u.current = !1, a.preventDefault();
    }),
    onInteractOutside: l(e.onInteractOutside, (a) => {
      const f = a.detail.originalEvent, x = f.button === 0 && f.ctrlKey === !0, i = f.button === 2 || x;
      (!t.modal || i) && (u.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)"
    }
  }));
}), X = /* @__PURE__ */ $((e, r) => {
  const { __scopeDropdownMenu: n, ...o } = e, t = s(n);
  return /* @__PURE__ */ c(F, d({}, t, o, {
    ref: r
  }));
}), Y = /* @__PURE__ */ $((e, r) => {
  const { __scopeDropdownMenu: n, ...o } = e, t = s(n);
  return /* @__PURE__ */ c(R, d({}, t, o, {
    ref: r
  }));
}), Z = /* @__PURE__ */ $((e, r) => {
  const { __scopeDropdownMenu: n, ...o } = e, t = s(n);
  return /* @__PURE__ */ c(y, d({}, t, o, {
    ref: r
  }));
}), ee = /* @__PURE__ */ $((e, r) => {
  const { __scopeDropdownMenu: n, ...o } = e, t = s(n);
  return /* @__PURE__ */ c(T, d({}, t, o, {
    ref: r
  }));
}), oe = /* @__PURE__ */ $((e, r) => {
  const { __scopeDropdownMenu: n, ...o } = e, t = s(n);
  return /* @__PURE__ */ c(H, d({}, t, o, {
    ref: r
  }));
}), ne = /* @__PURE__ */ $((e, r) => {
  const { __scopeDropdownMenu: n, ...o } = e, t = s(n);
  return /* @__PURE__ */ c(E, d({}, t, o, {
    ref: r
  }));
}), re = /* @__PURE__ */ $((e, r) => {
  const { __scopeDropdownMenu: n, ...o } = e, t = s(n);
  return /* @__PURE__ */ c(k, d({}, t, o, {
    ref: r
  }));
}), te = /* @__PURE__ */ $((e, r) => {
  const { __scopeDropdownMenu: n, ...o } = e, t = s(n);
  return /* @__PURE__ */ c(G, d({}, t, o, {
    ref: r
  }));
}), ae = (e) => {
  const { __scopeDropdownMenu: r, children: n, open: o, onOpenChange: t, defaultOpen: p } = e, u = s(r), [a = !1, f] = g({
    prop: o,
    defaultProp: p,
    onChange: t
  });
  return /* @__PURE__ */ c(U, d({}, u, {
    open: a,
    onOpenChange: f
  }), n);
}, ce = /* @__PURE__ */ $((e, r) => {
  const { __scopeDropdownMenu: n, ...o } = e, t = s(n);
  return /* @__PURE__ */ c(A, d({}, t, o, {
    ref: r
  }));
}), pe = /* @__PURE__ */ $((e, r) => {
  const { __scopeDropdownMenu: n, ...o } = e, t = s(n);
  return /* @__PURE__ */ c(N, d({}, t, o, {
    ref: r,
    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)"
    }
  }));
}), me = q, ge = B, _e = J, De = V, Me = X, he = Y, Ce = Z, Se = ee, ve = oe, Ie = ne, Pe = re, Oe = te, Re = ae, ye = ce, Te = pe;
export {
  Se as CheckboxItem,
  De as Content,
  q as DropdownMenu,
  ee as DropdownMenuCheckboxItem,
  V as DropdownMenuContent,
  X as DropdownMenuGroup,
  Z as DropdownMenuItem,
  re as DropdownMenuItemIndicator,
  Y as DropdownMenuLabel,
  J as DropdownMenuPortal,
  oe as DropdownMenuRadioGroup,
  ne as DropdownMenuRadioItem,
  te as DropdownMenuSeparator,
  ae as DropdownMenuSub,
  pe as DropdownMenuSubContent,
  ce as DropdownMenuSubTrigger,
  B as DropdownMenuTrigger,
  Me as Group,
  Ce as Item,
  Pe as ItemIndicator,
  he as Label,
  _e as Portal,
  ve as RadioGroup,
  Ie as RadioItem,
  me as Root,
  Oe as Separator,
  Re as Sub,
  Te as SubContent,
  ye as SubTrigger,
  ge as Trigger,
  we as createDropdownMenuScope
};
