import { AlertTriangle, ArrowDownRight, ArrowUpRight, GitCommitHorizontal, Repeat, TrendingDown, TrendingUp, Trophy, Waves } from 'lucide-react'; import Link from 'next/link'; import { t, tOpt } from '@/i18n'; import { cn } from '@/lib/cn'; import { formatPeriod } from '@/lib/format'; import { severityLabel, severityLevel } from '@/lib/severity'; import { routes } from '@/lib/site'; import type { ChangeItem } from '@/lib/types'; const ICON: Record = { yoy_jump: ArrowUpRight, yoy_drop: ArrowDownRight, record_high: Trophy, record_low: AlertTriangle, n_year_high: TrendingUp, n_year_low: TrendingDown, sign_flip: Repeat, accelerating: TrendingUp, decelerating: TrendingDown, structural_break: GitCommitHorizontal, trend_reversal: Repeat, volatility_spike: Waves, }; export function kindLabel(kind: string | null | undefined, windowYears?: number | null): string { if (!kind) return ''; return tOpt(`change.kind.${kind}`, kind.replace(/_/g, ' '), { n: windowYears ?? 10 }); } /** * Feed of detected changes/events: kind icon + label, headline, country (optional), period, severity chip. * Server component. `showCountry` for the global feed; `compact` for the timeline. */ export function ChangeList({ items, showCountry = false, className, emptyText }: { items: ChangeItem[]; showCountry?: boolean; className?: string; emptyText?: string }) { if (items.length === 0) return

{emptyText ?? t('country.changes.none')}

; return (
    {items.map((c, i) => { const Icon = ICON[c.kind ?? ''] ?? ArrowUpRight; const lvl = severityLevel(c.severity); const indSlug = (c.indicator as { slug?: string; id: string }).slug ?? c.indicator.id; const href = c.country?.slug ? routes.country(c.country.slug) : routes.indicator(indSlug); return (
  1. {kindLabel(c.kind, c.window_years)} {c.period ? {formatPeriod(c.period, 'A')} : null} {severityLabel(c.severity)}
    {showCountry && c.country ? ( {c.country.flag} {c.country.name} ) : null} {c.headline ?? `${'name' in c.indicator ? c.indicator.name : indSlug}: ${c.formatted ?? ''}`}
  2. ); })}
); }