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