import React, { useMemo } from 'react';
import { IconButton, PopoverMenu, } from '@wix/design-system';
import { observer } from 'mobx-react-lite';
import { MoreSmall } from '@wix/wix-ui-icons-common';
import { getDefaultActionCellProps } from '../CollectionItemActions/getDefaultActionCellProps';
import { ItemActionsState } from '../../state';
import { MessageActionModal } from '../ActionModal';
function _StageActions({ state, stageKey, stageActionCell, }) {
    const keyedItem = state.stagesCollectionState.getKeyedItem(stageKey);
    const stageActionsState = useMemo(() => {
        if (!keyedItem) {
            return null;
        }
        return new ItemActionsState({
            keyedItem,
            fade: 'static',
            collection: state.stagesCollectionState,
            reportBi: state.toolbar.reportBi,
        });
    }, [keyedItem, state.stagesCollectionState, state.toolbar.reportBi]);
    if (!keyedItem || !stageActionsState) {
        return null;
    }
    const resolvedActionCell = typeof stageActionCell === 'function'
        ? stageActionCell(keyedItem.item, keyedItem.indexWithinPage, stageActionsState.actionCellAPI)
        : stageActionCell;
    const secondaryActions = resolvedActionCell?.secondaryActions;
    if (!secondaryActions?.length) {
        return null;
    }
    return (React.createElement(React.Fragment, null,
        stageActionsState.confirmModal.value && (React.createElement(MessageActionModal, { state: stageActionsState.confirmModal, ...stageActionsState.confirmModal.value })),
        React.createElement(PopoverMenu, { ...getDefaultActionCellProps(), textSize: "small", minWidth: "223px", dataHook: `kanban-stage-more-actions-${stageKey}`, triggerElement: ({ toggle }) => {
                return (React.createElement(IconButton, { skin: "dark", priority: "tertiary", size: "small", dataHook: `kanban-stage-more-actions-trigger-${stageKey}`, onClick: (e) => {
                        e.stopPropagation();
                        toggle();
                    } },
                    React.createElement(MoreSmall, null)));
            } }, secondaryActions.map((secondaryAction, index) => {
            if (secondaryAction.divider) {
                return React.createElement(PopoverMenu.Divider, { key: index });
            }
            const action = secondaryAction;
            const { icon: prefixIcon, skin, ...rest } = action;
            return (React.createElement(PopoverMenu.MenuItem, { key: index, dataHook: `kanban-stage-more-actions-item-${stageKey}`, skin: skin, prefixIcon: prefixIcon, ...rest }));
        }))));
}
export const StageActions = observer(_StageActions);
//# sourceMappingURL=StageActions.js.map