// (C) 2020-2026 GoodData Corporation
import { useCallback } from "react";
import { invariant } from "ts-invariant";
import { triggerEvent } from "../commands/events.js";
import { isDashboardEventOrCustomDashboardEvent, } from "../events/base.js";
import { useDashboardDispatch } from "./DashboardStoreProvider.js";
/**
 * Convenience hook for dispatching Dashboard events.
 *
 * @returns function that you can use to dispatch Dashboard events
 * @alpha
 */
export const useDashboardEventDispatch = () => {
    const dispatch = useDashboardDispatch();
    return useCallback((eventBody) => {
        invariant(isDashboardEventOrCustomDashboardEvent(eventBody), "Unsupported event passed to useDashboardEventDispatch result.");
        const command = triggerEvent(eventBody);
        dispatch(command);
    }, [dispatch]);
};
