import countries from '../../data/countries';
import { longestMatchingPrefix } from '../longestMatchingPrefix';

export const findCountryByCode = (code: string) => {
  if (code.length === 2) {
    const matchingCodes = countries.filter((country) => code.toUpperCase() === country.iso2);
    if (matchingCodes.length > 0) {
      return longestMatchingPrefix(matchingCodes);
    }
  }
  return null;
};
