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