const require_getConfiguration = require('../../../../config/dist/esm/configFile/getConfiguration.cjs');
const require_index = require('../unmerged-dictionaries-entry/dist/esm/index.cjs');
const require_writeDynamicDictionary = require('./writeDynamicDictionary.cjs');
const require_writeFetchDictionary = require('./writeFetchDictionary.cjs');
const require_writeMergedDictionary = require('./writeMergedDictionary.cjs');
const require_writeUnmergedDictionary = require('./writeUnmergedDictionary.cjs');

//#region ../chokidar/dist/esm/buildIntlayerDictionary/buildIntlayerDictionary.mjs
/**
* This function transpile the bundled code to to make dictionaries as JSON files
*/
const buildDictionary = async (localDictionariesEntries, configuration = require_getConfiguration.getConfiguration(), formats = ["cjs", "esm"], importOtherDictionaries = true) => {
	const { importMode } = configuration.build;
	const unmergedDictionariesToUpdate = [...localDictionariesEntries];
	if (importOtherDictionaries) {
		const prevUnmergedDictionaries = require_index.getUnmergedDictionaries(configuration);
		for (const dictionaryToWrite of localDictionariesEntries) {
			const allPrebuiltUnmergedDictionaries = prevUnmergedDictionaries[dictionaryToWrite.key];
			if (allPrebuiltUnmergedDictionaries?.length > 0) {
				const otherUnmergedDictionaries = allPrebuiltUnmergedDictionaries.filter((unmergedDictionary) => unmergedDictionary.localId !== dictionaryToWrite.localId);
				unmergedDictionariesToUpdate.push(...otherUnmergedDictionaries);
			}
		}
	}
	const unmergedDictionaries = await require_writeUnmergedDictionary.writeUnmergedDictionaries(unmergedDictionariesToUpdate, configuration);
	const mergedDictionaries = await require_writeMergedDictionary.writeMergedDictionaries(unmergedDictionaries, configuration);
	let dynamicDictionaries = null;
	if (importMode === "dynamic" || importMode === "live") dynamicDictionaries = await require_writeDynamicDictionary.writeDynamicDictionary(mergedDictionaries, configuration, formats);
	let fetchDictionaries = null;
	if (importMode === "live") fetchDictionaries = await require_writeFetchDictionary.writeFetchDictionary(dynamicDictionaries, configuration, formats);
	return {
		unmergedDictionaries,
		mergedDictionaries,
		dynamicDictionaries,
		fetchDictionaries
	};
};

//#endregion
exports.buildDictionary = buildDictionary;
//# sourceMappingURL=buildIntlayerDictionary.cjs.map