import { jsxs as s, jsx as e } from "react/jsx-runtime";
import { useRef as y } from "react";
import { useTheme as R, Box as p, IconButton as k, Popper as w, ClickAwayListener as C, Fade as P, Paper as L, List as z, ListItem as A, ListItemButton as M, Typography as S } from "@mui/material";
import { Icon as u } from "@iconify/react";
import T from "iconify-icons-material-symbols-400/dashboard-outline-rounded";
import B from "@iconify-icons/material-symbols/widgets-outline-rounded";
import { useReactive as E, useMemoizedFn as j } from "ahooks";
import F from "../Button/index.js";
import { BLOCKLET_SERVICE_PATH_PREFIX as O, NAVIGATION_URL as _ } from "../Util/constant.js";
import D from "../SessionPermission/index.js";
import { getTranslation as m } from "../Util/index.js";
function J({
  session: r,
  locale: i = "zh",
  size: f = 24,
  popperType: h = "click",
  sx: g,
  ...x
}) {
  const c = window?.blocklet || {}, a = (c.navigation || []).filter((n) => n.section === "sessionManager" && !["/sessionManager"].includes(n.id)).filter((n) => !!(n?.role || []).includes(r?.user?.role || "guest")).map((n) => {
    const o = (c?.componentMountPoints || []).find((v) => n.component === v.name);
    return {
      ...n,
      component: o
    };
  }), b = R(), d = y(null), l = E({
    open: !1
  }), t = j((n = !l.open) => {
    l.open = n;
  }), I = h === "hover" ? { onMouseEnter: () => t(!0), onMouseLeave: () => t(!1) } : { onClick: () => t() };
  return a.length === 0 || !r?.user ? null : /* @__PURE__ */ s(
    p,
    {
      sx: { display: "inline-flex", alignItems: "center", justifyContent: "center", ...g },
      ...x,
      ...I,
      children: [
        /* @__PURE__ */ e(k, { size: "medium", ref: d, children: /* @__PURE__ */ e(u, { icon: T, fontSize: f, style: { transform: "scale(1.08)" } }) }),
        /* @__PURE__ */ e(
          w,
          {
            open: l.open,
            anchorEl: d.current,
            transition: !0,
            placement: "bottom-end",
            sx: { zIndex: 1600 },
            children: ({ TransitionProps: n }) => /* @__PURE__ */ e(
              C,
              {
                onClickAway: (o) => {
                  o.preventDefault(), o.stopPropagation(), t(!1);
                },
                children: /* @__PURE__ */ e(P, { ...n, timeout: 350, children: /* @__PURE__ */ s(
                  L,
                  {
                    variant: "outlined",
                    sx: {
                      borderRadius: 1.5,
                      width: 350,
                      maxWidth: "90vw",
                      p: 2
                    },
                    children: [
                      /* @__PURE__ */ e(
                        z,
                        {
                          sx: {
                            display: "grid",
                            gridTemplateColumns: "repeat(auto-fill, 100px)",
                            gridAutoRows: "minmax(100px, max-content)",
                            justifyContent: "space-between",
                            maxHeight: 350,
                            overflowY: "auto",
                            p: 0
                          },
                          children: a.map((o) => /* @__PURE__ */ e(A, { disablePadding: !0, children: /* @__PURE__ */ s(
                            M,
                            {
                              href: m(o.link, i),
                              sx: {
                                p: 1,
                                display: "flex",
                                flexDirection: "column",
                                alignItems: "center",
                                gap: 1,
                                width: "100%",
                                height: "100%",
                                borderRadius: 1,
                                "&:hover": {
                                  backgroundColor: "action.hover"
                                }
                              },
                              children: [
                                o?.component?.did ? /* @__PURE__ */ e(
                                  p,
                                  {
                                    component: "img",
                                    src: `${O}/blocklet/logo-bundle/${o.component.did}`,
                                    sx: {
                                      borderRadius: 1,
                                      width: 50,
                                      height: 50,
                                      objectFit: "contain"
                                    },
                                    alt: "SessionBlocklet component icon"
                                  }
                                ) : /* @__PURE__ */ e(
                                  u,
                                  {
                                    fontSize: 50,
                                    icon: o.icon || B,
                                    color: b.palette.text.secondary
                                  }
                                ),
                                /* @__PURE__ */ e(
                                  S,
                                  {
                                    sx: {
                                      fontSize: "12px",
                                      color: "text.primary",
                                      textAlign: "center",
                                      lineHeight: "normal"
                                    },
                                    children: m(o.title, i)
                                  }
                                )
                              ]
                            }
                          ) }, o.id))
                        }
                      ),
                      /* @__PURE__ */ e(D, { session: r, children: /* @__PURE__ */ e(F, { variant: "outlined", fullWidth: !0, href: _, sx: { mt: 1 }, children: i === "zh" ? "管理" : "Manage" }) })
                    ]
                  }
                ) })
              }
            )
          }
        )
      ]
    }
  );
}
export {
  J as default
};
