import { TableActionCell } from '@wix/design-system';
import React, { useEffect } from 'react';
import { observer } from 'mobx-react-lite';
import { MessageActionModal } from '../ActionModal';
import { useToolbarCollectionContext } from '../ToolbarCollectionContext';
import { createPrimaryActionCellPropsWithBI, createSecondaryActionCellPropWithBi, reportOnPopoverMenuShow, } from './CollectionItemActionsHelper';
import { getDefaultActionCellProps } from './getDefaultActionCellProps';
import { useExtensionMenuItems } from '../../hooks/useExtensionMenuItems';
function _CollectionItemActions({ state, renderActionCell, }) {
    const { confirmModal } = state;
    const toolbarState = useToolbarCollectionContext();
    const { toolbarBIReporter } = toolbarState;
    const actionCellProps = renderActionCell?.(state) ?? {};
    const keyedItem = state.actionCellAPI.keyedItem;
    const existingExtension = actionCellProps.containerId
        ? toolbarState.menuItemExtensions.get(actionCellProps.containerId)
        : undefined;
    const extensionMenuItems = useExtensionMenuItems({
        containerId: actionCellProps.containerId,
        extension: existingExtension,
    });
    useEffect(() => {
        if (extensionMenuItems && actionCellProps.containerId) {
            toolbarState.menuItemExtensions.set(actionCellProps.containerId, extensionMenuItems);
        }
    }, [extensionMenuItems, actionCellProps.containerId]);
    const secondaryActionCellPropsWithBI = createSecondaryActionCellPropWithBi({
        toolbarBIReporter,
        actionCellProps,
        keyedItem,
        extensionMenuItems,
    });
    const primaryActionCellPropsWithBI = createPrimaryActionCellPropsWithBI(toolbarBIReporter, actionCellProps, keyedItem);
    return (React.createElement(React.Fragment, null,
        confirmModal.value && (React.createElement(MessageActionModal, { state: confirmModal, ...confirmModal.value })),
        React.createElement(TableActionCell, { dataHook: "collection-action-cell", ...actionCellProps, popoverMenuProps: {
                ...getDefaultActionCellProps(),
                onShow: () => reportOnPopoverMenuShow(toolbarBIReporter, actionCellProps, state.keyedItem),
                ...actionCellProps.popoverMenuProps,
                ...getDefaultActionCellProps(),
            }, primaryAction: primaryActionCellPropsWithBI, secondaryActions: secondaryActionCellPropsWithBI })));
}
export const CollectionItemActions = observer(_CollectionItemActions);
//# sourceMappingURL=CollectionItemActions.js.map