import {
  CurrentProfileMenu_default
} from "./chunk-ZHR3K6NM.mjs";
import {
  MenuItems_default
} from "./chunk-3NAERPFL.mjs";
import {
  CurrentUser_default
} from "./chunk-O2URELIU.mjs";
import {
  LogoutItem_default
} from "./chunk-65DTYIWW.mjs";
import {
  PopoverStyles
} from "./chunk-FLXSZXMF.mjs";
import {
  CurrentProfile_default
} from "./chunk-NH7KZ2QM.mjs";
import {
  ProfilesList_default
} from "./chunk-4M7SXVJD.mjs";
import {
  SwitchProfileMenu_default
} from "./chunk-CE2ARI5I.mjs";
import {
  AddProfileMenuItem_default
} from "./chunk-QOREC33F.mjs";

// tmp-babel/navigations/web/Header/AccountMenu/AccountPopover/index.js
import { useEffect, useState } from "react";
import { useCurrentProfile } from "@baseapp-frontend/authentication";
import { ClickableAvatar } from "@baseapp-frontend/design-system/components/web/avatars";
import { Popover } from "@baseapp-frontend/design-system/components/web/popovers";
import { usePopover } from "@baseapp-frontend/design-system/hooks/common";
import { Box } from "@mui/material";
import Divider from "@mui/material/Divider";
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
function _typeof(o) {
  "@babel/helpers - typeof";
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o2) {
    return typeof o2;
  } : function(o2) {
    return o2 && "function" == typeof Symbol && o2.constructor === Symbol && o2 !== Symbol.prototype ? "symbol" : typeof o2;
  }, _typeof(o);
}
function ownKeys(e, r) {
  var t = Object.keys(e);
  if (Object.getOwnPropertySymbols) {
    var o = Object.getOwnPropertySymbols(e);
    r && (o = o.filter(function(r2) {
      return Object.getOwnPropertyDescriptor(e, r2).enumerable;
    })), t.push.apply(t, o);
  }
  return t;
}
function _objectSpread(e) {
  for (var r = 1; r < arguments.length; r++) {
    var t = null != arguments[r] ? arguments[r] : {};
    r % 2 ? ownKeys(Object(t), true).forEach(function(r2) {
      _defineProperty(e, r2, t[r2]);
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r2) {
      Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2));
    });
  }
  return e;
}
function _defineProperty(e, r, t) {
  return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e;
}
function _toPropertyKey(t) {
  var i = _toPrimitive(t, "string");
  return "symbol" == _typeof(i) ? i : i + "";
}
function _toPrimitive(t, r) {
  if ("object" != _typeof(t) || !t) return t;
  var e = t[Symbol.toPrimitive];
  if (void 0 !== e) {
    var i = e.call(t, r || "default");
    if ("object" != _typeof(i)) return i;
    throw new TypeError("@@toPrimitive must return a primitive value.");
  }
  return ("string" === r ? String : Number)(t);
}
function _slicedToArray(r, e) {
  return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
}
function _nonIterableRest() {
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _unsupportedIterableToArray(r, a) {
  if (r) {
    if ("string" == typeof r) return _arrayLikeToArray(r, a);
    var t = {}.toString.call(r).slice(8, -1);
    return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
  }
}
function _arrayLikeToArray(r, a) {
  (null == a || a > r.length) && (a = r.length);
  for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
  return n;
}
function _iterableToArrayLimit(r, l) {
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
  if (null != t) {
    var e, n, i, u, a = [], f = true, o = false;
    try {
      if (i = (t = t.call(r)).next, 0 === l) {
        if (Object(t) !== t) return;
        f = false;
      } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = true) ;
    } catch (r2) {
      o = true, n = r2;
    } finally {
      try {
        if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return;
      } finally {
        if (o) throw n;
      }
    }
    return a;
  }
}
function _arrayWithHoles(r) {
  if (Array.isArray(r)) return r;
}
var AccountPopover = function AccountPopover2(_ref) {
  var _profile$image;
  var _ref$PopoverStyles = _ref.PopoverStyles, PopoverStyles2 = _ref$PopoverStyles === void 0 ? {} : _ref$PopoverStyles, _ref$MenuItems = _ref.MenuItems, MenuItems = _ref$MenuItems === void 0 ? MenuItems_default : _ref$MenuItems, _ref$MenuItemsProps = _ref.MenuItemsProps, MenuItemsProps = _ref$MenuItemsProps === void 0 ? {} : _ref$MenuItemsProps, _ref$CurrentUser = _ref.CurrentUser, CurrentUser = _ref$CurrentUser === void 0 ? CurrentUser_default : _ref$CurrentUser, _ref$CurrentProfile = _ref.CurrentProfile, CurrentProfile = _ref$CurrentProfile === void 0 ? CurrentProfile_default : _ref$CurrentProfile, _ref$SwitchProfileMen = _ref.SwitchProfileMenu, SwitchProfileMenu = _ref$SwitchProfileMen === void 0 ? SwitchProfileMenu_default : _ref$SwitchProfileMen, _ref$SwitchProfileMen2 = _ref.SwitchProfileMenuProps, SwitchProfileMenuProps = _ref$SwitchProfileMen2 === void 0 ? {} : _ref$SwitchProfileMen2, _ref$ProfilesList = _ref.ProfilesList, ProfilesList = _ref$ProfilesList === void 0 ? ProfilesList_default : _ref$ProfilesList, _ref$ProfilesListProp = _ref.ProfilesListProps, ProfilesListProps = _ref$ProfilesListProp === void 0 ? {} : _ref$ProfilesListProp, _ref$AddProfileMenuIt = _ref.AddProfileMenuItem, AddProfileMenuItem = _ref$AddProfileMenuIt === void 0 ? AddProfileMenuItem_default : _ref$AddProfileMenuIt, _ref$AddProfileMenuIt2 = _ref.AddProfileMenuItemProps, AddProfileMenuItemProps = _ref$AddProfileMenuIt2 === void 0 ? {} : _ref$AddProfileMenuIt2, _ref$LogoutItemProps = _ref.LogoutItemProps, LogoutItemProps = _ref$LogoutItemProps === void 0 ? {} : _ref$LogoutItemProps;
  var _useCurrentProfile = useCurrentProfile(), profile = _useCurrentProfile.currentProfile;
  var popover = usePopover();
  var _useState = useState(false), _useState2 = _slicedToArray(_useState, 2), openProfilesList = _useState2[0], setOpenProfilesList = _useState2[1];
  var timeoutId = null;
  var handlePopoverOnClose = function handlePopoverOnClose2() {
    popover.onClose();
    if (openProfilesList) {
      timeoutId = setTimeout(function() {
        setOpenProfilesList(false);
      }, 500);
    }
  };
  useEffect(function() {
    return function() {
      if (timeoutId) {
        clearTimeout(timeoutId);
      }
    };
  }, [timeoutId]);
  return /* @__PURE__ */ _jsxs(_Fragment, {
    children: [/* @__PURE__ */ _jsx(ClickableAvatar, {
      color: "secondary",
      src: (_profile$image = profile === null || profile === void 0 ? void 0 : profile.image) !== null && _profile$image !== void 0 ? _profile$image : "",
      alt: "User avatar",
      onClick: popover.onOpen,
      isOpen: !!popover.open
    }), /* @__PURE__ */ _jsxs(Popover, {
      open: popover.open,
      onClose: handlePopoverOnClose,
      sx: _objectSpread(_objectSpread({}, PopoverStyles), PopoverStyles2),
      children: [!!ProfilesList && openProfilesList ? /* @__PURE__ */ _jsx(ProfilesList, _objectSpread({
        openSubmenu: openProfilesList,
        handleCloseSubmenu: function handleCloseSubmenu() {
          return setOpenProfilesList(false);
        }
      }, ProfilesListProps)) : /* @__PURE__ */ _jsx(CurrentProfileMenu_default, {
        CurrentUser,
        CurrentProfile,
        SwitchProfileMenu,
        SwitchProfileMenuProps,
        MenuItems,
        MenuItemsProps,
        handlePopoverOnClose,
        setOpenProfilesList
      }), Boolean(LogoutItem_default) && /* @__PURE__ */ _jsx(Divider, {
        sx: {
          borderStyle: "solid"
        }
      }), /* @__PURE__ */ _jsxs(Box, {
        margin: 1.5,
        display: "flex",
        flexDirection: "column",
        gap: 0.5,
        children: [openProfilesList && Boolean(AddProfileMenuItem) && /* @__PURE__ */ _jsx(AddProfileMenuItem_default, _objectSpread({}, AddProfileMenuItemProps)), /* @__PURE__ */ _jsx(LogoutItem_default, _objectSpread({
          handlePopoverOnClose
        }, LogoutItemProps))]
      })]
    })]
  });
};
var AccountPopover_default = AccountPopover;

export {
  AccountPopover_default
};
//# sourceMappingURL=chunk-B4O6UXDL.mjs.map