import { jsx as e, jsxs as b } from "react/jsx-runtime";
import f, { useCallback as D } from "react";
import { DropdownMenuItem as w, DropdownMenuCheckboxItem as C, DropdownMenuLabel as k, DropdownMenuSeparator as L, DropdownMenuSub as T, DropdownMenuSubTrigger as J, DropdownMenuSubContent as x } from "../../../dropdown/DropdownPrimitives.js";
import y from "../jtl-dropdown-menu-icon/JTLDropdownMenuIcon.js";
import I from "../jtl-dropdown-menu-shortcut/JTLDropdownMenuShortcut.js";
import { c as v } from "../../../../index-BtlgVD4m.js";
import o from "../../types/DropdownItem.js";
import h from "../jtl-dropdown-default-menu-item/JTLDropdownDefaultMenuItem.js";
const M = f.memo((l) => {
  const { type: n, label: t, icon: i, shortcut: c, onClick: r, isDisabled: a, children: p, isSelected: d, onClose: u } = l, s = D(
    (m) => {
      m.stopPropagation(), r == null || r(), n !== o.SubMenuTrigger && n !== o.Label && n !== o.Separator && n !== o.Checkbox && (u == null || u());
    },
    [r, u, n]
  ), g = D(() => {
    r == null || r();
  }, [r]);
  switch (n) {
    case o.Default:
      return /* @__PURE__ */ e(h, { label: t, icon: i, shortcut: c, isDisabled: a, onClick: s });
    case o.Danger:
      return /* @__PURE__ */ e(h, { label: t, icon: i, shortcut: c, isDisabled: a, isDanger: !0, onClick: s });
    case o.Separator:
      return /* @__PURE__ */ e(L, {});
    case o.Label:
      return /* @__PURE__ */ e(k, { children: t });
    case o.Checkbox:
      return (
        // onCheckedChange is the correct Radix API — fires for both mouse and keyboard activation.
        // onSelect is overridden to prevent the default dismiss behaviour so that the user can
        // toggle multiple checkboxes without the dropdown closing after each interaction.
        /* @__PURE__ */ e(
          C,
          {
            checked: d,
            disabled: a,
            onCheckedChange: g,
            onSelect: (m) => m.preventDefault(),
            children: t
          }
        )
      );
    case o.SubMenuTrigger:
      return /* @__PURE__ */ e(
        S,
        {
          label: t,
          icon: i,
          shortcut: c,
          isDisabled: a,
          onClick: s,
          children: p,
          onClose: u
        }
      );
    default:
      return /* @__PURE__ */ e(w, { disabled: !0, children: t });
  }
});
M.displayName = "JTLDropdownMenuItem";
const S = f.memo((l) => {
  const { label: n, icon: t, shortcut: i, isDisabled: c, onClick: r, children: a, onClose: p } = l;
  return !a || a.length === 0 ? /* @__PURE__ */ e(w, { disabled: !0, children: n }) : /* @__PURE__ */ b(T, { children: [
    /* @__PURE__ */ b(
      J,
      {
        onClick: c ? void 0 : r,
        disabled: c,
        className: v(c && "opacity-[var(--opacity-opacity-50)]"),
        children: [
          /* @__PURE__ */ e(y, { icon: t }),
          n,
          /* @__PURE__ */ e(I, { shortcut: i })
        ]
      }
    ),
    /* @__PURE__ */ e(x, { children: a.map((d, u) => /* @__PURE__ */ e(M, { ...d, onClose: p }, `${d.type}-${d.label}-${u}`)) })
  ] });
});
S.displayName = "JTLDropDownSubMenuItem";
export {
  S as J,
  M as default
};
//# sourceMappingURL=JTLDropdownMenuItem.js.map
