import { useState } from 'react'; import type { Locale, Service } from '../types'; import { formatDuration, formatPercent, formatTime, translations } from '../lib/i18n'; import { ArrowRight, Statistics as StatisticsIcon } from './Icons'; import { ResponseChart } from './Charts'; export function ReliabilityMetrics({ service, locale }: { service: Service; locale: Locale }) { const t = translations[locale], stats = service.reliability; const duration = (value: number | null) => `${stats.downtimeIncomplete && value !== null ? '≥ ' : ''}${formatDuration(value, locale)}`; return <>
{t.measuredDowntime}
{duration(stats.downtimeMs)}
{t.confirmedIncidents}: {stats.incidentCount}
{t.longestOutage}
{duration(stats.longestDowntimeMs)}
{t.lastRecovery}
{stats.lastRecoveryAt === null ? t.noRecovery : formatTime(stats.lastRecoveryAt, locale, true)}
{stats.lastRecoveryScope && {stats.lastRecoveryScope === 'scenario' ? t.scenarioTitle : t.basicCheck}}

{t.timeCoverage}: {stats.observedMs > 0 && stats.coverage < .1 ? `<${formatPercent(.1, locale)}` : formatPercent(stats.coverage, locale)}{stats.downtimeIncomplete && <> · {t.incompleteDowntime}}

; } export function StatisticsPanel({ services, locale, range, onDetails }: { services: Service[]; locale: Locale; range: number; onDetails: (id: string) => void }) { const t = translations[locale]; const [selected, setSelected] = useState(services[0]?.id || 'api'); const [period, setPeriod] = useState<'24h' | 'range'>('24h'); const service = services.find(item => item.id === selected) || services[0]; if (!service) return null; const latency = period === '24h' ? service.latency24h : service.latency; const points = period === '24h' ? service.responseHistory : service.latencyHistory; const change = latency.changePercent; return

{t.statisticsTitle}

{t.statisticsDescription}

{range} {t.days}
{services.map(item => )}

{t.statisticsMethod}

{t.latencyTrend}

{t.periodAverage}{latency.averageMs === null ? '—' : `${latency.averageMs} ${t.ms}`}
{t.latencyPercentile}{latency.p95Ms === null ? '—' : `${latency.p95Ms} ${t.ms}`}
0 ? 'slower' : 'faster'}`}>{t.latencyComparison}{change === null ? '—' : `${change > 0 ? '+' : ''}${change.toLocaleString(locale)}%`}{change === null && {t.latencyNoComparison}}
{latency.samples.toLocaleString(locale)} {t.measurements}
; }