import { supportedLanguages as baseSupportedLanguages, findLanguageForTag } from './languages.js';
export default function loadConfig({ application, config, control = {} }) {
    const { supportedLanguages = baseSupportedLanguages } = control;
    application.enableTranslation = config.enableTranslation;
    application.nativeLanguage = config.nativeLanguage;
    const nativeLanguageDefinition = findLanguageForTag(config.nativeLanguage, supportedLanguages);
    if (!nativeLanguageDefinition) {
        throw new Error(`Native language ${config.nativeLanguage} does not exist`);
    }
    application.nativeLanguageDefinition = nativeLanguageDefinition;
    if (application.enableTranslation) {
        application.languages = config.languages;
        application.languagesDefinition = application.languages
            .map(lang => findLanguageForTag(lang, supportedLanguages))
            .filter(lang => lang);
        application.enableI18nRTL = (application.languagesDefinition ?? [application.nativeLanguageDefinition]).some(language => language.rtl);
    }
    else {
        application.enableI18nRTL = application.nativeLanguageDefinition.rtl;
    }
}
