import detectLanguage from './support/detect-language.js';
import { languagesAsChoices } from './support/languages.js';
export async function askI18n() {
    if (!this.askForMoreLanguages)
        return;
    const nativeLanguage = this.jhipsterConfig.nativeLanguage;
    const answers = await this.prompt([
        {
            type: 'confirm',
            name: 'enableTranslation',
            message: 'Would you like to enable internationalization support?',
            default: true,
        },
        {
            type: 'list',
            name: 'nativeLanguage',
            message: 'Please choose the native language of the application',
            choices: () => languagesAsChoices(this.supportedLanguages),
            default: () => (this.options.reproducible ? 'zh-cn' : detectLanguage()),
            store: true,
        },
    ], this.config);
    if (nativeLanguage !== answers.nativeLanguage) {
        this.languagesToApply.push(answers.nativeLanguage);
    }
}
export async function askForLanguages({ control }) {
    if (!this.askForMoreLanguages) {
        return;
    }
    const currentLanguages = this.jhipsterConfig.languages ?? [];
    const answers = await this.prompt([
        {
            type: 'checkbox',
            name: 'languages',
            message: 'Please choose additional languages to install',
            choices: () => {
                const languageOptions = this.supportedLanguages;
                const nativeLanguage = this.jhipsterConfigWithDefaults.nativeLanguage;
                const choices = languagesAsChoices(languageOptions.filter(l => l.languageTag !== nativeLanguage));
                const defaults = this.jhipsterConfigWithDefaults.languages ?? [];
                return [...choices.filter(({ value }) => defaults.includes(value)), ...choices.filter(({ value }) => !defaults.includes(value))];
            },
            default: () => this.jhipsterConfigWithDefaults.languages,
        },
    ]);
    if (control.existingProject) {
        this.languagesToApply.push(...answers.languages.filter(newLang => !currentLanguages.includes(newLang)));
    }
    else {
        this.languagesToApply.push(...answers.languages);
    }
}
