import { makeEnumLike } from '@roostorg/coop-types';

// https://gist.github.com/jrnk/8eb57b065ea0b098d571
export const ISO_LANG_MAP = {
  aa: 'AFAR',
  ab: 'ABKHAZIAN',
  ae: 'AVESTAN',
  af: 'AFRIKAANS',
  ak: 'AKAN',
  am: 'AMHARIC',
  an: 'ARAGONESE',
  ar: 'ARABIC',
  as: 'ASSAMESE',
  av: 'AVARIC',
  ay: 'AYMARA',
  az: 'AZERBAIJANI',
  ba: 'BASHKIR',
  be: 'BELARUSIAN',
  bg: 'BULGARIAN',
  bh: 'BIHARI',
  bi: 'BISLAMA',
  bm: 'BAMBARA',
  bn: 'BENGALI',
  bo: 'TIBETAN',
  br: 'BRETON',
  bs: 'BOSNIAN',
  ca: 'CATALAN',
  ce: 'CHECHEN',
  ch: 'CHAMORRO',
  co: 'CORSICAN',
  cr: 'CREE',
  cs: 'CZECH',
  cu: 'CHURCH_SLAVIC',
  cv: 'CHUVASH',
  cy: 'WELSH',
  da: 'DANISH',
  de: 'GERMAN',
  dv: 'DHIVEHI',
  dz: 'DZONGKHA',
  ee: 'EWE',
  el: 'GREEK',
  en: 'ENGLISH',
  eo: 'ESPERANTO',
  es: 'SPANISH',
  et: 'ESTONIAN',
  eu: 'BASQUE',
  fa: 'PERSIAN',
  ff: 'FULAH',
  fi: 'FINNISH',
  fj: 'FIJIAN',
  fo: 'FAROESE',
  fr: 'FRENCH',
  fy: 'WESTERN_FRISIAN',
  ga: 'IRISH',
  gd: 'GAELIC',
  gl: 'GALICIAN',
  gn: 'GUARANI',
  gu: 'GUJARATI',
  gv: 'MANX',
  ha: 'HAUSA',
  he: 'HEBREW',
  hi: 'HINDI',
  ho: 'HIRI_MOTU',
  hr: 'CROATIAN',
  ht: 'HAITIAN',
  hu: 'HUNGARIAN',
  hy: 'ARMENIAN',
  hz: 'HERERO',
  ia: 'INTERLINGUA',
  id: 'INDONESIAN',
  ig: 'IGBO',
  ii: 'SICHUAN_YI',
  ik: 'INUPIAQ',
  io: 'IDO',
  is: 'ICELANDIC',
  it: 'ITALIAN',
  iu: 'INUKTITUT',
  ja: 'JAPANESE',
  jv: 'JAVANESE',
  ka: 'GEORGIAN',
  kg: 'KONGO',
  ki: 'KIKUYU',
  kj: 'KUANYAMA',
  kk: 'KAZAKH',
  kl: 'KALAALLISUT',
  km: 'CENTRAL_KHMER',
  kn: 'KANNADA',
  ko: 'KOREAN',
  kr: 'KANURI',
  ks: 'KASHMIRI',
  ku: 'KURDISH',
  kv: 'KOMI',
  kw: 'CORNISH',
  ky: 'KYRGYZ',
  la: 'LATIN',
  lb: 'LUXEMBOURGISH',
  lg: 'GANDA',
  li: 'LIMBURGAN',
  ln: 'LINGALA',
  lo: 'LAO',
  lt: 'LITHUANIAN',
  lu: 'LUBA_KATANGA',
  lv: 'LATVIAN',
  mg: 'MALAGASY',
  mh: 'MARSHALLESE',
  mi: 'MAORI',
  mk: 'MACEDONIAN',
  ml: 'MALAYALAM',
  mn: 'MONGOLIAN',
  mr: 'MARATHI',
  ms: 'MALAY',
  mt: 'MALTESE',
  my: 'BURMESE',
  na: 'NAURU',
  nb: 'NORWEGIAN',
  nd: 'NORTH_NDEBELE',
  ne: 'NEPALI',
  ng: 'NDONGA',
  nl: 'DUTCH',
  nn: 'NORWEGIAN',
  no: 'NORWEGIAN',
  nr: 'SOUTH_NDEBELE',
  nv: 'NAVAJO',
  ny: 'NYANJA',
  oc: 'OCCITAN',
  oj: 'OJIBWA',
  om: 'OROMO',
  or: 'ORIYA',
  os: 'OSSETIAN',
  pa: 'PUNJABI',
  pi: 'PALI',
  pl: 'POLISH',
  ps: 'PASHTO',
  pt: 'PORTUGUESE',
  qu: 'QUECHUA',
  rm: 'ROMANSH',
  rn: 'RUNDI',
  ro: 'ROMANIAN',
  ru: 'RUSSIAN',
  rw: 'KINYARWANDA',
  sa: 'SANSKRIT',
  sc: 'SARDINIAN',
  sd: 'SINDHI',
  se: 'NORTHERN_SAMI',
  sg: 'SANGO',
  si: 'SINHALESE',
  sk: 'SLOVAK',
  sl: 'SLOVENE',
  sm: 'SAMOAN',
  sn: 'SHONA',
  so: 'SOMALI',
  sq: 'ALBANIAN',
  sr: 'SERBIAN',
  ss: 'SWATI',
  st: 'SOUTHERN_SOTHO',
  su: 'SUNDANESE',
  sv: 'SWEDISH',
  sw: 'SWAHILI',
  ta: 'TAMIL',
  te: 'TELUGU',
  tg: 'TAJIK',
  th: 'THAI',
  ti: 'TIGRINYA',
  tk: 'TURKMEN',
  tl: 'TAGALOG',
  tn: 'TSWANA',
  to: 'TONGA',
  tr: 'TURKISH',
  ts: 'TSONGA',
  tt: 'TATAR',
  tw: 'TWI',
  ty: 'TAHITIAN',
  ug: 'UYGHUR',
  uk: 'UKRAINIAN',
  ur: 'URDU',
  uz: 'UZBEK',
  ve: 'VENDA',
  vi: 'VIETNAMESE',
  vo: 'VOLAPUK',
  wa: 'WALLOON',
  wo: 'WOLOF',
  xh: 'XHOSA',
  yi: 'YIDDISH',
  yo: 'YORUBA',
  za: 'ZHUANG',
  zh: 'CHINESE',
  zu: 'ZULU',
} satisfies { [k: string]: Language };

