// (C) 2024-2026 GoodData Corporation
import { put, select } from "redux-saga/effects";
import { visualizationSwitcherWidgetVisualizationsUpdated, } from "../../events/visualizationSwitcher.js";
import { tabsActions } from "../../store/tabs/index.js";
import { selectWidgetsMap } from "../../store/tabs/layout/layoutSelectors.js";
import { validateExistingVisualizationSwitcherWidget } from "./validation/widgetValidations.js";
export function* updateVisualizationsFromSwticherWidgetContentHandler(ctx, cmd) {
    const { payload: { visualizations }, correlationId, } = cmd;
    const widgets = yield select(selectWidgetsMap);
    const visualizationSwitcherWidget = validateExistingVisualizationSwitcherWidget(widgets, cmd, ctx);
    yield put(tabsActions.updateVisualizationSwitcherWidgetVisualizations({
        ref: visualizationSwitcherWidget.ref,
        visualizations,
        undo: {
            cmd,
        },
    }));
    return visualizationSwitcherWidgetVisualizationsUpdated(ctx, visualizationSwitcherWidget.ref, visualizations, correlationId);
}
