// (C) 2020-2026 GoodData Corporation
import { useState } from "react";
import { useDashboardCommand } from "./useDashboardCommand.js";
/**
 * @internal
 */
export const useDashboardCommandProcessing = ({ commandCreator, successEvent, errorEvent, onSuccess, onError, onBeforeRun, }) => {
    const [status, setStatus] = useState();
    const run = useDashboardCommand(commandCreator, {
        [successEvent]: (event) => {
            setStatus("success");
            onSuccess?.(event);
        },
        [errorEvent]: (event) => {
            setStatus("error");
            onError?.(event);
        },
    }, (cmd) => {
        setStatus("running");
        onBeforeRun?.(cmd);
    });
    return {
        run,
        status,
    };
};
