import React from 'react'; export interface MetricCard { label: string; value: number | string; /** previous period value for trend calculation */ previousValue?: number; currentValue?: number; /** When true, a decrease is good (green) and an increase is bad (red). Use for error counts, latency, etc. */ lowerIsBetter?: boolean; } function TrendBadge({ current, previous, lowerIsBetter = false }: { current: number; previous: number; lowerIsBetter?: boolean }): React.ReactElement { if (previous === 0 && current === 0) { return ; } const upColor = lowerIsBetter ? 'text-red-600' : 'text-green-600'; const downColor = lowerIsBetter ? 'text-green-600' : 'text-red-600'; if (current > previous) { const pct = previous > 0 ? Math.round(((current - previous) / previous) * 100) : 100; return ( ↑ {pct}% ); } if (current < previous) { const pct = previous > 0 ? Math.round(((previous - current) / previous) * 100) : 100; return ( ↓ {pct}% ); } return ; } function SkeletonCard(): React.ReactElement { return (
); } interface MetricsGridProps { cards: MetricCard[]; loading: boolean; } export function MetricsGrid({ cards, loading }: MetricsGridProps): React.ReactElement { if (loading) { return (
{[0, 1, 2, 3].map((i) => ( ))}
); } return (
{cards.map((card) => (

{card.label}

{card.value}

{card.currentValue !== undefined && card.previousValue !== undefined && (
vs prev 24h
)}
))}
); }