import { jsx as p, jsxs as v } from "react/jsx-runtime";
import M, { useMemo as o, useState as j, useCallback as c } from "react";
import { DropdownMenu as x, DropdownMenuTrigger as y, DropdownMenuContent as J } from "../dropdown/DropdownPrimitives.js";
import L from "./utils/mapPositionToAlign.js";
import $ from "./components/jtl-dropdown-menu-item/JTLDropdownMenuItem.js";
import { c as E } from "../../index-BtlgVD4m.js";
import "./types/DropdownItem.js";
const N = ({ isOpen: n, defaultOpen: f = !1, position: i = "center", onClose: r, menuItems: s, children: a, width: l }) => {
  const g = o(() => L(i), [i]), d = o(() => M.isValidElement(a) ? a.props.disabled === !0 : !1, [a]), [w, m] = j(f), e = o(() => n !== void 0 && r !== void 0, [n, r]), u = c(() => {
    e ? r == null || r() : m(!1);
  }, [e, r]), D = e ? n : w, b = c(
    (t) => {
      t && d || (e ? t || r == null || r() : m(t));
    },
    [e, d, r]
  ), T = o(() => s.map((t, h) => /* @__PURE__ */ p($, { ...t, onClose: u }, `${t.type}-${t.label}-${h}`)), [s, u]);
  return /* @__PURE__ */ v(x, { open: D, onOpenChange: b, children: [
    /* @__PURE__ */ p(y, { asChild: !0, disabled: d, children: a }),
    /* @__PURE__ */ p(
      J,
      {
        align: g,
        loop: !0,
        style: { "--jtl-dropdown-content-width": l },
        className: E("w-full", "rounded-[var(--border-radius-md)] p-[var(--spacing-1)]", l && "w-[var(--jtl-dropdown-content-width)]"),
        children: T
      }
    )
  ] });
};
N.displayName = "JTLDropdown";
export {
  N as default
};
//# sourceMappingURL=JTLDropdown.js.map
