const DEFAULT_LANGUAGE = 'en';
const TRANSLATIONS = {
    en: {
        topRewards: 'Top Rewards: ',
        loading: 'Loading...',
        join: 'Join',
        joined: 'Joined',
        games: 'Games',
        activities: 'Activities',
        events: 'Events',
        leaderboard: 'Leaderboard',
        rules: 'Rules',
        notQualified: 'Not qualified',
        reasonToQualify: '(Make {bet1} bets to qualify)',
        joinedSuccess: `You've joined of the tournament.`,
        joinedFailed: 'Failed to join the tournament. Please try again.',
        noParticipant: 'No participants yet.'
    }
};
export const getTranslations = (url) => {
    return new Promise((resolve) => {
        fetch(url)
            .then((res) => res.json())
            .then((data) => {
            Object.keys(data).forEach((lang) => {
                if (!TRANSLATIONS[lang]) {
                    TRANSLATIONS[lang] = {};
                }
                for (let key in data[lang]) {
                    TRANSLATIONS[lang][key] = data[lang][key];
                }
            });
            resolve(true);
        });
    });
};
export const translate = (key, customLang, values) => {
    const lang = customLang;
    let translation = TRANSLATIONS[(lang !== undefined) && (lang in TRANSLATIONS) ? 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;
};
