const DEFAULT_LANGUAGE = 'en';
export const TRANSLATIONS = {
  "en": {
    "nextButton": 'Next',
    "backButton": 'Back',
    "doneButton": 'Done',
    "GmErr_BadRequest_Duplicate_User": 'A user with this information already exists.',
    "GmErr_BadRequest_PasswordContainsUsername": "The password cannot be the same as the username.",
    "GmErr_BadRequest_PasswordContainsEmail": "The password cannot be the same as the email.",
    "GmErr_BadRequest_Duplicate_PersonalId": "There is already a registration with the data you entered or you entered your data in an incorrect format.",
    "GmErr_Forbidden_UserAccount_NavExcluded": 'User is NAV Excluded. Registration was denied.',
    "GmErr_BadRequest_ModelValidationFailed": 'Something went wrong... Please try again.',
    "GmErr_BadInternalConfigs": 'Something went wrong... Please try again.',
    "GmErr_Unauthorized": 'Something went wrong... Please try again.',
    "GmErr_NotFound": 'Something went wrong... Please try again.',
    "GmErr_UnexpectedException": 'Something went wrong... Please try again.',
    "generalError": "Something went wrong... Please try again.",
    "successMessage": "Register successful"
  },
  "hu": {
    "nextButton": 'Következő',
    "backButton": 'Vissza',
    "doneButton": 'Kész',
    "GmErr_BadRequest_Duplicate_User": 'Már létezik felhasználó ezzel az információval.',
    "GmErr_BadRequest_PasswordContainsUsername": "The password cannot be the same as the username.",
    "GmErr_BadRequest_PasswordContainsEmail": "The password cannot be the same as the email.",
    "GmErr_BadRequest_Duplicate_PersonalId": "There is already a registration with the data you entered or you entered your data in an incorrect format.",
    "GmErr_Forbidden_UserAccount_NavExcluded": 'User is NAV Excluded. Registration was denied',
    "GmErr_BadRequest_ModelValidationFailed": 'Valami hiba történt... Kérjük, próbálja újra.',
    "GmErr_BadInternalConfigs": 'Valami hiba történt... Kérjük, próbálja újra.',
    "GmErr_Unauthorized": 'Valami hiba történt... Kérjük, próbálja újra.',
    "GmErr_NotFound": 'Valami hiba történt... Kérjük, próbálja újra.',
    "GmErr_UnexpectedException": 'Valami hiba történt... Kérjük, próbálja újra.',
    "generalError": "Valami hiba történt... Próbáld újra.",
    "successMessage": "Sikeres regisztráció"
  },
  "hr": {
    "nextButton": 'Sljedeće',
    "backButton": 'Nazad',
    "doneButton": 'Gotovo',
    "GmErr_BadRequest_Duplicate_User": 'Korisnik s ovim podacima već postoji.',
    "GmErr_BadRequest_PasswordContainsUsername": "The password cannot be the same as the username.",
    "GmErr_BadRequest_PasswordContainsEmail": "The password cannot be the same as the email.",
    "GmErr_BadRequest_Duplicate_PersonalId": "There is already a registration with the data you entered or you entered your data in an incorrect format.",
    "GmErr_Forbidden_UserAccount_NavExcluded": 'Korisnik je NAV isključen. Registracija je odbijena.',
    "GmErr_BadRequest_ModelValidationFailed": 'Nešto nije u redu... Molimo pokušajte ponovo',
    "GmErr_BadInternalConfigs": 'Nešto nije u redu... Molimo pokušajte ponovo',
    "GmErr_Unauthorized": 'Nešto nije u redu... Molimo pokušajte ponovo',
    "GmErr_NotFound": 'Nešto nije u redu... Molimo pokušajte ponovo',
    "GmErr_UnexpectedException": 'Nešto nije u redu... Molimo pokušajte ponovo',
    "generalError": "Nešto nije u redu... Molimo pokušajte ponovo",
    "successMessage": "Register successful"
  },
  'pt-br': {
    "nextButton": 'Seguindo',
    "backButton": 'Voltar',
    "doneButton": 'Terminar',
    "GmErr_BadRequest_Duplicate_User": 'Já existe um usuário com esta informação',
    "GmErr_Forbidden_UserAccount_NavExcluded": 'O usuário está excluído NAV. O registro foi negado',
    "GmErr_BadRequest_ModelValidationFailed": 'Alguma coisa deu errado. Por favor tente outra vez.',
    "GmErr_BadInternalConfigs": 'Alguma coisa deu errado. Por favor tente outra vez',
    "GmErr_Unauthorized": 'Alguma coisa deu errado. Por favor tente outra vez',
    "GmErr_NotFound": 'Alguma coisa deu errado. Por favor tente outra vez',
    "GmErr_UnexpectedException": 'Alguma coisa deu errado. Por favor tente outra vez',
    "generalError": 'Alguma coisa deu errado. Por favor tente outra vez',
    "successMessage": 'Registro bem-sucedido'
  },
  'es-mx': {
    "nextButton": 'Siguiente',
    "backButton": 'Atrás',
    "doneButton": 'Terminar',
    "GmErr_BadRequest_Duplicate_User": 'Un usuario con esta información ya existe',
    "GmErr_Forbidden_UserAccount_NavExcluded": 'Usuario es Excluído NA. Registro fue negado',
    "GmErr_BadRequest_ModelValidationFailed": 'Algo salió mal…por favor intente de nuevo.',
    "GmErr_BadInternalConfigs": 'Algo salió mal... Por favor intente de nuevo',
    "GmErr_Unauthorized": 'Algo salió mal... Por favor intente de nuevo',
    "GmErr_NotFound": 'Algo salió mal... Por favor intente de nuevo',
    "GmErr_UnexpectedException": 'Algo salió mal... Por favor intente de nuevo',
    "generalError": 'Algo salió mal... Por favor intente de nuevo',
    "successMessage": 'Registro exitoso'
  }
};
export const getTranslations = (url) => {
  // fetch url, get the data, replace the TRANSLATIONS content
  return new Promise((resolve) => {
    fetch(url)
      .then((res) => res.json())
      .then((data) => {
      Object.keys(data).forEach((item) => {
        for (let key in data[item]) {
          TRANSLATIONS[item][key] = data[item][key];
        }
      });
      resolve(true);
    });
  });
};
export const translate = (key, customLang, values) => {
  const lang = customLang;
  let translation = TRANSLATIONS[lang !== undefined ? lang : DEFAULT_LANGUAGE][key];
  if (values !== undefined) {
    for (const [key, value] of Object.entries(values.values)) {
      const regex = new RegExp(`{${key}}`, 'g');
      translation = translation.replace(regex, value);
    }
  }
  return translation;
};
