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