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."
  }
};
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 };
