import { updateLanguagesInDayjsConfigurationTask } from '../../client/support/index.mjs';
import { generateLanguagesWebappOptions } from '../../languages/support/index.mjs';
function updateLanguagesInPipeTask({ application, control = {} }) {
    const { clientSrcDir, languagesDefinition = [] } = application;
    const { ignoreNeedlesError: ignoreNonExisting } = control;
    const newContent = `{
        ${generateLanguagesWebappOptions(languagesDefinition).join(',\n        ')}
        // jhipster-needle-i18n-language-key-pipe - JHipster will add/remove languages in this object
    };
`;
    this.editFile(`${clientSrcDir}/app/config/translation.ts`, { ignoreNonExisting }, content => content.replace(/{\s*('[a-z-]*':)?([^=]*jhipster-needle-i18n-language-key-pipe[^;]*)\};/g, newContent));
}
function updateLanguagesInWebpackReactTask({ application, control = {} }) {
    const { clientRootDir, clientSrcDir, languages } = application;
    const { ignoreNeedlesError: ignoreNonExisting } = control;
    let newContent = 'groupBy: [\n';
    languages?.forEach((language) => {
        newContent += `                    { pattern: "./${this.relativeDir(clientRootDir, clientSrcDir)}i18n/${language}/*.json", fileName: "./i18n/${language}.json" },\n`;
    });
    newContent +=
        '                    // jhipster-needle-i18n-language-webpack - JHipster will add/remove languages in this array\n' +
            '                ]';
    this.editFile(`${application.clientRootDir}webpack/webpack.common.js`, { ignoreNonExisting }, content => content.replace(/groupBy:.*\[([^\]]*jhipster-needle-i18n-language-webpack[^\]]*)\]/g, newContent));
}
export default function updateLanguagesTask(taskParam) {
    updateLanguagesInPipeTask.call(this, taskParam);
    updateLanguagesInWebpackReactTask.call(this, taskParam);
    updateLanguagesInDayjsConfigurationTask.call(this, taskParam, {
        configurationFile: `${taskParam.application.clientSrcDir}app/config/dayjs.ts`,
        commonjs: true,
    });
}
