import { Activity, AlertTriangle, CheckCircle2, XCircle } from 'lucide-react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { useRunSystemMaintenance, type SystemHealthData } from '@/hooks/useSystemHealth'; import type { DatabaseHealth } from '@/hooks/admin/useDatabaseHealth'; interface SystemHealthStatusProps { systemHealth?: SystemHealthData; dbHealth?: DatabaseHealth; isLoading: boolean; } export function SystemHealthStatus({ systemHealth, dbHealth, isLoading }: SystemHealthStatusProps) { const runMaintenance = useRunSystemMaintenance(); const getOverallStatus = () => { if (isLoading) return 'checking'; if (!systemHealth) return 'unknown'; const hasCriticalIssues = (systemHealth.orphaned_images_count || 0) > 0 || (systemHealth.failed_webhook_count || 0) > 0 || (systemHealth.critical_alerts_count || 0) > 0 || dbHealth?.status === 'unhealthy'; if (hasCriticalIssues) return 'unhealthy'; const hasWarnings = dbHealth?.status === 'warning' || (systemHealth.high_alerts_count || 0) > 0; if (hasWarnings) return 'warning'; return 'healthy'; }; const status = getOverallStatus(); const statusConfig = { healthy: { icon: CheckCircle2, label: 'All Systems Operational', color: 'text-green-500', bgColor: 'bg-green-500/10', borderColor: 'border-green-500/20', }, warning: { icon: AlertTriangle, label: 'System Warning', color: 'text-yellow-500', bgColor: 'bg-yellow-500/10', borderColor: 'border-yellow-500/20', }, unhealthy: { icon: XCircle, label: 'Critical Issues Detected', color: 'text-red-500', bgColor: 'bg-red-500/10', borderColor: 'border-red-500/20', }, checking: { icon: Activity, label: 'Checking System Health...', color: 'text-muted-foreground', bgColor: 'bg-muted', borderColor: 'border-border', }, unknown: { icon: AlertTriangle, label: 'Unable to Determine Status', color: 'text-muted-foreground', bgColor: 'bg-muted', borderColor: 'border-border', }, }; const config = statusConfig[status]; const StatusIcon = config.icon; const handleRunMaintenance = () => { runMaintenance.mutate(); }; return (
System Health {(status === 'unhealthy' || status === 'warning') && ( )}
{config.label} {status.toUpperCase()}
{systemHealth && (
Orphaned Images: {systemHealth.orphaned_images_count || 0}
Failed Webhooks: {systemHealth.failed_webhook_count || 0}
Critical Alerts: {systemHealth.critical_alerts_count || 0}
DB Errors (1h): {dbHealth?.recentErrors || 0}
)}
); }