export const Language = makeEnumLike([
  'ABKHAZIAN',
  'AFAR',
  'AFRIKAANS',
  'AKAN',
  'ALBANIAN',
  'AMHARIC',
  'ARABIC',
  'ARAGONESE',
  'ARMENIAN',
  'ASSAMESE',
  'AVARIC',
  'AVESTAN',
  'AYMARA',
  'AZERBAIJANI',
  'AZERI',
  'BAMBARA',
  'BASHKIR',
  'BASQUE',
  'BELARUSIAN',
  'BENGALI',
  'BIHARI',
  'BISLAMA',
  'BOKMAL',
  'BOSNIAN',
  'BRETON',
  'BULGARIAN',
  'BURMESE',
  'CATALAN',
  'CEBUANO',
  'CENTRAL_KHMER',
  'CHAMORRO',
  'CHECHEN',
  'CHINESE',
  'CHURCH_SLAVIC',
  'CHUVASH',
  'CORNISH',
  'CORSICAN',
  'CREE',
  'CROATIAN',
  'CZECH',
  'DANISH',
  'DHIVEHI',
  'DUTCH',
  'DZONGKHA',
  'ENGLISH',
  'ESPERANTO',
  'ESTONIAN',
  'EWE',
  'FAROESE',
  'FARSI',
  'FIJIAN',
  'FINNISH',
  'FLEMISH',
  'FRENCH',
  'FULAH',
  'GAELIC',
  'GALICIAN',
  'GANDA',
  'GEORGIAN',
  'GERMAN',
  'GREEK',
  'GUARANI',
  'GUJARATI',
  'HAITIAN',
  'HAUSA',
  'HAWAIIAN',
  'HEBREW',
  'HERERO',
  'HINDI',
  'HIRI_MOTU',
  'HUNGARIAN',
  'ICELANDIC',
  'IDO',
  'IGBO',
  'INDONESIAN',
  'INTERLINGUA',
  'INUKTITUT',
  'INUPIAQ',
  'IRISH',
  'ITALIAN',
  'JAPANESE',
  'JAVANESE',
  'KALAALLISUT',
  'KANNADA',
  'KANURI',
  'KASHMIRI',
  'KAZAKH',
  'KIKUYU',
  'KINYARWANDA',
  'KOMI',
  'KONGO',
  'KOREAN',
  'KUANYAMA',
  'KURDISH',
  'KYRGYZ',
  'LAO',
  'LATIN',
  'LATVIAN',
  'LIMBURGAN',
  'LINGALA',
  'LITHUANIAN',
  'LUBA_KATANGA',
  'LUXEMBOURGISH',
  'MACEDONIAN',
  'MALAGASY',
  'MALAY',
  'MALAYALAM',
  'MALTESE',
  'MANX',
  'MAORI',
  'MARATHI',
  'MARSHALLESE',
  'MOLDOVIAN',
  'MONGOLIAN',
  'NAURU',
  'NAVAJO',
  'NDONGA',
  'NEPALI',
  'NORTH_NDEBELE',
  'NORTHERN_SAMI',
  'NORWEGIAN',
  'NYANJA',
  'OCCITAN',
  'OJIBWA',
  'ORIYA',
  'OROMO',
  'OSSETIAN',
  'PALI',
  'PASHTO',
  'PERSIAN',
  'PIDGIN',
  'POLISH',
  'PORTUGUESE',
  'PUNJABI',
  'QUECHUA',
  'ROMANIAN',
  'ROMANSH',
  'RUNDI',
  'RUSSIAN',
  'SAMOAN',
  'SANGO',
  'SANSKRIT',
  'SARDINIAN',
  'SERBIAN',
  'SHONA',
  'SICHUAN_YI',
  'SINDHI',
  'SINHALESE',
  'SLOVAK',
  'SLOVENE',
  'SOMALI',
  'SOUTH_NDEBELE',
  'SOUTHERN_SOTHO',
  'SPANISH',
  'SUNDANESE',
  'SWAHILI',
  'SWATI',
  'SWEDISH',
  'TAGALOG',
  'TAHITIAN',
  'TAJIK',
  'TAMIL',
  'TATAR',
  'TELUGU',
  'THAI',
  'TIBETAN',
  'TIGRINYA',
  'TONGA',
  'TSONGA',
  'TSWANA',
  'TURKISH',
  'TURKMEN',
  'TWI',
  'UKRAINIAN',
  'URDU',
  'UYGHUR',
  'UZBEK',
  'VENDA',
  'VIETNAMESE',
  'VOLAPUK',
  'WALLOON',
  'WELSH',
  'WESTERN_FRISIAN',
  'WOLOF',
  'XHOSA',
  'YIDDISH',
  'YORUBA',
  'ZHUANG',
  'ZULU',
]);

export function getLanguageFromCode(countryCode: string) {
  if (countryCode in ISO_LANG_MAP) {
    return ISO_LANG_MAP[countryCode as keyof typeof ISO_LANG_MAP];
  }
  return null;
}

export type Language = keyof typeof Language;
