"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CardGridSecondaryActions = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const react_2 = require("react");
const Menu_1 = require("../../Menu");
const MenuItem_1 = require("../../MenuItem");
const useBlockingActions_1 = require("../hooks/useBlockingActions");
const CardGridSecondaryActionsSkeleton_1 = require("./CardGridSecondaryActionsSkeleton");
const SecondaryActionsMenuContext_1 = require("./SecondaryActionsMenuContext");
/**
 * Компонент для отображения дополнительных действий в выпадающем меню.
 *
 * @example
 * ```tsx
 * <CardGridSecondaryActions
 *   actions={[
 *     { name: 'Дублировать', onClick: handleDuplicate },
 *     { name: 'Архивировать', onClick: handleArchive, disabled: !canArchive },
 *     { name: 'Экспортировать', onClick: handleExport }
 *   ]}
 *   isLoading={isActionsLoading}
 * />
 * ```
 */
const CardGridSecondaryActions = ({ actions, isLoading, mobileTitle, }) => {
    const { onActionClick } = (0, useBlockingActions_1.useBlockingActions)(actions);
    const { anchorEl, open } = (0, react_2.useContext)(SecondaryActionsMenuContext_1.SecondaryActionsMenuContext);
    const renderActions = () => {
        return actions?.map((action) => {
            const { onClick, name, loading, isBlockingOperation, ...restProps } = action;
            return ((0, react_1.createElement)(MenuItem_1.MenuItem, { ...restProps, key: name, tooltipPlacement: "left", onClick: onActionClick(onClick) }, name));
        });
    };
    return ((0, jsx_runtime_1.jsx)(Menu_1.Menu, { open: open, title: mobileTitle, anchorEl: anchorEl, anchorOrigin: { vertical: 'bottom', horizontal: 'right' }, transformOrigin: { vertical: 'top', horizontal: 'right' }, children: isLoading ? (0, jsx_runtime_1.jsx)(CardGridSecondaryActionsSkeleton_1.CardGridSecondaryActionsSkeleton, {}) : renderActions() }));
};
exports.CardGridSecondaryActions = CardGridSecondaryActions;
