// (C) 2021-2026 GoodData Corporation
import { put, select } from "redux-saga/effects";
import { insightWidgetVisPropertiesChanged, } 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* changeInsightWidgetVisPropertiesHandler(ctx, cmd) {
    const { payload: { properties }, correlationId, } = cmd;
    const widgets = yield select(selectWidgetsMap);
    const insightWidget = validateExistingInsightWidget(widgets, cmd, ctx);
    yield put(tabsActions.replaceInsightWidgetVisProperties({
        ref: insightWidget.ref,
        properties,
        undo: {
            cmd,
        },
    }));
    return insightWidgetVisPropertiesChanged(ctx, insightWidget.ref, properties, correlationId);
}
