"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FlashingCellInternalApi = void 0;
const tslib_1 = require("tslib");
const ApiBase_1 = require("../Implementation/ApiBase");
const Helper_1 = require("../../Utilities/Helpers/Helper");
const AlertRedux = tslib_1.__importStar(require("../../Redux/ActionsReducers/AlertRedux"));
const FlashingCellService_1 = require("../../Utilities/Services/FlashingCellService");
class FlashingCellInternalApi extends ApiBase_1.ApiBase {
    /**
     * Merges a Flashing Cell Definition with default values
     * @param flashingCellDefinition Flashing Cell Definition to Merge
     */
    mergeFlashingCellDefinitionWithDefaults(flashingCellDefinition) {
        let flashingDefaults = this.getFlashingCellOptions();
        if (!flashingDefaults) {
            return flashingCellDefinition;
        }
        // deep clone it, otherwise we will mutate&share(!!) the global flashingCellOptions object
        flashingDefaults = (0, Helper_1.cloneObject)(flashingDefaults);
        if (!flashingCellDefinition.DownChangeStyle && flashingDefaults.defaultDownChangeStyle) {
            flashingCellDefinition.DownChangeStyle = flashingDefaults.defaultDownChangeStyle;
        }
        if (!flashingCellDefinition.UpChangeStyle && flashingDefaults.defaultUpChangeStyle) {
            flashingCellDefinition.UpChangeStyle = flashingDefaults.defaultUpChangeStyle;
        }
        if (!flashingCellDefinition.NeutralChangeStyle && flashingDefaults.defaultNeutralChangeStyle) {
            flashingCellDefinition.NeutralChangeStyle = flashingDefaults.defaultNeutralChangeStyle;
        }
        if (!flashingCellDefinition.FlashDuration && flashingDefaults.defaultFlashDuration) {
            flashingCellDefinition.FlashDuration = flashingDefaults.defaultFlashDuration;
        }
        if (!flashingCellDefinition.FlashTarget && flashingDefaults.defaultFlashTarget) {
            flashingCellDefinition.FlashTarget = flashingDefaults.defaultFlashTarget;
        }
        return flashingCellDefinition;
    }
    getAdaptableFlashingCellFor(primaryKey, columnId) {
        const flashingCellService = this.getAdaptableInternalApi().getFlashingCellService();
        const AdaptableFlashingAlerts = flashingCellService.gridCellsCurrentlyFlashing;
        const AdaptableFlashingAlertsMap = flashingCellService.flashingCellsMapping;
        const forPrimaryKey = AdaptableFlashingAlerts[primaryKey] ?? {};
        const toFlashingAlert = (uuid) => uuid ? AdaptableFlashingAlertsMap[uuid] ?? null : null;
        const adaptableFlashingCell = columnId
            ? toFlashingAlert(forPrimaryKey[columnId])
            : toFlashingAlert(forPrimaryKey[FlashingCellService_1.FLASHING_CELL_ROW_KEY]);
        if (adaptableFlashingCell?.flashingCellDefinition &&
            !this.getLayoutApi().internalApi.isObjectExtendedInLayout(adaptableFlashingCell.flashingCellDefinition, 'FlashingCell', this.getLayoutApi().getCurrentLayout())) {
            return;
        }
        return adaptableFlashingCell;
    }
    clearFlashingCellState() {
        this.dispatchAction(AlertRedux.AlertClearFlashingCells());
    }
}
exports.FlashingCellInternalApi = FlashingCellInternalApi;
