'use client'; import { ArrowLeftRight } from 'lucide-react'; import { useRouter } from 'next/navigation'; import { t } from '@/i18n'; import { routes } from '@/lib/site'; import type { RegionItem } from '@/lib/types-explore'; const KIND_ORDER = ['world', 'region', 'continent', 'income', 'org']; /** Two group selects (grouped by kind) → /regions/compare?a=&b=. Also used inline on a group page with `fixedA`. */ export function GroupComparePicker({ groups, a, b, fixedA = false }: { groups: RegionItem[]; a: string; b: string; fixedA?: boolean }) { const router = useRouter(); const go = (na: string, nb: string) => router.push(routes.regionCompare(na, nb)); const byKind = KIND_ORDER.map((k) => ({ kind: k, items: groups.filter((g) => (g.kind ?? 'custom') === k).sort((x, y) => (x.name ?? '').localeCompare(y.name ?? '')) })).filter((g) => g.items.length); const select = (value: string, onChange: (v: string) => void, label: string) => ( ); return (
{fixedA ? {groups.find((g) => g.slug === a)?.name ?? a} : select(a, (v) => go(v, b), t('regions.compare.a'))} {select(b, (v) => go(a, v), t('regions.compare.b'))}
); }