"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 {
    internalApi;
    constructor(_adaptable) {
        super(_adaptable);
        this.internalApi = new FlashingCellInternalApi_1.FlashingCellInternalApi(_adaptable);
    }
    getFlashingCellState() {
        return this.getAdaptableState().FlashingCell;
    }
    getFlashingCellDefinitions(config) {
        const flashingCellDefinitions = this.handleLayoutExtensionObjects(this.getFlashingCellState().FlashingCellDefinitions, 'FlashingCell', config) ?? [];
        return flashingCellDefinitions.map((flashingCellDefinition) => {
            return this.internalApi.mergeFlashingCellDefinitionWithDefaults(flashingCellDefinition);
        });
    }
    getFlashingCellDefinitionById(id, config) {
        return this.getFlashingCellDefinitions(config)?.find((fc) => fc?.Uuid === id);
    }
    getFlashingCellDefinitionByName(name) {
        return this.getFlashingCellDefinitions().find((fc) => fc.Name === name);
    }
    getActiveFlashingCellDefinitions(config) {
        return this.getFlashingCellDefinitions(config).filter((fc) => !fc.IsSuspended);
    }
    getSuspendedFlashingCellDefinitions(config) {
        return this.getFlashingCellDefinitions(config).filter((fc) => fc.IsSuspended);
    }
    getFlashingCellFlashTarget(flashingCellDefinition) {
        return flashingCellDefinition.FlashTarget ?? 'cell';
    }
    showFlashingCell(flashingCellToShow) {
        this.addUidToAdaptableObject(flashingCellToShow);
        this.getAdaptableApi()
            .internalApi.getFlashingCellService()
            .addGridCellFlash(flashingCellToShow);
        const { FlashDuration: FlashDuration } = flashingCellToShow.flashingCellDefinition;
        if (FlashDuration && FlashDuration !== 'always') {
            setTimeout(() => {
                this.getAdaptableApi()
                    .internalApi.getFlashingCellService()
                    .clearGridCellFlash(flashingCellToShow);
            }, FlashDuration);
        }
        this.getEventApi().internalApi.fireFlashingCellDisplayedEvent(flashingCellToShow);
    }
    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?.map((flashingCell) => this.getFlashingCellDefinitionById(flashingCell?.Uuid));
    }
    editFlashingCellDefinitions(flashingCellDefinitions) {
        flashingCellDefinitions.forEach((fad) => {
            this.editFlashingCellDefinition(fad);
        });
        return flashingCellDefinitions?.map((flashingCell) => this.getFlashingCellDefinitionById(flashingCell?.Uuid));
    }
    deleteFlashingCellDefinition(flashingCellDefinition) {
        this.dispatchAction(FlashingCellRedux.FlashingCellDefinitionDelete(flashingCellDefinition));
    }
    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({
            includeLayoutNotExtendedObjects: true,
        }));
    }
}
exports.FlashingCellApiImpl = FlashingCellApiImpl;
