'use client'

import { getCountryFlag, getCountryName, normalizeCountryToCode } from '@/lib/countries'

/**
 * Displays a country flag emoji followed by the country name.
 * Accepts either an ISO-2 code or a full country name.
 */
export function CountryDisplay({
  country,
  showName = true,
  className,
}: {
  country: string | null | undefined
  showName?: boolean
  className?: string
}) {
  if (!country) return null

  const code = normalizeCountryToCode(country)
  const flag = code ? getCountryFlag(code) : null
  const name = code ? getCountryName(code) : country

  return (
    <span className={className}>
      {flag && <span className="mr-1">{flag}</span>}
      {showName && name}
    </span>
  )
}
