import { createElement } from 'react';
import { action } from 'mobx';
import { KanbanCtaType } from '../../state/KanbanState/KanbanStateBIReporter';
const calcCtaCount = (actionCellProps) => {
    const { secondaryActions } = actionCellProps;
    return secondaryActions?.length || 0;
};
export const createKanbanSecondaryActionCellPropsWithBI = ({ state, actionCellProps, keyedItem, extensionMenuItems, stageId, }) => {
    const { secondaryActions = [] } = actionCellProps;
    const stageIndex = state.getStageIndexByKey(stageId);
    const stageName = state.getStageNameByKey(stageId);
    const moreSecondaryItems = extensionMenuItems?.menuItems.map((menuItem) => {
        return {
            ...menuItem,
            icon: menuItem.prefixIcon || createElement('div'),
        };
    }) || [];
    const allActions = [
        ...secondaryActions,
        ...moreSecondaryItems,
    ];
    return (allActions.map((_action, index) => {
        const biIndex = index;
        if (_action.divider) {
            return _action;
        }
        const onClick = action(() => {
            state.kanbanStateBIReporter.reportCardCTAClicked({
                itemId: keyedItem.id,
                itemIndex: keyedItem.index,
                ctaName: _action.biName || _action.text || 'Secondary Action',
                ctaType: KanbanCtaType.MORE_ACTIONS_OPTION,
                stageIndex,
                stageId,
                stageName,
                ctaIndex: biIndex,
                numCtas: calcCtaCount(actionCellProps),
            });
            _action.onClick?.();
        });
        const { biName: _biName, ...secondaryActionProperties } = _action;
        return { ...secondaryActionProperties, onClick };
    }) || []);
};
export const createKanbanPrimaryActionCellPropsWithBI = ({ state, actionCellProps, keyedItem, stageId, }) => {
    const { primaryAction } = actionCellProps;
    const stageIndex = state.getStageIndexByKey(stageId);
    const stageName = state.getStageNameByKey(stageId);
    if (primaryAction && !Array.isArray(primaryAction)) {
        const onClick = action(() => {
            state.kanbanStateBIReporter.reportCardCTAClicked({
                itemId: keyedItem.id,
                itemIndex: keyedItem.index,
                ctaName: primaryAction?.biName || primaryAction?.text || 'Primary Action',
                ctaType: KanbanCtaType.PRIMARY_BUTTON,
                stageId,
                stageIndex,
                stageName,
            });
            primaryAction?.onClick();
        });
        const { biName, ...primaryActionProperties } = primaryAction;
        return { ...primaryActionProperties, onClick };
    }
    return primaryAction;
};
export const reportOnKanbanPopoverMenuShow = ({ state, keyedItem, stageId, }) => {
    const stageIndex = state.getStageIndexByKey(stageId);
    const stageName = state.getStageNameByKey(stageId);
    state.kanbanStateBIReporter.reportCardCTAClicked({
        itemId: keyedItem.id,
        itemIndex: keyedItem.index,
        ctaName: 'More Actions',
        ctaType: KanbanCtaType.SECONDARY_DROPDOWN,
        stageId,
        stageIndex,
        stageName,
    });
};
//# sourceMappingURL=KanbanCardActionsHelper.js.map