import { useId, useState } from 'react'; export type Country = { code: string; name: string; name_en: string }; export default function CountrySelect({ countries, value, onChange, id, disabled = false, label = 'País', required = false, allowLegacyValue = false, error, }: { countries: Country[]; value: string; onChange: (value: string) => void; id?: string; disabled?: boolean; label?: string; required?: boolean; allowLegacyValue?: boolean; error?: string; }) { const generatedId = useId(); const [search, setSearch] = useState(''); const matches = countries.filter( (country) => country.code === value || `${country.name} ${country.name_en} ${country.code}` .normalize('NFD') .replace(/\p{Diacritic}/gu, '') .toLowerCase() .includes( search .normalize('NFD') .replace(/\p{Diacritic}/gu, '') .toLowerCase(), ), ); return (
Países:{' '} {matches.length ? `${matches.length} opções disponíveis` : 'Nenhuma opção encontrada'}
)} {error && ({error}
)} {matches.length === 0 && (Nenhum país corresponde à pesquisa.
)}