// (C) 2020-2026 GoodData Corporation
import { useCallback } from "react";
import { saveScheduledEmail } from "../../../../model/commands/scheduledEmail.js";
import { useDashboardCommandProcessing, } from "../../../../model/react/useDashboardCommandProcessing.js";
export const useUpdateScheduledEmail = ({ onBeforeRun, onSuccess, onError, } = {}) => {
    const scheduledEmailCommandProcessing = useDashboardCommandProcessing({
        commandCreator: saveScheduledEmail,
        errorEvent: "GDC.DASH/EVT.COMMAND.FAILED",
        successEvent: "GDC.DASH/EVT.SCHEDULED_EMAIL.SAVED",
        onError: (event) => {
            onError?.(event.payload.error);
        },
        onSuccess: () => {
            onSuccess?.();
        },
        onBeforeRun: (cmd) => {
            onBeforeRun?.(cmd.payload.scheduledEmail);
        },
    });
    const save = useCallback((scheduledEmailToSave) => {
        scheduledEmailCommandProcessing.run(scheduledEmailToSave);
    }, [scheduledEmailCommandProcessing]);
    return {
        save,
        savingStatus: scheduledEmailCommandProcessing.status,
    };
};
//# sourceMappingURL=useUpdateScheduledEmail.js.map