function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
import React, { useEffect, useMemo } from 'react';
import { Dropdown, Badge } from 'antd';
import { UserOutlined } from "@ant-design/icons";
import classNames from 'classnames';
import PisellAvatar from "../pisellAvatar";
import "./index.less";
var ProfileMenu = function ProfileMenu(_ref) {
  var menuIcon = _ref.menuIcon,
    _ref$userName = _ref.userName,
    userName = _ref$userName === void 0 ? '' : _ref$userName,
    _ref$email = _ref.email,
    email = _ref$email === void 0 ? '' : _ref$email,
    _ref$isShowUserName = _ref.isShowUserName,
    isShowUserName = _ref$isShowUserName === void 0 ? true : _ref$isShowUserName,
    _ref$isShowEmail = _ref.isShowEmail,
    isShowEmail = _ref$isShowEmail === void 0 ? true : _ref$isShowEmail,
    _ref$isShowUserInfo = _ref.isShowUserInfo,
    isShowUserInfo = _ref$isShowUserInfo === void 0 ? false : _ref$isShowUserInfo,
    onClick = _ref.onClick,
    avatar = _ref.avatar,
    className = _ref.className,
    style = _ref.style,
    _ref$menuItems = _ref.menuItems,
    menuItems = _ref$menuItems === void 0 ? [] : _ref$menuItems,
    _ref$placement = _ref.placement,
    placement = _ref$placement === void 0 ? 'bottomRight' : _ref$placement,
    _ref$trigger = _ref.trigger,
    trigger = _ref$trigger === void 0 ? ['click'] : _ref$trigger,
    _ref$showBadge = _ref.showBadge,
    showBadge = _ref$showBadge === void 0 ? false : _ref$showBadge,
    _ref$badgeCount = _ref.badgeCount,
    badgeCount = _ref$badgeCount === void 0 ? 1 : _ref$badgeCount;
  useEffect(function () {
    document.body.id = 'body';
  }, []);
  var handleClick = function handleClick(e) {
    e.preventDefault();
    onClick === null || onClick === void 0 ? void 0 : onClick();
  };
  var renderAvatar = function renderAvatar(avatarProps) {
    return /*#__PURE__*/React.createElement(PisellAvatar, {
      style: {
        margin: '0 6px'
      },
      size: "md",
      src: (avatarProps === null || avatarProps === void 0 ? void 0 : avatarProps.src) || '',
      alt: (avatarProps === null || avatarProps === void 0 ? void 0 : avatarProps.alt) || '',
      icon: /*#__PURE__*/React.createElement(UserOutlined, {
        style: {
          fontSize: 24,
          color: '#475467'
        }
      })
    });
  };
  var finalMenuItems = useMemo(function () {
    if (!isShowUserInfo) return menuItems;
    var userInfoItem = {
      key: 'user-info',
      label: /*#__PURE__*/React.createElement("div", {
        className: "profile-menu-user-info-item"
      }, renderAvatar(avatar), /*#__PURE__*/React.createElement("div", {
        className: "profile-menu-user-info"
      }, userName && /*#__PURE__*/React.createElement("p", {
        className: "profile-menu-user-info-name"
      }, userName), email && /*#__PURE__*/React.createElement("p", {
        className: "profile-menu-user-info-email"
      }, email)))
    };
    return [userInfoItem, {
      type: 'divider'
    }].concat(_toConsumableArray(menuItems || []));
  }, [isShowUserInfo, menuItems, userName, email, avatar]);
  var showUserInfo = isShowUserName && userName || isShowEmail && email;
  return /*#__PURE__*/React.createElement(Dropdown, {
    menu: {
      items: finalMenuItems
    },
    placement: placement,
    trigger: trigger,
    overlayClassName: "profile-menu-dropdown"
  }, /*#__PURE__*/React.createElement("div", {
    className: classNames('profile-menu-wrap', className),
    style: _objectSpread(_objectSpread({}, style), {}, {
      paddingRight: showUserInfo ? 16 : 0
    }),
    onClick: handleClick
  }, menuIcon && /*#__PURE__*/React.createElement("div", {
    className: "profile-menu-icon"
  }, menuIcon), /*#__PURE__*/React.createElement(Badge, {
    count: showBadge ? badgeCount : 0,
    offset: [-6, 6]
  }, renderAvatar(avatar)), showUserInfo && /*#__PURE__*/React.createElement("div", {
    className: "profile-menu-user-info"
  }, isShowUserName && userName && /*#__PURE__*/React.createElement("p", {
    className: "profile-menu-user-info-name",
    title: userName
  }, userName), isShowEmail && email && /*#__PURE__*/React.createElement("p", {
    className: "profile-menu-user-info-email",
    title: email
  }, email))));
};
export default ProfileMenu;