// (C) 2024-2026 GoodData Corporation
import { useCallback } from "react";
import { saveAlert } from "../../../../../../model/commands/alerts.js";
import { useDashboardCommandProcessing, } from "../../../../../../model/react/useDashboardCommandProcessing.js";
export const useUpdateAlert = ({ onBeforeRun, onSuccess, onError, } = {}) => {
    const alertCommandProcessing = useDashboardCommandProcessing({
        commandCreator: saveAlert,
        errorEvent: "GDC.DASH/EVT.COMMAND.FAILED",
        successEvent: "GDC.DASH/EVT.ALERT.SAVED",
        onError: (event) => {
            onError?.(event.payload.error);
        },
        onSuccess: (event) => {
            onSuccess?.(event.payload.alert);
        },
        onBeforeRun: (cmd) => {
            onBeforeRun?.(cmd.payload.alert);
        },
    });
    const save = useCallback((alertToSave) => {
        alertCommandProcessing.run(alertToSave);
    }, [alertCommandProcessing]);
    return {
        save,
        savingStatus: alertCommandProcessing.status,
    };
};
