import { _objectSpread2 } from "../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import PisellAvatar from "../pisellAvatar/index.js";
import React, { useEffect, useMemo } from "react";
import { Badge, Dropdown } from "antd";
import { UserOutlined } from "@ant-design/icons";
import classNames from "classnames";
import "./index.less";
//#region src/components/profileMenu/index.tsx
const ProfileMenu = ({ menuIcon, userName = "", email = "", isShowUserName = true, isShowEmail = true, isShowUserInfo = false, onClick, avatar, className, style, menuItems = [], placement = "bottomRight", trigger = ["click"], showBadge = false, badgeCount = 1 }) => {
	useEffect(() => {
		document.body.id = "body";
	}, []);
	const handleClick = (e) => {
		e.preventDefault();
		onClick === null || onClick === void 0 || onClick();
	};
	const renderAvatar = (avatarProps) => /* @__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"
		} })
	});
	const finalMenuItems = useMemo(() => {
		if (!isShowUserInfo) return menuItems;
		return [
			{
				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)))
			},
			{ type: "divider" },
			...menuItems || []
		];
	}, [
		isShowUserInfo,
		menuItems,
		userName,
		email,
		avatar
	]);
	const showUserInfo = isShowUserName && userName || isShowEmail && email;
	return /* @__PURE__ */ React.createElement(Dropdown, {
		menu: { items: finalMenuItems },
		placement,
		trigger,
		overlayClassName: "profile-menu-dropdown"
	}, /* @__PURE__ */ React.createElement("div", {
		className: classNames("profile-menu-wrap", className),
		style: _objectSpread2(_objectSpread2({}, 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))));
};
//#endregion
export { ProfileMenu as default };
