// (C) 2026 GoodData Corporation
import { getActiveTab } from "../tabsState.js";
/**
 * Changes the config mode for the measure value filter given by its local identifier.
 */
const changeMeasureValueFilterConfigMode = (state, action) => {
    const { localIdentifier, mode } = action.payload;
    const activeTab = getActiveTab(state);
    if (!activeTab) {
        return;
    }
    if (!activeTab.measureValueFilterConfigs) {
        activeTab.measureValueFilterConfigs = { measureValueFilterConfigs: [] };
    }
    const existingConfig = activeTab.measureValueFilterConfigs.measureValueFilterConfigs?.find((item) => item.localIdentifier === localIdentifier);
    if (existingConfig) {
        existingConfig.mode = mode;
        activeTab.measureValueFilterConfigs.measureValueFilterConfigs = [
            ...(activeTab.measureValueFilterConfigs.measureValueFilterConfigs ?? []),
        ];
    }
    else {
        activeTab.measureValueFilterConfigs.measureValueFilterConfigs = [
            ...(activeTab.measureValueFilterConfigs.measureValueFilterConfigs || []),
            { localIdentifier, mode },
        ];
    }
};
const setMeasureValueFilterConfigs = (state, action) => {
    const { measureValueFilterConfigs } = action.payload;
    const activeTab = getActiveTab(state);
    if (!activeTab) {
        return;
    }
    activeTab.measureValueFilterConfigs = measureValueFilterConfigs
        ? { measureValueFilterConfigs }
        : undefined;
};
const removeMeasureValueFilterConfig = (state, action) => {
    const activeTab = getActiveTab(state);
    if (!activeTab) {
        return;
    }
    if (activeTab.measureValueFilterConfigs?.measureValueFilterConfigs) {
        activeTab.measureValueFilterConfigs.measureValueFilterConfigs =
            activeTab.measureValueFilterConfigs.measureValueFilterConfigs.filter((config) => config.localIdentifier !== action.payload);
    }
};
export const measureValueFilterConfigsReducers = {
    changeMeasureValueFilterConfigMode,
    setMeasureValueFilterConfigs,
    removeMeasureValueFilterConfig,
};
//# sourceMappingURL=measureValueFilterConfigsReducers.js.map