import { ApiBase } from '../Implementation/ApiBase';
import { cloneObject } from '../../Utilities/Helpers/Helper';
import * as AlertRedux from '../../Redux/ActionsReducers/AlertRedux';
import { FLASHING_CELL_ROW_KEY } from '../../Utilities/Services/FlashingCellService';
export class FlashingCellInternalApi extends 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 = 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[FLASHING_CELL_ROW_KEY]);
        if (adaptableFlashingCell?.flashingCellDefinition &&
            !this.getLayoutApi().internalApi.isObjectAvailableInLayout(adaptableFlashingCell.flashingCellDefinition, 'FlashingCell', this.getLayoutApi().getCurrentLayout())) {
            return;
        }
        return adaptableFlashingCell;
    }
    clearFlashingCellState() {
        this.dispatchAction(AlertRedux.AlertClearFlashingCells());
    }
}
