import { Alert, Button, Chip, Modal } from "@heroui/react"; import { useMutation } from "@tanstack/react-query"; import { connectTestManagedNe } from "../../services/api"; import { AppModalShell } from "../../components/ui/AppModalShell"; import { useI18n } from "../../i18n"; import { formatSystemTime } from "../../utils/time"; import type { ManagedNeItem } from "../../types"; import { connectPillLevel } from "./connectStatus"; export type ManagedNeConnectDetailDialogProps = { row: ManagedNeItem | null; onClose: () => void; /** Called after a retest is submitted so parent can refresh/poll. */ onRetestSubmitted?: (rowId: string) => void; }; function chipColor(level: string): "success" | "danger" | "warning" | "default" { if (level === "up" || level === "pass") return "success"; if (level === "down" || level === "fail") return "danger"; if (level === "testing") return "warning"; return "default"; } export function ManagedNeConnectDetailDialog({ row, onClose, onRetestSubmitted, }: ManagedNeConnectDetailDialogProps) { const { t } = useI18n(); const connectMutation = useMutation({ mutationFn: connectTestManagedNe, onSuccess: () => { if (row) onRetestSubmitted?.(row.id); }, }); const open = Boolean(row); const level = row ? connectPillLevel(row.connect_status) : "unknown"; return ( {t("managedNe.connectDetailTitle")} {row ? ( <>

{row.name || row.ip_address} · {row.ip_address}:{row.port}/{row.protocol} {row.connect_tested_at ? ` · ${formatSystemTime(row.connect_tested_at, { assumeUtcNaive: true })}` : ""}

{row.connect_status} {row.connect_message ? ( — {row.connect_message} ) : null}
              {row.connect_detail?.trim() ||
                row.connect_message?.trim() ||
                t("managedNe.connectDetailEmpty")}
            
) : null} {connectMutation.isError ? ( {String(connectMutation.error)} ) : null}
); }