import Link from 'next/link'; import { cn } from '@/lib/cn'; import { EVENT_TYPE_LABELS, routes } from '@/lib/site'; import type { EventEntity } from '@/lib/types'; /** Event type → colour token. Launch = accent, decay/reentry = warn, orbit change = accent-2, decommission = danger, activation = active. */ export const EVENT_TYPE_COLORS: Record = { SATELLITE_LAUNCH: 'var(--accent)', DECAY: 'var(--warn)', REENTRY: 'var(--warn)', ORBIT_CHANGE: 'var(--accent-2)', SATELLITE_DECOMMISSION: 'var(--danger)', SATELLITE_ACTIVATION: 'var(--active)', CONSTELLATION_EXPANSION: 'var(--accent)', REGULATORY_APPROVAL: 'var(--series-4)', NEW_LICENSE: 'var(--series-4)', COMPANY_ANNOUNCEMENT: 'var(--inactive)', }; export function eventColor(type: string): string { return EVENT_TYPE_COLORS[type] ?? 'var(--inactive)'; } export function eventLabel(type: string): string { return EVENT_TYPE_LABELS[type] ?? type.replace(/_/g, ' ').toLowerCase().replace(/\b\w/g, (c) => c.toUpperCase()); } export function EventTypeBadge({ type, className, size = 'sm' }: { type: string; className?: string; size?: 'sm' | 'md' }) { const color = eventColor(type); return ( {eventLabel(type)} ); } /** Confidence as a mono percentage; tooltip explains it is derived. */ export function Confidence({ value, className }: { value: number | null | undefined; className?: string }) { if (value === null || value === undefined || !Number.isFinite(value)) return —; const pct = Math.round(value * 100); const color = pct >= 90 ? 'var(--active)' : pct >= 60 ? 'var(--warn)' : 'var(--danger)'; return ( {pct}% ); } export function entityHref(e: EventEntity): string | null { if (!e.slug) return null; switch (e.type) { case 'satellite': return routes.satellite(e.slug); case 'launch': return routes.launch(e.slug); case 'constellation': return routes.constellation(e.slug); case 'operator': return routes.operator(e.slug); case 'country': return routes.country(e.slug); case 'launch_site': return routes.launchSite(e.slug); default: return null; } } export function entityName(e: EventEntity): string { if (e.type === 'launch') return `Launch ${e.slug ?? e.id}`; return e.name ?? e.slug ?? e.id; } /** Inline list of entity links: satellite → /satellite/, launch → /launch/. */ export function EntityLinks({ entities, className, max = 6 }: { entities: EventEntity[] | null | undefined; className?: string; max?: number }) { if (!entities?.length) return null; const shown = entities.slice(0, max); return (
    {shown.map((e) => { const href = entityHref(e); const label = entityName(e); return (
  • {e.type.replace('_', ' ')} {href ? ( {label} ) : ( {label} )} {e.norad_id ? #{e.norad_id} : null}
  • ); })} {entities.length > max &&
  • +{entities.length - max} more
  • }
); }