// (C) 2021-2026 GoodData Corporation
import { call, select } from "redux-saga/effects";
import { objRefToString } from "@gooddata/sdk-model";
import { invalidArgumentsProvided } from "../../events/general.js";
import { selectWidgetPathByRef } from "../../store/tabs/layout/layoutSelectors.js";
import { removeSectionItemSaga } from "./removeSectionItemHandler.js";
export function* removeSectionItemByWidgetRefHandler(ctx, cmd) {
    let widgetCoordinates;
    try {
        widgetCoordinates = (yield select(selectWidgetPathByRef(cmd.payload.widgetRef)));
    }
    catch (e) {
        throw invalidArgumentsProvided(ctx, cmd, `Can't get widget coordinates for widget ref: ${objRefToString(cmd.payload.widgetRef)}, ${e.message}`);
    }
    return yield call(removeSectionItemSaga, ctx, {
        correlationId: cmd.correlationId,
        payload: {
            itemPath: widgetCoordinates,
            sectionIndex: -1, // just for compatibility purposes, information will be ignored
            itemIndex: -1, // just for compatibility purposes, information will be ignored
            eager: cmd.payload.eager,
            stashIdentifier: cmd.payload.stashIdentifier,
        },
    }, cmd);
}
//# sourceMappingURL=removeSectionItemByWidgetRefHandler.js.map