import { jsxs as a, jsx as e, Fragment as C } from "@emotion/react/jsx-runtime";
import { useEnvironment as O, useModuleDictionary as x } from "@m4l/core";
import { TEST_PROP_ID as A } from "../../../../test/constants_no_mock.js";
import { PATH_VERSION as P, PATH_CONFIGURATION as D, PATH_SIGN_OFF as E } from "../../constants.js";
import { PopoverStyled as T, UserDataContainerStyled as M, AvatarPopoverStyled as W, UserNameEmailStyled as F, FullNametStyled as H, EmailtStyled as V, VersionContainerStyled as z, VersionStyled as L, VersionIconStyled as U, DividerStyled as $, CircularProgressStyled as R, MenuItemSettingsStyled as j, MenuItemStyled as G, MenuItemLogoutStyled as B } from "../../slots/AccountPopoverSlots.js";
import { getNameDataTestId as q } from "../../tests/utils.js";
import w from "../MyAvatar/MyAvatar.js";
import { useTheme as J } from "@mui/material";
const ae = (g) => {
  const {
    version: h,
    handleClose: l,
    anchorEl: r,
    userData: u,
    settingsHandleOpen: v,
    handleLogOut: y,
    itemHandleClick: S,
    data: i = [],
    asyncState: _,
    size: b
  } = g, { host_static_assets: s, environment_assets: c } = O(), { firstName: d, lastName: m, email: p, avatarUrl: f } = u || {}, { getLabel: o } = x(), n = J().size.baseSpacings.sp2, I = (t) => {
    S(t), l();
  }, N = () => {
    l(), v();
  }, k = () => {
    y(), l();
  };
  return r ? /* @__PURE__ */ a(
    T,
    {
      size: b,
      open: !!r,
      anchorEl: r,
      onClose: l,
      anchorOrigin: { vertical: "bottom", horizontal: "right" },
      transformOrigin: { vertical: "top", horizontal: "right" },
      ...process.env.NODE_ENV !== "production" ? { [A]: q("popover") } : {},
      children: [
        /* @__PURE__ */ a(M, { children: [
          /* @__PURE__ */ e(w, { avatarUrl: f, firstName: d || "first name", lastName: m || "last name", slotAvatar: W }),
          /* @__PURE__ */ a(F, { children: [
            /* @__PURE__ */ e(H, { variant: "paragraphDens", skeletonWidth: `calc(${`${d} ${m}`.length}ex + ${n})`, children: `${d} ${m}` }),
            /* @__PURE__ */ e(V, { variant: "bodyStandard", skeletonWidth: `calc(${p?.length}ex + ${n})`, children: p })
          ] })
        ] }),
        /* @__PURE__ */ a(z, { children: [
          /* @__PURE__ */ e(L, { variant: "bodyStandard", skeletonWidth: `calc(${h.length}ex + ${n})`, children: `${o("account_popover.label_version")} ${h}` }),
          /* @__PURE__ */ e(U, { src: `${s}/${c}/${P}` })
        ] }),
        /* @__PURE__ */ e($, {}),
        _ === "loading" ? /* @__PURE__ */ e(R, {}) : /* @__PURE__ */ a(C, { children: [
          /* @__PURE__ */ e(j, { skeletonWidth: `calc(${o("account_popover.label_settings").length}ex + ${n})`, onClick: N, label: o("account_popover.label_settings"), endIcon: `${s}/${c}/${D}` }),
          Array.isArray(i) && i.length > 0 && i.map((t) => /* @__PURE__ */ e(G, { variant: "body", skeletonWidth: `calc(${t.title.length}ex + ${n})`, onClick: () => I(t), label: t.title }, `${t.title}-${t.module_id}`)),
          /* @__PURE__ */ e($, {})
        ] }),
        /* @__PURE__ */ e(B, { variant: "body", skeletonWidth: `calc(${o("account_popover.label_logout").length}ex + ${n})`, onClick: k, label: o("account_popover.label_logout"), endIcon: `${s}/${c}/${E}` })
      ]
    }
  ) : null;
};
export {
  ae as MenuPopover
};
