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