"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MenuList = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const QuitOutlineMd_1 = require("../../../icons/QuitOutlineMd");
const BottomDrawer_1 = require("../../BottomDrawer");
const CopyTypography_1 = require("../../CopyTypography");
const Divider_1 = require("../../Divider");
const ListItemIcon_1 = require("../../ListItemIcon");
const ListItemText_1 = require("../../ListItemText");
const MenuItem_1 = require("../../MenuItem");
const OverflowTypography_1 = require("../../OverflowTypography");
const useViewportType_1 = require("../../useViewportType");
const constants_1 = require("../constants");
const styles_1 = require("./styles");
/**
 * Компонент для рендера menu с помощью массива данных
 */
const MenuList = (props) => {
    const { open, onClose, menuList, exitButton, displayName, annotation, ...restProps } = props;
    const { isMobile } = (0, useViewportType_1.useViewportType)();
    const renderMenuList = () => {
        const items = [];
        items.push((0, jsx_runtime_1.jsxs)(styles_1.DisplayNameMenuItem, { children: [(0, jsx_runtime_1.jsx)(CopyTypography_1.CopyTypography, { noWrap: true, isShowCopyText: true, copyText: displayName, showCopyIcon: "onHover", isOverflow: true, children: displayName }), annotation && ((0, jsx_runtime_1.jsx)(CopyTypography_1.CopyTypography, { variant: "caption", color: "grey", colorIntensity: "700", noWrap: true, isShowCopyText: true, showCopyIcon: "onHover", copyText: annotation, isOverflow: true, children: annotation }))] }, "displayName"));
        items.push((0, jsx_runtime_1.jsx)(styles_1.StyledDivider, {}, "divider"));
        // Добавляем элементы меню
        if (menuList) {
            items.push(...menuList.map(({ render, icon, title, onClick }) => render ? (render({ icon, title, onClick })) : ((0, jsx_runtime_1.jsxs)(MenuItem_1.MenuItem, { onClick: onClick, children: [icon && (0, jsx_runtime_1.jsx)(ListItemIcon_1.ListItemIcon, { children: icon }), (0, jsx_runtime_1.jsx)(ListItemText_1.ListItemText, { children: (0, jsx_runtime_1.jsx)(OverflowTypography_1.OverflowTypography, { noWrap: true, children: title }) })] }, `menu-item-${title}`))));
        }
        // Добавляем разделитель если есть кнопка выхода и есть элементы menuList до кнопки выхода
        if (exitButton && menuList) {
            items.push((0, jsx_runtime_1.jsx)(Divider_1.Divider, {}, "divider"));
        }
        items.push((0, jsx_runtime_1.jsxs)(styles_1.ExitMenuItem, { "$exitButton": Boolean(exitButton), onClick: exitButton?.onClick, children: [(0, jsx_runtime_1.jsx)(ListItemIcon_1.ListItemIcon, { children: (0, jsx_runtime_1.jsx)(QuitOutlineMd_1.QuitOutlineMd, {}) }), (0, jsx_runtime_1.jsx)(ListItemText_1.ListItemText, { children: (0, jsx_runtime_1.jsx)(OverflowTypography_1.OverflowTypography, { noWrap: true, children: "\u0412\u044B\u0439\u0442\u0438" }) })] }, "exit"));
        return items;
    };
    if (isMobile) {
        return ((0, jsx_runtime_1.jsx)(BottomDrawer_1.BottomDrawer, { id: constants_1.PROFILE_POPOVER_ID, title: displayName, onClose: onClose, open: open, children: (0, jsx_runtime_1.jsx)(styles_1.StyledMenuList, { children: renderMenuList() }) }));
    }
    return ((0, jsx_runtime_1.jsx)(styles_1.StyledMenu, { MenuListProps: { id: constants_1.PROFILE_POPOVER_ID }, open: open, onClose: onClose, ...restProps, children: renderMenuList() }));
};
exports.MenuList = MenuList;
