"use client" import { useState, useEffect } from "react" import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog" import { Badge } from "@/components/ui/badge" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { Loader2, CheckCircle2, AlertTriangle, XCircle, Activity } from "lucide-react" interface HealthCheck { category: string name: string status: "healthy" | "warning" | "critical" value: string message: string details: any } interface HealthDetails { overall: { status: "healthy" | "warning" | "critical" critical_count: number warning_count: number healthy_count: number total_checks: number } checks: HealthCheck[] } interface HealthStatusModalProps { open: boolean onOpenChange: (open: boolean) => void getApiUrl: (path: string) => string } export function HealthStatusModal({ open, onOpenChange, getApiUrl }: HealthStatusModalProps) { const [loading, setLoading] = useState(true) const [healthData, setHealthData] = useState(null) const [error, setError] = useState(null) useEffect(() => { if (open) { fetchHealthDetails() } }, [open]) const fetchHealthDetails = async () => { setLoading(true) setError(null) try { const response = await fetch(getApiUrl("/api/health/details")) if (!response.ok) { throw new Error("Failed to fetch health details") } const data = await response.json() setHealthData(data) } catch (err) { setError(err instanceof Error ? err.message : "Unknown error") } finally { setLoading(false) } } const getStatusIcon = (status: string) => { switch (status) { case "healthy": return case "warning": return case "critical": return default: return } } const getStatusBadge = (status: string) => { switch (status) { case "healthy": return Healthy case "warning": return Warning case "critical": return Critical default: return Unknown } } const groupedChecks = healthData?.checks && Array.isArray(healthData.checks) ? healthData.checks.reduce( (acc, check) => { if (!acc[check.category]) { acc[check.category] = [] } acc[check.category].push(check) return acc }, {} as Record, ) : {} return ( System Health Status Detailed health checks for all system components {loading && (
)} {error && (

Error loading health status

{error}

)} {healthData && !loading && (
{/* Overall Status Summary */} Overall Status {getStatusBadge(healthData.overall.status)}
{healthData.overall.total_checks}
Total Checks
{healthData.overall.healthy_count}
Healthy
{healthData.overall.warning_count}
Warnings
{healthData.overall.critical_count}
Critical
{/* Grouped Health Checks */} {groupedChecks && Object.entries(groupedChecks).map(([category, checks]) => ( {category}
{checks.map((check, index) => (
{getStatusIcon(check.status)}

{check.name}

{check.value}

{check.message}

))}
))}
)}
) }