'use client'; import Link from 'next/link'; import { usePathname } from 'next/navigation'; import { useEffect, useRef } from 'react'; import { t } from '@/i18n'; import { cn } from '@/lib/cn'; import { routes } from '@/lib/site'; import { TOPICS } from '@/lib/topics'; /** * Topic navigation for a country: horizontally scrollable chips on mobile, sticky sub-nav on desktop. * The active chip scrolls into view on mount. Counts (optional) show indicators with data per topic. */ export function TopicNav({ slug, counts, sticky = true, className }: { slug: string; counts?: Record; sticky?: boolean; className?: string }) { const pathname = usePathname(); const ref = useRef(null); useEffect(() => { const el = ref.current?.querySelector('[aria-current="page"]'); if (el) el.scrollIntoView({ block: 'nearest', inline: 'center', behavior: 'instant' as ScrollBehavior }); }, [pathname]); const items = [{ id: '', short: t('country.overview'), href: routes.country(slug) }, ...TOPICS.map((tp) => ({ id: tp.id, short: tp.short, href: routes.countryTopic(slug, tp.id) }))]; return ( ); }