// (C) 2021-2026 GoodData Corporation
import { put, select } from "redux-saga/effects";
import { kpiWidgetConfigurationChanged, } from "../../events/kpi.js";
import { tabsActions } from "../../store/tabs/index.js";
import { selectWidgetsMap } from "../../store/tabs/layout/layoutSelectors.js";
import { validateExistingKpiWidget } from "./validation/widgetValidations.js";
export function* changeKpiWidgetConfigurationHandler(ctx, cmd) {
    const { payload: { config }, correlationId, } = cmd;
    const widgets = yield select(selectWidgetsMap);
    const kpiWidget = validateExistingKpiWidget(widgets, cmd, ctx);
    yield put(tabsActions.replaceKpiWidgetConfiguration({
        ref: kpiWidget.ref,
        config,
        undo: {
            cmd,
        },
    }));
    return kpiWidgetConfigurationChanged(ctx, kpiWidget.ref, config, correlationId);
}
