// (C) 2021-2026 GoodData Corporation
import { put, select } from "redux-saga/effects";
import { insightWidgetVisConfigurationChanged, } from "../../events/insight.js";
import { tabsActions } from "../../store/tabs/index.js";
import { selectWidgetsMap } from "../../store/tabs/layout/layoutSelectors.js";
import { validateExistingInsightWidget } from "./validation/widgetValidations.js";
export function* changeInsightWidgetVisConfigurationHandler(ctx, cmd) {
    const { payload: { config }, correlationId, } = cmd;
    const widgets = yield select(selectWidgetsMap);
    const insightWidget = validateExistingInsightWidget(widgets, cmd, ctx);
    yield put(tabsActions.replaceInsightWidgetVisConfiguration({
        ref: insightWidget.ref,
        config,
        undo: {
            cmd,
        },
    }));
    return insightWidgetVisConfigurationChanged(ctx, insightWidget.ref, config, insightWidget.configuration, correlationId);
}
