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 { FormattedMessage, defineMessage, useIntl } from "react-intl";
import { Button, Dialog, Hyperlink, Typography, useId } from "@gooddata/sdk-ui-kit";
import { messages } from "../../../locales.js";
import { useDashboardSelector } from "../../../model/react/DashboardStoreProvider.js";
import { selectIsWhiteLabeled } from "../../../model/store/config/configSelectors.js";
import { isMobileView } from "../DefaultAlertingDialog/utils/responsive.js";
import { AlertsOld } from "./components/AlertsListOld.js";
import { DeleteAlertConfirmDialog } from "./components/DeleteAlertConfirmDialog.js";
import { PauseAlertRunner } from "./components/PauseAlertRunner.js";
/**
 * @alpha
 */
export function DefaultAlertingManagementDialogOld({ onPauseSuccess, onPauseError, onEdit, onDeleteSuccess, onDeleteError, onClose, isLoadingAlertingData, automations, }) {
    const [alertToDelete, setAlertToDelete] = useState(null);
    const [alertToPause, setAlertToPause] = useState(null);
    const intl = useIntl();
    const isWhiteLabeled = useDashboardSelector(selectIsWhiteLabeled);
    const handleAlertDelete = useCallback((alert) => {
        setAlertToDelete(alert);
    }, []);
    const handleAlertEdit = useCallback((alert, widget, anchor, onClosed) => {
        onEdit?.(alert, widget, anchor, onClosed);
    }, [onEdit]);
    const handleAlertPause = useCallback((alert, pause) => {
        setAlertToPause([alert, pause]);
    }, []);
    const handleAlertDeleteSuccess = (alert) => {
        onDeleteSuccess?.(alert);
        setAlertToDelete(null);
    };
    const handleAlertPauseSuccess = (alert, pause) => {
        onPauseSuccess?.(alert, pause);
        setAlertToPause(null);
    };
    const handleAlertPauseError = (err, pause) => {
        onPauseError?.(err, pause);
        setAlertToPause(null);
    };
    const helpTextId = isMobileView()
        ? defineMessage({ id: "dialogs.alerting.footer.title.short" }).id
        : defineMessage({ id: "dialogs.alerting.footer.title" }).id;
    const titleElementId = useId();
    return (_jsxs(_Fragment, { children: [
            _jsxs(Dialog, { displayCloseButton: true, onCancel: onClose, shouldCloseOnClick: () => false, className: "gd-notifications-channels-management-dialog s-alerting-management-dialog", accessibilityConfig: { titleElementId, isModal: true }, children: [
                    _jsx("div", { className: "gd-notifications-channels-management-dialog-title", children: _jsx(Typography, { tagName: "h3", className: "gd-dialog-header", id: titleElementId, children: _jsx(FormattedMessage, { id: "dialogs.alerting.management.title" }) }) }), _jsxs("div", { className: "gd-notifications-channels-content", children: [
                            _jsx("div", { className: "gd-notifications-channels-content-header", children: _jsx(Typography, { tagName: "h3", children: _jsx(FormattedMessage, { id: messages.alertingManagementListTitle.id }) }) }), _jsx(AlertsOld, { onDelete: handleAlertDelete, onEdit: handleAlertEdit, onPause: handleAlertPause, isLoading: isLoadingAlertingData, alerts: automations, noAlertsMessageId: messages.alertingManagementNoAlerts.id })
                        ] }), _jsx("div", { className: "gd-content-divider" }), _jsxs("div", { className: "gd-buttons", children: [isWhiteLabeled ? null : (_jsx(Hyperlink, { text: intl.formatMessage({ id: helpTextId }), href: "https://www.gooddata.com/docs/cloud/create-dashboards/automation/alerts/", iconClass: "gd-icon-circle-question" })), _jsx(Button, { onClick: onClose, className: "gd-button-secondary s-close-button", value: intl.formatMessage({ id: "close" }) })
                        ] })
                ] }), alertToDelete ? (_jsx(DeleteAlertConfirmDialog, { alert: alertToDelete, onCancel: () => setAlertToDelete(null), onSuccess: handleAlertDeleteSuccess, onError: onDeleteError })) : null, alertToPause ? (_jsx(PauseAlertRunner, { alert: alertToPause[0], pause: alertToPause[1], onSuccess: handleAlertPauseSuccess, onError: handleAlertPauseError })) : null] }));
}
//# sourceMappingURL=DefaultAlertingManagementDialogOld.js.map