'use client' import * as React from 'react' import { CheckIcon, ChevronsUpDown } from 'lucide-react' import { cn } from '@/lib/utils' import { Button } from '@/components/ui/button' import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from '@/components/ui/command' import { Popover, PopoverContent, PopoverTrigger, } from '@/components/ui/popover' import { ScrollArea } from '@/components/ui/scroll-area' import { COUNTRIES } from '@/lib/countries' // Build sorted country list from the canonical COUNTRIES source const countryList = Object.entries(COUNTRIES) .map(([code, info]) => ({ code, name: info.name })) .sort((a, b) => a.name.localeCompare(b.name)) /** Renders a country flag image from flagcdn.com CDN */ function CountryFlagImg({ code, size = 20, className }: { code: string; size?: number; className?: string }) { return ( {code} ) } export type Country = { code: string; name: string } interface CountrySelectProps { value?: string onChange?: (value: string) => void placeholder?: string disabled?: boolean className?: string } const CountrySelect = React.forwardRef( ({ value, onChange, placeholder = 'Select country...', disabled, className }, ref) => { const [open, setOpen] = React.useState(false) const selectedCountry = countryList.find((c) => c.code === value) return ( No country found. {countryList.map((country) => ( { onChange?.(country.code) setOpen(false) }} className="gap-2" > {country.name} ))} ) } ) CountrySelect.displayName = 'CountrySelect' export { CountrySelect, countryList as countries, CountryFlagImg }