const COUNTRY_OPTIONS = [
  { code: 'AR', name: 'Argentinien' },
  { code: 'AU', name: 'Australien' },
  { code: 'AT', name: 'Österreich' },
  { code: 'BE', name: 'Belgien' },
  { code: 'BA', name: 'Bosnien und Herzegowina' },
  { code: 'BR', name: 'Brasilien' },
  { code: 'BG', name: 'Bulgarien' },
  { code: 'CA', name: 'Kanada' },
  { code: 'CL', name: 'Chile' },
  { code: 'CN', name: 'China' },
  { code: 'CO', name: 'Kolumbien' },
  { code: 'CZ', name: 'Tschechien' },
  { code: 'DK', name: 'Dänemark' },
  { code: 'DE', name: 'Deutschland' },
  { code: 'EE', name: 'Estland' },
  { code: 'FI', name: 'Finnland' },
  { code: 'FR', name: 'Frankreich' },
  { code: 'GR', name: 'Griechenland' },
  { code: 'GB', name: 'Vereinigtes Königreich' },
  { code: 'IE', name: 'Irland' },
  { code: 'IS', name: 'Island' },
  { code: 'IN', name: 'Indien' },
  { code: 'IT', name: 'Italien' },
  { code: 'JP', name: 'Japan' },
  { code: 'HR', name: 'Kroatien' },
  { code: 'LV', name: 'Lettland' },
  { code: 'LI', name: 'Liechtenstein' },
  { code: 'LT', name: 'Litauen' },
  { code: 'LU', name: 'Luxemburg' },
  { code: 'MT', name: 'Malta' },
  { code: 'MX', name: 'Mexiko' },
  { code: 'NL', name: 'Niederlande' },
  { code: 'NZ', name: 'Neuseeland' },
  { code: 'NO', name: 'Norwegen' },
  { code: 'PL', name: 'Polen' },
  { code: 'PT', name: 'Portugal' },
  { code: 'RO', name: 'Rumänien' },
  { code: 'SE', name: 'Schweden' },
  { code: 'CH', name: 'Schweiz' },
  { code: 'SK', name: 'Slowakei' },
  { code: 'SI', name: 'Slowenien' },
  { code: 'ES', name: 'Spanien' },
  { code: 'ZA', name: 'Südafrika' },
  { code: 'KR', name: 'Südkorea' },
  { code: 'TR', name: 'Türkei' },
  { code: 'UA', name: 'Ukraine' },
  { code: 'HU', name: 'Ungarn' },
  { code: 'US', name: 'Vereinigte Staaten' }
];

export const countryOptions = [...COUNTRY_OPTIONS].sort((left, right) =>
  left.name.localeCompare(right.name, 'de')
);

export const getCountryOption = (value = '') => {
  const normalizedValue = String(value || '').trim().toUpperCase();
  if (!normalizedValue) return null;

  return countryOptions.find((country) => country.code === normalizedValue) || null;
};

export const getCountryLabel = (value = '') => {
  const option = getCountryOption(value);
  if (option) return option.name;
  return String(value || '').trim();
};
