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

export const findCountryByPrefix = (number: string) => {
  if (number.length > 1) {
    const matchingCodes = countries.filter((country) => number.startsWith(country.phone));
    if (matchingCodes.length > 0) {
      return longestMatchingPrefix(matchingCodes);
    }
  }
  return null;
};
