'use client' import { formatNumber } from '@/lib/utils/format' import * as Flags from 'country-flag-icons/react/3x2' interface CountriesProps { countries: Array<{ country: string; pageviews: number }> } export default function Countries({ countries }: CountriesProps) { if (!countries || countries.length === 0) { return (

Countries

No data available

) } const getFlagComponent = (countryCode: string) => { if (!countryCode || countryCode === 'Unknown') return null // * The API returns 2-letter country codes (e.g. US, DE) // * We cast it to the flag component name const FlagComponent = (Flags as any)[countryCode] return FlagComponent ? : null } const getCountryName = (code: string) => { if (!code || code === 'Unknown') return 'Unknown' try { const regionNames = new Intl.DisplayNames(['en'], { type: 'region' }) return regionNames.of(code) || code } catch (e) { return code } } return (

Countries

{countries.map((country, index) => (
{getFlagComponent(country.country)} {getCountryName(country.country)}
{formatNumber(country.pageviews)}
))}
) }