import { useMemo } from 'react' import { Activity, AlertCircle, CheckCircle2 } from 'lucide-react' import { useTranslation } from 'react-i18next' import { cn } from '@/lib/utils' import { Tooltip, TooltipContent, TooltipTrigger, } from '@/components/ui/tooltip' import { formatUptimePct } from '@/features/performance-metrics/lib/format' import { aggregateUptime, type UptimeDayPoint } from '../lib/mock-stats' // --------------------------------------------------------------------------- // Uptime sparkline // --------------------------------------------------------------------------- // // Compact 30-day uptime visualisation: a row of small coloured bars where: // - Bar colour reflects per-day uptime (green / amber / red) // - Bar height reflects severity (the worse the day, the shorter the bar) // - Hovering a bar reveals the exact date and uptime // // Useful as a header strip ("at-a-glance" status) and as a per-row visual // inside the per-group performance table. type SparklineSize = 'sm' | 'md' type UptimeSparklineProps = { series: UptimeDayPoint[] size?: SparklineSize showOverall?: boolean emptyLabel?: string className?: string } function colourFor(uptime: number): string { if (uptime >= 99.9) return 'bg-emerald-500' if (uptime >= 99.0) return 'bg-emerald-400' if (uptime >= 95.0) return 'bg-amber-500' if (uptime >= 90.0) return 'bg-amber-600' return 'bg-rose-500' } function heightFor(uptime: number): string { if (uptime >= 99.9) return 'h-full' if (uptime >= 99.0) return 'h-[88%]' if (uptime >= 95.0) return 'h-[72%]' if (uptime >= 90.0) return 'h-[55%]' return 'h-[40%]' } function overallTextColour(pct: number): string { if (pct >= 99.9) return 'text-emerald-600 dark:text-emerald-400' if (pct >= 99.0) return 'text-emerald-600 dark:text-emerald-400' if (pct >= 95.0) return 'text-amber-600 dark:text-amber-400' return 'text-rose-600 dark:text-rose-400' } export function UptimeSparkline(props: UptimeSparklineProps) { const size = props.size ?? 'md' const showOverall = props.showOverall ?? true if (props.series.length === 0) { return ( {props.emptyLabel ?? '—'} ) } const overall = props.series.reduce((s, p) => s + p.uptime_pct, 0) / props.series.length const containerHeight = size === 'sm' ? 'h-3.5' : 'h-5' const barWidth = size === 'sm' ? 'w-[3px]' : 'w-1' const gap = size === 'sm' ? 'gap-px' : 'gap-[2px]' return (