'use client';
import { ArrowDown, ArrowUp } from 'lucide-react';
import Link from 'next/link';
import { t } from '@/i18n';
import { cn } from '@/lib/cn';
import { displayValue, isNum, ordinal } from '@/lib/format';
import { routes } from '@/lib/site';
import type { MetricValue } from '@/lib/types';
import type { CompareSnapshotRow, CountryLite } from '@/lib/types-compare';
import { seriesVar } from '@/components/charts/palette';
import { payloadFor } from '@/components/data/metric';
import { useProvenance } from '@/components/data/provenance-context';
import { chartHrefFor } from './snapshot-table';
import type { CompareState } from '@/lib/compare-state';
/**
* Head-to-head view for exactly two countries: the indicator in the middle, one value per side, mirrored bars
* proportional to the larger value, the year under each value, and a thin world-percentile track with both
* countries marked (from rank / n). No "winner" language — a small glyph shows the declared direction only.
*/
export function HeadToHead({ rows, countries, slugs, state }: { rows: CompareSnapshotRow[]; countries: CountryLite[]; slugs: string[]; state: CompareState }) {
const { open } = useProvenance();
const [a, b] = countries;
if (!a || !b) return null;
const visible = rows.filter((r) => r.values[a.id]?.has_data || r.values[b.id]?.has_data);
if (!visible.length) return