'use client'; import { Activity, CheckCircle, AlertCircle, XCircle, Globe, Server } from 'lucide-react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/Card'; import { useSystemHealth } from '@/hooks/useDashboardData'; type HealthSite = { status?: string }; type HealthResource = { status?: string }; export function SystemHealthTile() { const { data, loading, error } = useSystemHealth(); // Calculate health data from API response const healthData = data ? { regions: { total: data.sites?.length || 0, healthy: data.sites?.filter((s: HealthSite) => s.status === 'ACTIVE').length || 0, warning: data.sites?.filter((s: HealthSite) => s.status === 'MAINTENANCE').length || 0, critical: data.sites?.filter((s: HealthSite) => s.status === 'INACTIVE').length || 0, }, clusters: { total: data.resources?.length || 0, healthy: data.resources?.filter((r: HealthResource) => r.status === 'RUNNING').length || 0, warning: data.resources?.filter((r: HealthResource) => r.status === 'PROVISIONING').length || 0, critical: data.resources?.filter((r: HealthResource) => r.status === 'ERROR').length || 0, }, nodes: { total: data.resources?.length || 0, healthy: data.resources?.filter((r: HealthResource) => r.status === 'RUNNING').length || 0, warning: data.resources?.filter((r: HealthResource) => r.status === 'PROVISIONING').length || 0, critical: data.resources?.filter((r: HealthResource) => r.status === 'ERROR').length || 0, }, } : { regions: { total: 0, healthy: 0, warning: 0, critical: 0 }, clusters: { total: 0, healthy: 0, warning: 0, critical: 0 }, nodes: { total: 0, healthy: 0, warning: 0, critical: 0 }, }; if (loading) { return ( System Health Overview Loading... ); } if (error) { return ( System Health Overview Error loading health data ); } const overallHealth = healthData.regions.healthy / healthData.regions.total > 0.95 ? 'healthy' : healthData.regions.healthy / healthData.regions.total > 0.85 ? 'warning' : 'critical'; return ( System Health Overview {overallHealth === 'healthy' ? 'Healthy' : overallHealth === 'warning' ? 'Warning' : 'Critical'} Regions {healthData.regions.total} {healthData.regions.healthy} {healthData.regions.warning > 0 && ( {healthData.regions.warning} )} {healthData.regions.critical > 0 && ( {healthData.regions.critical} )} Clusters {healthData.clusters.total} {healthData.clusters.healthy} {healthData.clusters.warning > 0 && ( {healthData.clusters.warning} )} Nodes {healthData.nodes.total} {healthData.nodes.healthy} {healthData.nodes.warning > 0 && ( {healthData.nodes.warning} )} {healthData.nodes.critical > 0 && ( {healthData.nodes.critical} )} ); }
Regions
{healthData.regions.total}
Clusters
{healthData.clusters.total}
Nodes
{healthData.nodes.total}