import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
// (C) 2022-2026 GoodData Corporation
import { useCallback, useState } from "react";
import { useAutomationsContext } from "../../contexts/AutomationsContext.js";
import { DeleteAlertConfirmDialog } from "./components/DeleteAlertConfirmDialog.js";
import { PauseAlertRunner } from "./components/PauseAlertRunner.js";
import { DefaultAlertingManagementDialogContentBasic } from "./DefaultAlertingManagementDialogContentBasic.js";
import { DefaultAlertingManagementDialogContentEnhanced } from "./DefaultAlertingManagementDialogContentEnhanced.js";
/**
 * @alpha
 */
export function DefaultAlertingManagementDialogNew({ onPauseSuccess, onPauseError, onEdit, onAdd, onDeleteSuccess, onDeleteError, onClose, isLoadingAlertingData, automations, }) {
    const [alertToDelete, setAlertToDelete] = useState(null);
    const [alertToPause, setAlertToPause] = useState(null);
    const { features: { enableAutomationManagement }, } = useAutomationsContext();
    const handleAlertDeleteOpen = useCallback((alert) => {
        setAlertToDelete(alert);
    }, []);
    const handleAlertDeleteClose = useCallback(() => {
        setAlertToDelete(null);
    }, []);
    const handleAlertEdit = useCallback((alert) => {
        onEdit?.(alert);
    }, [onEdit]);
    const handleAlertPause = useCallback((alert, pause) => {
        setAlertToPause([alert, pause]);
    }, []);
    const handleAlertDeleteSuccess = useCallback((alert) => {
        onDeleteSuccess?.(alert);
        handleAlertDeleteClose();
    }, [onDeleteSuccess, handleAlertDeleteClose]);
    const handleAlertPauseSuccess = useCallback((alert, pause) => {
        onPauseSuccess?.(alert, pause);
        setAlertToPause(null);
    }, [onPauseSuccess]);
    const handleAlertPauseError = useCallback((err, pause) => {
        onPauseError?.(err, pause);
        setAlertToPause(null);
    }, [onPauseError]);
    return (_jsxs(_Fragment, { children: [enableAutomationManagement ? (_jsx(DefaultAlertingManagementDialogContentEnhanced, { onAdd: onAdd, onClose: onClose, onEdit: handleAlertEdit })) : (_jsx(DefaultAlertingManagementDialogContentBasic, { onClose: onClose, onDelete: handleAlertDeleteOpen, onEdit: handleAlertEdit, onPause: handleAlertPause, isLoadingAlertingData: isLoadingAlertingData, automations: automations })), alertToDelete ? (_jsx(DeleteAlertConfirmDialog, { alert: alertToDelete, onCancel: handleAlertDeleteClose, onSuccess: handleAlertDeleteSuccess, onError: onDeleteError })) : null, alertToPause ? (_jsx(PauseAlertRunner, { alert: alertToPause[0], pause: alertToPause[1], onSuccess: handleAlertPauseSuccess, onError: handleAlertPauseError })) : null] }));
}
