'use client' import Link from 'next/link' import { AlertCircle, AlertTriangle, Zap, TrendingUp, TrendingDown, Minus, RefreshCw, Loader2, Building2, Server as ServerIcon, ArrowRight, } from 'lucide-react' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { Button } from '@/components/ui/button' import { useAllClientsErrorSummary } from '@/hooks/use-enterprise-clients' const TREND_CONFIG = { increasing: { icon: TrendingUp, color: 'text-red-600', bg: 'bg-red-50', label: 'increasing', }, decreasing: { icon: TrendingDown, color: 'text-green-600', bg: 'bg-green-50', label: 'decreasing', }, stable: { icon: Minus, color: 'text-slate-600', bg: 'bg-slate-50', label: 'stable', }, } export function EnterpriseErrorSummaryWidget() { const { data, isLoading, isError, refetch, isFetching } = useAllClientsErrorSummary() if (isLoading) { return ( ) } if (isError || !data) { return ( Failed to load error summary refetch()}> Retry ) } const { totals, clients } = data const hasCriticalIssues = totals.criticalErrors24h > 0 || totals.crashes24h > 0 const clientsWithIssues = clients.filter( (c) => c.criticalErrors24h > 0 || c.crashes24h > 0 ).slice(0, 3) const trendConfig = TREND_CONFIG[totals.overallTrend] const TrendIcon = trendConfig.icon return ( System Health {hasCriticalIssues && ( )} refetch()} disabled={isFetching} className="h-8 w-8 p-0" > {/* Main Stats */} Critical Errors (24h) 0 ? 'text-red-600' : 'text-muted-foreground'}`} /> 0 ? 'text-red-600' : ''}`}> {totals.criticalErrors24h} Crashed Containers (24h) 0 ? 'text-orange-600' : 'text-muted-foreground'}`} /> 0 ? 'text-orange-600' : ''}`}> {totals.crashes24h} {/* Trend */} Error trend: {trendConfig.label} ({totals.totalErrors24h} total errors today) {/* Clients with Issues */} {clientsWithIssues.length > 0 && ( Clients with Issues ({totals.clientsWithIssues} total) {clientsWithIssues.map((client) => ( {client.clientName} {client.criticalErrors24h > 0 && ( {client.criticalErrors24h} critical )} {client.crashes24h > 0 && ( {client.crashes24h} crashed )} ))} )} {/* No Issues State */} {clientsWithIssues.length === 0 && totals.totalClients > 0 && ( All {totals.totalClients} clients are healthy )} {/* No Clients State */} {totals.totalClients === 0 && ( No enterprise clients configured )} ) }
Failed to load error summary
Critical Errors (24h)
Crashed Containers (24h)
Clients with Issues ({totals.clientsWithIssues} total)