import type { ComponentId, LevelId, Trend } from './types'; /** Pressure scale — mirrors packages/config/pressure.yaml (ids/max) and the design palette (colours). */ export const LEVELS: { id: LevelId; max: number; label: string; short: string; color: string }[] = [ { id: 'calm', max: 10, label: 'Exceptionally calm', short: 'Calm', color: '#4CC9F0' }, { id: 'normal', max: 25, label: 'Normal', short: 'Normal', color: '#7FB77E' }, { id: 'elevated', max: 40, label: 'Elevated', short: 'Elevated', color: '#E9C46A' }, { id: 'stressed', max: 55, label: 'Stressed', short: 'Stressed', color: '#F4A261' }, { id: 'high', max: 70, label: 'Highly stressed', short: 'High', color: '#E76F51' }, { id: 'severe', max: 85, label: 'Severe disruption', short: 'Severe', color: '#D62828' }, { id: 'extreme', max: 100, label: 'Extreme Internet event', short: 'Extreme', color: '#F72585' }, ]; export const NEUTRAL = '#0F151D'; export const ACCENT = '#5B8DEF'; export function levelFor(value: number | null | undefined): (typeof LEVELS)[number] { if (value == null || Number.isNaN(value)) return LEVELS[1]!; return LEVELS.find((l) => value <= l.max) ?? LEVELS[LEVELS.length - 1]!; } export function levelById(id: LevelId | string | null | undefined) { return LEVELS.find((l) => l.id === id); } /** Colour for a level id or a numeric pressure value. */ export function pressureColor(levelOrValue: LevelId | number | null | undefined): string { if (levelOrValue == null) return '#3A4756'; if (typeof levelOrValue === 'number') return levelFor(levelOrValue).color; return levelById(levelOrValue)?.color ?? '#3A4756'; } export function levelWord(levelOrValue: LevelId | number | null | undefined): string { if (levelOrValue == null) return '—'; const l = typeof levelOrValue === 'number' ? levelFor(levelOrValue) : levelById(levelOrValue); return (l?.short ?? '—').toUpperCase(); } export const COMPONENT_ORDER: ComponentId[] = ['routing', 'latency', 'dns', 'availability', 'http_tls', 'path', 'corroboration']; export const COMPONENT_LABEL: Record = { routing: 'Routing', latency: 'Latency', dns: 'DNS', availability: 'Availability', http_tls: 'HTTP/TLS', path: 'Path', corroboration: 'Corroboration', }; export function trendArrow(trend: Trend | undefined, delta?: number): string { if (trend === 'rising' || (trend === undefined && (delta ?? 0) > 0)) return '↑'; if (trend === 'falling' || (trend === undefined && (delta ?? 0) < 0)) return '↓'; return '→'; } export const STATUS_COLOR: Record = { detected: '#E9C46A', developing: '#F4A261', active: '#E76F51', recovering: '#4CC9F0', resolved: '#8B98A5', online: '#7FB77E', stale: '#E9C46A', offline: '#D62828', excluded: '#8B98A5', };