import { jsxs as u, Fragment as f, jsx as r } from "react/jsx-runtime";
import { useRef as m } from "react";
import { Box as x, Menu as l, MenuItem as d } from "@mui/material";
import { useReactive as h } from "ahooks";
import { mergeSx as P } from "@arcblock/ux/lib/Util/style";
import t from "prop-types";
import { AppInfoItem as A } from "@arcblock/ux/lib/DIDConnect";
import { useStateContext as y } from "../contexts/state.js";
function S({ sx: s = {}, children: i }) {
  const { appInfoList: p, extraParams: c, connectState: a } = y(), n = m(null), e = h({
    open: !1
  });
  return p.length <= 1 ? null : /* @__PURE__ */ u(f, { children: [
    /* @__PURE__ */ r(
      x,
      {
        component: "span",
        ref: n,
        sx: P(
          {
            color: "text.secondary",
            cursor: "pointer"
          },
          s
        ),
        onClick: () => {
          e.open = !0;
        },
        children: i
      }
    ),
    /* @__PURE__ */ r(
      l,
      {
        anchorEl: n.current,
        open: e.open,
        onClose: () => {
          e.open = !1;
        },
        slotProps: {
          paper: {
            variant: "outlined",
            sx: {
              border: 0,
              boxShadow: ({ palette: o }) => `0px 4px 8px 0px ${o.grey[100]}, 0px 0px 0px 1px ${o.grey[100]}`,
              borderRadius: 1
            }
          }
        },
        children: p.map((o) => /* @__PURE__ */ r(
          d,
          {
            onClick: () => {
              e.open = !1, a.sourceAppPid = o.sourceAppPid;
            },
            children: /* @__PURE__ */ r(A, { appInfo: o, active: o.sourceAppPid === c?.sourceAppPid })
          },
          o.appPid
        ))
      }
    )
  ] });
}
S.propTypes = {
  sx: t.object,
  children: t.any.isRequired
};
export {
  S as default
};
