"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LanguageProvider = exports.Language = void 0;
const i18next_1 = __importDefault(require("i18next"));
const en_gb_1 = __importDefault(require("translations/languages/en-gb"));
const es_1 = __importDefault(require("translations/languages/es"));
const fr_1 = __importDefault(require("translations/languages/fr"));
const zh_cn_1 = __importDefault(require("translations/languages/zh-cn"));
const zh_tw_1 = __importDefault(require("translations/languages/zh-tw"));
const RoomstayThemeEngine_1 = __importDefault(require("./RoomstayThemeEngine"));
const ObjectHelper_1 = require("../util/ObjectHelper");
var Language;
(function (Language) {
    Language["en_us"] = "en-US";
    Language["zh_cn"] = "zh-CN";
    Language["zh_tw"] = "zh-TW";
    Language["es"] = "es";
    Language["fr"] = "fr";
    Language["clear"] = "testing_only";
})(Language || (exports.Language = Language = {}));
class LanguageProvider {
    static changeLanguage(lang) {
        RoomstayThemeEngine_1.default.selectedLang = lang;
        i18next_1.default.changeLanguage(lang);
    }
    static getPrettyLanguageName(lang) {
        switch (lang) {
            case Language.en_us:
                return 'English';
            case Language.zh_cn:
                return '简体中文';
            case Language.zh_tw:
                return '繁體中文';
            case Language.es:
                return 'Español';
            case Language.fr:
                return 'Français';
            default:
                return '';
        }
    }
    static getI18nMappedLanguages() {
        const workingMappings = {};
        const languages = this.getLanguages();
        Object.keys(languages).forEach((key) => {
            const translation = this.getOverridesForLanguage(key);
            workingMappings[key] = {
                translation,
            };
        });
        return workingMappings;
    }
    /**
     * Create a way to override translations for specific languages, and hotels.
     * @param lang
     * @param overrideTree
     */
    static registerOverride(lang, overrideTree) {
        LanguageProvider.overrides[lang] = (0, ObjectHelper_1.mergeDeep)(LanguageProvider.overrides[lang], overrideTree);
        // Check required for making sure Lang is loaded first.
        if (i18next_1.default && i18next_1.default.addResourceBundle) {
            i18next_1.default.addResourceBundle(lang, 'translation', this.getOverridesForLanguage(lang));
        }
    }
    static getLanguages() {
        if (this.filterLanguages.length >= 1) {
            const filteredLanguages = {};
            this.filterLanguages.map((lang) => {
                filteredLanguages[lang] = this.languages[lang];
            });
            return filteredLanguages;
        }
        else {
            return this.languages;
        }
    }
    static getOverridesForLanguage(lang) {
        const languages = this.getLanguages();
        const translation = languages[lang];
        return (0, ObjectHelper_1.mergeDeep)(translation, LanguageProvider.overrides[lang]);
    }
}
exports.LanguageProvider = LanguageProvider;
LanguageProvider.filterLanguages = [];
LanguageProvider.overrides = {};
LanguageProvider.languages = {
    [Language.en_us]: en_gb_1.default,
    [Language.es]: (0, ObjectHelper_1.mergeDeep)(en_gb_1.default, es_1.default),
    [Language.fr]: (0, ObjectHelper_1.mergeDeep)(en_gb_1.default, fr_1.default),
    [Language.zh_cn]: (0, ObjectHelper_1.mergeDeep)(en_gb_1.default, zh_cn_1.default),
    [Language.zh_tw]: (0, ObjectHelper_1.mergeDeep)(en_gb_1.default, zh_tw_1.default),
};
//# sourceMappingURL=LanguageProvider.js.map