import { jsxs as s, Fragment as I, jsx as e } from "react/jsx-runtime";
import { useState as P, useRef as b, createElement as A, isValidElement as E } from "react";
import { ExpandMore as L } from "@mui/icons-material";
import { ButtonGroup as S, Popper as w, MenuItem as p, Button as c, Paper as z, ClickAwayListener as j, MenuList as G } from "@mui/material";
import R from "lodash/noop";
import { styled as d } from "../Theme/index.js";
function v({ ...o }) {
  const {
    size: m = "medium",
    color: r = "primary",
    menu: i = [],
    children: l = null,
    variant: u = "contained",
    onClick: f = R,
    menuButtonProps: h = {},
    ...g
  } = o, [y, a] = P(!1), n = b(null), x = Array.isArray(i) ? (
    // eslint-disable-next-line react/no-array-index-key
    i.map((t, C) => E(t) ? t : /* @__PURE__ */ A(p, { ...t, key: C }))
  ) : i, M = () => {
    a((t) => !t);
  }, k = (t) => {
    n.current && n.current.contains(t.target) || a(!1);
  }, B = (t) => {
    t.target.closest(".MuiMenuItem-root") && a(!1);
  };
  return /* @__PURE__ */ s(I, { children: [
    /* @__PURE__ */ s(F, { variant: u, size: m, color: r, ref: n, ...g, children: [
      typeof l == "function" ? l() : /* @__PURE__ */ e(c, { onClick: f, color: r, children: l }),
      /* @__PURE__ */ e(c, { onClick: M, color: r, ...h, "aria-label": "more functions", children: /* @__PURE__ */ e(L, {}) })
    ] }),
    /* @__PURE__ */ e(O, { open: y, anchorEl: n.current, placement: "bottom-end", disablePortal: !1, children: /* @__PURE__ */ e(z, { children: /* @__PURE__ */ e(j, { onClickAway: k, children: /* @__PURE__ */ e(G, { onClick: B, children: x }) }) }) })
  ] });
}
v.Item = p;
const F = d(S)`
  > .MuiButtonBase-root:last-of-type {
    min-width: 2em;
    padding-left: 0;
    padding-right: 0;
  }
`, O = d(w)`
  z-index: ${(o) => o.theme.zIndex.tooltip};
  .MuiList-root {
    padding: 4px 0;
  }
  .MuiListItem-root {
    padding-top: 4px;
    padding-bottom: 4px;
  }
`;
export {
  v as default
};
