import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { CheckCircle2, RotateCcw } from 'lucide-react'; import { useStackRestartMap } from './useStackRestartMap'; import type { StackRestartSummary } from './useStackRestartMap'; type DominantCategory = 'crash' | 'autoheal' | 'manual'; function dominantCategory(entry: StackRestartSummary): DominantCategory { if (entry.crash >= entry.autoheal && entry.crash >= entry.manual) return 'crash'; if (entry.autoheal >= entry.manual) return 'autoheal'; return 'manual'; } const CATEGORY_LABELS: Record = { crash: 'crash', autoheal: 'auto-heal', manual: 'manual', }; const CATEGORY_CLASSES: Record = { crash: 'border-destructive/30 bg-destructive/10 text-destructive', autoheal: 'border-success/30 bg-success/10 text-success', manual: 'border-brand/30 bg-brand/10 text-brand', }; const CATEGORY_BAR_CLASSES: Record = { crash: 'bg-destructive/50', autoheal: 'bg-success/50', manual: 'bg-brand/50', }; function CategoryBadge({ category }: { category: DominantCategory }) { return ( {CATEGORY_LABELS[category]} ); } function SkeletonRow() { return (
); } export function StackRestartMap() { const { restarts, loading, error } = useStackRestartMap(); if (loading) { return ( Stack Restarts (7d) {Array.from({ length: 4 }).map((_, i) => )} ); } if (error) { return ( Stack Restarts (7d)

Unable to load restart data.

); } const withRestarts = restarts.filter(s => s.total > 0); const stableCount = restarts.length - withRestarts.length; const maxTotal = withRestarts.reduce((m, s) => Math.max(m, s.total), 1); return (
Stack Restarts (7d)
{withRestarts.length === 0 ? (
No restarts in the last 7 days.
) : (
{withRestarts.map(entry => { const category = dominantCategory(entry); const barWidth = Math.round((entry.total / maxTotal) * 100); return (
{entry.stackName} {entry.total}
); })} {stableCount > 0 && (
{stableCount} stack{stableCount !== 1 ? 's' : ''} stable
)}
)} ); }