import { action, makeObservable, observable } from 'mobx';
import { ConditionalModalState, } from '@wix/bex-core';
import { ConfirmModalBIReporter } from './ConfirmModalBIReporter';
export class ItemActionsState {
    constructor(params) {
        this.confirmModal = new ConditionalModalState();
        this.fade = params.fade;
        this.keyedItem = params.keyedItem;
        this.collection = params.collection;
        this.biReporter = params.reportBi
            ? new ConfirmModalBIReporter({
                reportBi: params.reportBi,
                itemId: params.keyedItem.id,
                itemIndex: params.keyedItem.indexWithinPage,
            })
            : null;
        makeObservable(this, {
            keyedItem: observable.ref,
            fade: observable.ref,
            onFadeStart: action.bound,
            onFadeDone: action.bound,
            setItemIfChanged: action,
            openConfirmModal: action.bound,
            openConfirmDeleteModal: action.bound,
        });
        this.actionCellAPI = {
            openConfirmModal: this.openConfirmModal,
            openConfirmDeleteModal: this.openConfirmDeleteModal,
            collection: this.collection,
            keyedItem: this.keyedItem,
        };
    }
    openConfirmModal(props) {
        const { translate: t } = this.collection;
        this.confirmModal.open({
            title: t('cairo.confirmModal.title'),
            primaryButtonText: t('cairo.confirm.button'),
            secondaryButtonText: t('cairo.cancel.button'),
            ...props,
        });
    }
    openConfirmDeleteModal(props) {
        const { translate: t } = this.collection;
        if (!this.confirmModal.isOpen) {
            this.biReporter?.reportDeleteModalShown();
        }
        this.openConfirmModal({
            theme: 'destructive',
            title: t('cairo.deleteModal.title'),
            content: t('cairo.deleteModal.body'),
            ...props,
            primaryButtonOnClick: () => {
                this.biReporter?.reportDeleteModalCtaClicked('Delete');
                props?.primaryButtonOnClick?.();
            },
            secondaryButtonOnClick: () => {
                this.biReporter?.reportDeleteModalCtaClicked('Cancel');
                props?.secondaryButtonOnClick?.();
            },
            onCloseButtonClick: (e) => {
                this.biReporter?.reportDeleteModalCtaClicked('X');
                props?.onCloseButtonClick?.(e);
            },
        });
    }
    onFadeStart() {
        if (this.fade === 'exit') {
            this.fade = 'exiting';
        }
    }
    onFadeDone() {
        const { fade } = this;
        if (fade === 'exiting') {
            this.fade = 'idle';
        }
    }
    setItemIfChanged(keyedItem) {
        if (this.keyedItem !== keyedItem) {
            this.keyedItem = keyedItem;
        }
    }
}
//# sourceMappingURL=ItemActionsState.js.map