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