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