"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FlashingCellApiImpl = void 0;
const tslib_1 = require("tslib");
const FlashingCellRedux = tslib_1.__importStar(require("../../Redux/ActionsReducers/FlashingCellRedux"));
const ApiBase_1 = require("./ApiBase");
const FlashingCellInternalApi_1 = require("../Internal/FlashingCellInternalApi");
class FlashingCellApiImpl extends ApiBase_1.ApiBase {
    constructor(_adaptable) {
        super(_adaptable);
        this.internalApi = new FlashingCellInternalApi_1.FlashingCellInternalApi(_adaptable);
    }
    getFlashingCellState() {
        return this.getAdaptableState().FlashingCell;
    }
    getFlashingCellDefinitions(config) {
        var _a;
        const flashingCellDefinitions = (_a = this.handleLayoutAssociatedObjects(this.getFlashingCellState().FlashingCellDefinitions, 'FlashingCell', config)) !== null && _a !== void 0 ? _a : [];
        return flashingCellDefinitions.map((flashingCellDefinition) => {
            return this.internalApi.mergeFlashingCellDefinitionWithDefaults(flashingCellDefinition);
        });
    }
    getFlashingCellDefinitionById(id) {
        var _a;
        return (_a = this.getFlashingCellDefinitions()) === null || _a === void 0 ? void 0 : _a.find((fc) => (fc === null || fc === void 0 ? void 0 : fc.Uuid) === id);
    }
    getActiveFlashingCellDefinitions() {
        return this.getFlashingCellDefinitions().filter((fc) => !fc.IsSuspended);
    }
    getSuspendedFlashingCellDefinitions() {
        return this.getFlashingCellDefinitions().filter((fc) => fc.IsSuspended);
    }
    getFlashingCellFlashTarget(flashingCellDefinition) {
        var _a;
        return (_a = flashingCellDefinition.FlashTarget) !== null && _a !== void 0 ? _a : 'cell';
    }
    showFlashingCell(flashingCellToShow) {
        this.addUidToAdaptableObject(flashingCellToShow);
        const flashingCellFiredInfo = Object.assign(Object.assign({}, this.getAdaptableInternalApi().buildBaseContext()), { flashingCell: flashingCellToShow });
        const results = this.getEventApi().emitSync('FlashingCellDisplayed', flashingCellFiredInfo);
        const shouldShow = results.reduce((endResult, aResult) => {
            return endResult && aResult !== false;
        }, true);
        if (shouldShow) {
            this.getAdaptableApi()
                .internalApi.getFlashingCellService()
                .addGridCellFlash(flashingCellToShow);
            const { FlashDuration: FlashDuration } = flashingCellToShow.flashingCellDefinition;
            if (FlashDuration && FlashDuration !== 'always') {
                setTimeout(() => {
                    this.getAdaptableApi()
                        .internalApi.getFlashingCellService()
                        .clearGridCellFlash(flashingCellToShow);
                }, FlashDuration);
            }
        }
    }
    addFlashingCellDefinition(flashingCellDefinition) {
        this.dispatchAction(FlashingCellRedux.FlashingCellDefinitionAdd(flashingCellDefinition));
        return this.getFlashingCellDefinitionById(flashingCellDefinition.Uuid);
    }
    setFlashingCellDefinitions(flashingCellDefinitions) {
        this.dispatchAction(FlashingCellRedux.FlashingCellDefinitionSet(flashingCellDefinitions));
    }
    editFlashingCellDefinition(flashingCellDefinition) {
        this.dispatchAction(FlashingCellRedux.FlashingCellDefinitionEdit(flashingCellDefinition));
        return this.getFlashingCellDefinitionById(flashingCellDefinition.Uuid);
    }
    suspendFlashingCellDefinition(flashingCellDefinition) {
        this.dispatchAction(FlashingCellRedux.FlashingCellDefinitionSuspend(flashingCellDefinition));
        return this.getFlashingCellDefinitionById(flashingCellDefinition.Uuid);
    }
    unSuspendFlashingCellDefinition(flashingCellDefinition) {
        this.dispatchAction(FlashingCellRedux.FlashingCellDefinitionUnSuspend(flashingCellDefinition));
        return this.getFlashingCellDefinitionById(flashingCellDefinition.Uuid);
    }
    suspendAllFlashingCellDefinition() {
        this.dispatchAction(FlashingCellRedux.FlashingCellDefinitionSuspendAll());
    }
    unSuspendAllFlashingCellDefinition() {
        this.dispatchAction(FlashingCellRedux.FlashingCellDefinitionUnSuspendAll());
    }
    addFlashingCellDefinitions(flashingCellDefinitions) {
        flashingCellDefinitions.forEach((fad) => {
            this.addFlashingCellDefinition(fad);
        });
        return flashingCellDefinitions === null || flashingCellDefinitions === void 0 ? void 0 : flashingCellDefinitions.map((flashingCell) => this.getFlashingCellDefinitionById(flashingCell === null || flashingCell === void 0 ? void 0 : flashingCell.Uuid));
    }
    editFlashingCellDefinitions(flashingCellDefinitions) {
        flashingCellDefinitions.forEach((fad) => {
            this.editFlashingCellDefinition(fad);
        });
        return flashingCellDefinitions === null || flashingCellDefinitions === void 0 ? void 0 : flashingCellDefinitions.map((flashingCell) => this.getFlashingCellDefinitionById(flashingCell === null || flashingCell === void 0 ? void 0 : flashingCell.Uuid));
    }
    getFlashingCellPredicateDefsForScope(scope) {
        return this.getAdaptableApi()
            .predicateApi.internalApi.getFlashingCellPredicateDefs(scope)
            .filter((predicateDef) => this.getColumnScopeApi().isScopeInScope(scope, predicateDef.columnScope));
    }
    clearAllFlashingCells() {
        this.getAdaptableInternalApi().getFlashingCellService().clearAllGridCellFlashes();
    }
    isAnyFlashingCellActive() {
        return this.getAdaptableInternalApi().getFlashingCellService().isAnyFlashingCellActive();
    }
    findFlashingCellDefinitions(criteria) {
        return this.getAdaptableInternalApi().findAdaptableObjectsByLookupCriteria(criteria, this.getFlashingCellDefinitions({
            includeLayoutNotAssociatedObjects: true,
        }));
    }
}
exports.FlashingCellApiImpl = FlashingCellApiImpl;
