const DEFAULT_LANGUAGE = 'en';
const TRANSLATIONS = {
  "en": {
    "dateError": 'The selected date should be between {min} and {max}',
    "dateError2": 'The selected date is not within the accepted range',
    "numberLengthError": 'The number should be between {min} and {max}',
    "lengthError": `The length should be between {minLength} and {maxLength}`,
    "requiredError": 'This input is required.',
    "invalidOriginalPasswordError": "Initial password field does not validate all criteria.",
    "passwordStrength": "Password strength",
    "passwordStrengthWeak": "is not adequate",
    "passwordStrengthStrong": "is adequate",
    "SpecialCharactersNotAllowed": 'Should not contain special characters',
    "InvalidEmailFormat": "Invalid email format.",
    "EmailNotMatching": "Emails not matching!",
    "PasswordNotMatching": "Passwords not matching",
    "MustIncludeNumber": "include a number",
    "MustContainCapital": "contain capital letters",
    "MustIncludePunctation": "punctuation",
    "OnlyNumbers": "Should contains only numbers."
  },
  "hu": {
    "dateError": 'A választott dátumnak {min} és {max} között kell lennie',
    "numberLengthError": 'A számnak {min} és {max} között kell lennie',
    "lengthError": `A hossznak {minLength} és {maxLength} között kell lennie`,
    "requiredError": 'Ez a beviteli mező kötelező.',
    "invalidOriginalPasswordError": "Initial password field does not validate all criteria.",
    "passwordStrength": "Jelszó erőssége",
    "passwordStrengthWeak": "nem megfelelő",
    "passwordStrengthStrong": "megfelelő",
    "SpecialCharactersNotAllowed": 'Nem tartalmazhat speciális karaktereket',
    "InvalidEmailFormat": "Érvénytelen e-mail formátum.",
    "EmailNotMatching": "Az e-mailek nem egyeznek!",
    "PasswordNotMatching": "A jelszavak nem egyeznek",
    "MustIncludeNumber": "tartalmaznia kell egy számot",
    "MustContainCapital": "nagybetűket kell tartalmaznia",
    "MustIncludePunctation": "írásjelet",
    "OnlyNumbers": "Csak számokat kell tartalmaznia."
  },
  "hr": {
    "dateError": 'Odabrani datum treba biti između {min} i {max}',
    "dateError2": 'Odabrani datum nije unutar prihvaćenog raspona',
    "numberLengthError": 'Broj bi trebao biti između {min} i {max}',
    "lengthError": `Duljina bi trebala biti između {minLength} i {maxLength}`,
    "requiredError": 'Ovaj unos je obavezan.',
    "invalidOriginalPasswordError": "Polje početne lozinke ne potvrđuje sve kriterije",
    "passwordStrength": "Jačina zaporke",
    "passwordStrengthWeak": "nije adekvatno",
    "passwordStrengthStrong": "je adekvatan",
    "SpecialCharactersNotAllowed": 'Ne smije sadržavati posebne znakove',
    "InvalidEmailFormat": "Nevažeći format e-maila",
    "EmailNotMatching": "E-mailovi se ne podudaraju!",
    "PasswordNotMatching": "Lozinke se ne podudaraju",
    "MustIncludeNumber": "uključiti broj",
    "MustContainCapital": "sadrže velika slova",
    "MustIncludePunctation": "interpunkcija",
    "OnlyNumbers": "Treba sadržavati samo brojeve."
  },
  'pt-br': {
    "dateError": "A data selecionada deve estar entre {min} e {max}",
    "dateError2": "A data selecionada não está dentro de um intervalo válido",
    "numberLengthError": "O número deve estar entre {min} e {max}",
    "lengthError": "O comprimento deve estar entre {minLength} e {maxLength}",
    "requiredError": "Este campo é obrigatório",
    "invalidOriginalPasswordError": "O campo de senha inicial não faz parte dos critérios válidos",
    "PasswordStrength": "Força da senha",
    "PasswordStrengthWeak": "Não é adequado",
    "PasswordStrengthStrong": "é apropriado",
    "SpecialCharactersNotAllowed": "Não deve conter caracteres especiais",
    "InvalidEmailFormat": "Formato de email inválido",
    "EmailNotMatching": "E-mail não corresponde",
    "PasswordNotMatching": "Senha não corresponde",
    "MustIncludeNumber": "inclui um número",
    "MustContainCapital": "contém letras maiúsculas",
    "MustIncludePunctation": "pontuação",
    "OnlyNumbers": "Deve conter apenas números"
  },
  'es-mx': {
    "dateError": "La fecha seleccionada debe ser entre {min} y {max}",
    "dateError2": "La fecha seleccionada no está dentro de un rango válido",
    "numberLengthError": "El número debe ser entre {min} y {max}",
    "lengthError": "La longitud deber ser entre {minLength} y {maxLength}",
    "requiredError": "Este campo es requerido",
    "invalidOriginalPasswordError": "El campo de contraseña inicial no es parte del criterio válido",
    "PasswordStrength": "La fortaleza de la contraseña",
    "PasswordStrengthWeak": "no es adecuada",
    "PasswordStrengthStrong": "es adecuada",
    "SpecialCharactersNotAllowed": "No debe contener caracteres especiales",
    "InvalidEmailFormat": "Formato inválido de correo",
    "EmailNotMatching": "El correo electrónico no coincide",
    "PasswordNotMatching": "La contraseña no coincide",
    "MustIncludeNumber": "incluye un número",
    "MustContainCapital": "contiene mayúsculas",
    "MustIncludePunctation": "puntuación",
    "OnlyNumbers": "Solo debe contener números"
  }
};
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;
};
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);
    });
  });
};

const tooltipIconSvg = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTIiIGhlaWdodD0iMTIiIHZpZXdCb3g9IjAgMCAxMiAxMiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGNpcmNsZSBjeD0iNiIgY3k9IjYiIHI9IjUuNSIgc3Ryb2tlPSIjOTc5Nzk3Ii8+CjxyZWN0IHg9IjUiIHk9IjUiIHdpZHRoPSIyIiBoZWlnaHQ9IjUiIGZpbGw9IiM5Nzk3OTciLz4KPGNpcmNsZSBjeD0iNiIgY3k9IjMiIHI9IjEiIGZpbGw9IiM5Nzk3OTciLz4KPC9zdmc+Cg==';

export { tooltipIconSvg as a, getTranslations as g, translate as t };
