"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PlusMinusApiImpl = void 0;
const tslib_1 = require("tslib");
const ApiBase_1 = require("./ApiBase");
const ModuleConstants = tslib_1.__importStar(require("../../Utilities/Constants/ModuleConstants"));
const PlusMinusRedux = tslib_1.__importStar(require("../../Redux/ActionsReducers/PlusMinusRedux"));
class PlusMinusApiImpl extends ApiBase_1.ApiBase {
    getPlusMinusState() {
        return this.getAdaptableState().PlusMinus;
    }
    getAllPlusMinus(config) {
        const layoutSpecificPlusMinusNudges = this.handleLayoutExtensionObjects(this.getPlusMinusState().PlusMinusNudges, 'PlusMinus', config) ?? [];
        return layoutSpecificPlusMinusNudges.filter((plusMinusNudge) => plusMinusNudge.Rule == undefined || plusMinusNudge.Rule.BooleanExpression != undefined);
    }
    getPlusMinusById(id, config) {
        return this.getAllPlusMinus(config).find((plusMinus) => plusMinus?.Uuid === id);
    }
    getPlusMinusNudgeByName(name) {
        return this.getAllPlusMinus().find((plusMinus) => plusMinus.Name === name);
    }
    getAllActivePlusMinus(config) {
        return this.getAllPlusMinus(config).filter((plusMinusNudge) => !plusMinusNudge.IsSuspended);
    }
    getAllSuspendedPlusMinus(config) {
        return this.getAllPlusMinus(config).filter((plusMinusNudge) => plusMinusNudge.IsSuspended);
    }
    runPlusMinusNudge(plusMinusNudge, cellsToUpdate, direction) {
        let plusMinusModule = (this.getAdaptableInternalApi().getModules().get(ModuleConstants.PlusMinusModuleId));
        plusMinusModule.applyPlusMinus([plusMinusNudge], cellsToUpdate, direction);
    }
    applyPlusMinus(cellUpdateRequests) {
        this.dispatchAction(PlusMinusRedux.PlusMinusApply(cellUpdateRequests));
    }
    openPlusMinusSettingsPanel() {
        this.showModulePopup(ModuleConstants.PlusMinusModuleId);
    }
    editPlusMinusNudge(plusMinusNudge) {
        this.dispatchAction(PlusMinusRedux.PlusMinusNudgeEdit(plusMinusNudge));
        return this.getPlusMinusById(plusMinusNudge.Uuid);
    }
    deletePlusMinusNudge(plusMinusNudge) {
        this.dispatchAction(PlusMinusRedux.PlusMinusNudgeDelete(plusMinusNudge));
    }
    suspendPlusMinusNudge(plusMinusNudge) {
        this.dispatchAction(PlusMinusRedux.PlusMinusNudgeSuspend(plusMinusNudge));
        return this.getPlusMinusById(plusMinusNudge.Uuid);
    }
    unSuspendPlusMinusNudge(plusMinusNudge) {
        this.dispatchAction(PlusMinusRedux.PlusMinusNudgeUnSuspend(plusMinusNudge));
        return this.getPlusMinusById(plusMinusNudge.Uuid);
    }
    addPlusMinusNudge(plusMinusNudge) {
        this.addUidToAdaptableObject(plusMinusNudge);
        this.dispatchAction(PlusMinusRedux.PlusMinusNudgeAdd(plusMinusNudge));
        return this.getPlusMinusById(plusMinusNudge.Uuid);
    }
}
exports.PlusMinusApiImpl = PlusMinusApiImpl;
