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_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_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": 'Next',
    "backButton": 'Back',
    "doneButton": 'Done',
    "GmErr_BadRequest_Duplicate_User": 'A user with this information already exists.',
    "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"
  }
};
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;
};
