import { Card } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { useBackendHealth } from '@/hooks/useBackendHealth'; import { useHealthAlerts } from '@/hooks/useHealthAlerts'; import { HealthAlertSettings } from '@/components/HealthAlertSettings'; import { AlertCircle, CheckCircle, RefreshCw, XCircle, Clock, AlertTriangle, Settings } from 'lucide-react'; import { formatDistanceToNow } from 'date-fns'; import { useState } from 'react'; export function BackendHealthMonitor() { const { healthReport, loading, lastChecked, refresh } = useBackendHealth(true, 60000); const { config, updateConfig, clearAlertHistory } = useHealthAlerts(healthReport); const [showSettings, setShowSettings] = useState(false); const getStatusIcon = (status: string) => { switch (status) { case 'healthy': return ; case 'degraded': return ; case 'unhealthy': return ; case 'not_configured': case 'skipped': return ; default: return ; } }; const getStatusBadge = (status: string) => { const variants: { [key: string]: any } = { healthy: 'default', degraded: 'secondary', unhealthy: 'destructive', not_configured: 'outline', skipped: 'outline', }; return ( {status} ); }; return (

Backend Health Monitor

{healthReport && ( {healthReport.overall_status} )}
{lastChecked && (
{formatDistanceToNow(lastChecked, { addSuffix: true })}
)}
{!healthReport && loading && (

Running health checks...

)} {healthReport && (
{/* Errors */} {healthReport.errors.length > 0 && (

Critical Issues

    {healthReport.errors.map((error, i) => (
  • • {error}
  • ))}
)} {/* Warnings */} {healthReport.warnings.length > 0 && (

Warnings

    {healthReport.warnings.map((warning, i) => (
  • • {warning}
  • ))}
)} {/* Individual Checks */}
{Object.entries(healthReport.checks).map(([key, check]) => (
{getStatusIcon(check.status)}

{key.replace(/_/g, ' ').replace('edge function ', '')}

{check.message}

{getStatusBadge(check.status)}
))}
)}
{showSettings && ( )}
); }