import { jsx as _jsx } from "react/jsx-runtime";
import { createElement as _createElement } from "react";
import { useContext } from 'react';
import { Menu } from '../../Menu';
import { MenuItem } from '../../MenuItem';
import { useBlockingActions } from '../hooks/useBlockingActions';
import { CardGridSecondaryActionsSkeleton } from './CardGridSecondaryActionsSkeleton';
import { SecondaryActionsMenuContext } from './SecondaryActionsMenuContext';
/**
 * Компонент для отображения дополнительных действий в выпадающем меню.
 *
 * @example
 * ```tsx
 * <CardGridSecondaryActions
 *   actions={[
 *     { name: 'Дублировать', onClick: handleDuplicate },
 *     { name: 'Архивировать', onClick: handleArchive, disabled: !canArchive },
 *     { name: 'Экспортировать', onClick: handleExport }
 *   ]}
 *   isLoading={isActionsLoading}
 * />
 * ```
 */
export const CardGridSecondaryActions = ({ actions, isLoading, mobileTitle, }) => {
    const { onActionClick } = useBlockingActions(actions);
    const { anchorEl, open } = useContext(SecondaryActionsMenuContext);
    const renderActions = () => {
        return actions?.map((action) => {
            const { onClick, name, loading, isBlockingOperation, ...restProps } = action;
            return (_createElement(MenuItem, { ...restProps, key: name, tooltipPlacement: "left", onClick: onActionClick(onClick) }, name));
        });
    };
    return (_jsx(Menu, { open: open, title: mobileTitle, anchorEl: anchorEl, anchorOrigin: { vertical: 'bottom', horizontal: 'right' }, transformOrigin: { vertical: 'top', horizontal: 'right' }, children: isLoading ? _jsx(CardGridSecondaryActionsSkeleton, {}) : renderActions() }));
};
