import { jsxs as T, Fragment as w, jsx as s } from "@emotion/react/jsx-runtime";
import { useNetwork as x } from "@m4l/core";
import { useState as c, useEffect as D, useCallback as u } from "react";
import { MenuPopover as M } from "./subcomponents/MenuPopover/MenuPopover.js";
import { ACCOUNT_KEY_POPOVER as R } from "./constants.js";
import { IconButtonRootStyled as U, AvatarStyled as _ } from "./slots/AccountPopoverSlots.js";
import j from "./subcomponents/MyAvatar/MyAvatar.js";
import { getComponentClasses as B } from "../../utils/getComponentSlotRoot.js";
import { AccountPopoverSlots as H } from "./slots/AccountPopoverEnum.js";
import { useComponentSize as b } from "../../hooks/useComponentSize/index.js";
const X = (p) => {
  const {
    anchorOrigin: d,
    transformOrigin: f,
    itemHandleClick: C,
    version: h,
    handleLogOut: O,
    userData: i,
    settingsHandleOpen: S,
    size: g
  } = p, { avatarUrl: v, firstName: A = "firstname", lastName: z = "lastname" } = i || {}, [m, n] = c("unLoad"), [t, e] = c(null), [E, l] = c([]), { networkOperation: P } = x(), { currentSize: r } = b(g), k = {
    size: r
  };
  D(() => {
    let o = !0;
    return m === "unLoad" && (n("loading"), P({
      method: "GET",
      responseToCamelCase: !0,
      endPoint: "menus",
      parms: {
        position: 1
      }
    }).then((a) => {
      o && (n("loaded"), l(a.data));
    }).catch((a) => {
      n("unLoad"), l([]);
    })), function() {
      o = !1;
    };
  }, [t]);
  const y = u(() => {
    e(null);
  }, [e]), N = u((o) => {
    e(o.currentTarget);
  }, [e]), L = B(R, H);
  return /* @__PURE__ */ T(w, { children: [
    /* @__PURE__ */ s(
      U,
      {
        ownerState: k,
        icon: /* @__PURE__ */ s(j, { size: r, avatarUrl: v, firstName: A, lastName: z, slotAvatar: _ }),
        src: "",
        onClick: N,
        selected: !!t,
        className: L.iconButtonRoot
      }
    ),
    !!t && /* @__PURE__ */ s(
      M,
      {
        size: r,
        data: E,
        asyncState: m,
        itemHandleClick: C,
        version: h,
        handleLogOut: O,
        userData: i,
        settingsHandleOpen: S,
        anchorOrigin: d,
        transformOrigin: f,
        anchorEl: t,
        handleClose: y
      }
    )
  ] });
};
export {
  X as AccountPopover
};
