// (C) 2022-2026 GoodData Corporation
import { useCallback, useEffect } from "react";
import { convertError } from "@gooddata/sdk-ui";
import { useSaveAlertToBackend } from "../../DefaultAlertingDialog/hooks/useSaveAlertToBackend.js";
export function PauseAlertRunner({ alert, pause, onSuccess, onError }) {
    const { handlePauseAlert, handleResumeAlert } = useSaveAlertToBackend({
        onPauseSuccess: () => {
            if (alert) {
                onSuccess?.(alert, true);
            }
        },
        onPauseError: (error) => {
            onError?.(convertError(error), true);
        },
        onResumeSuccess: () => {
            if (alert) {
                onSuccess?.(alert, false);
            }
        },
        onResumeError: () => {
            if (alert) {
                onSuccess?.(alert, false);
            }
        },
    });
    const handlerPauseAlert = useCallback(() => {
        if (!alert) {
            return;
        }
        if (pause) {
            const alertToPause = {
                ...alert,
                alert: { ...alert.alert, trigger: { ...alert.alert?.trigger, state: "PAUSED" } },
            };
            handlePauseAlert(alertToPause);
        }
        else {
            const alertToResume = {
                ...alert,
                alert: { ...alert.alert, trigger: { ...alert.alert?.trigger, state: "ACTIVE" } },
            };
            handleResumeAlert(alertToResume);
        }
    }, [alert, handlePauseAlert, handleResumeAlert, pause]);
    useEffect(() => {
        handlerPauseAlert();
        // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [alert]);
    return null;
}
//# sourceMappingURL=PauseAlertRunner.js.map