// Based on https://stackoverflow.com/questions/42234666/

const flagOffset = 0x1f1e6;
const asciiOffset = 0x41;
const flagShift = flagOffset - asciiOffset;

const flagLookup = country => {
  if (country === null || country === undefined) {
    return "🌎";
  }
  const upper = country.toUpperCase();
  const firstChar = upper.charCodeAt(0) + flagShift;
  const secondChar = upper.charCodeAt(1) + flagShift;
  return String.fromCodePoint(firstChar, secondChar);
};

export default flagLookup;
