const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
let __intlayer_chokidar = require("@intlayer/chokidar");
let __intlayer_config = require("@intlayer/config");
let node_path = require("node:path");
let __intlayer_unmerged_dictionaries_entry = require("@intlayer/unmerged-dictionaries-entry");
let __intlayer_core = require("@intlayer/core");
let __intlayer_dictionaries_entry = require("@intlayer/dictionaries-entry");

//#region src/fill/listTranslationsTasks.ts
const listTranslationsTasks = (localIds, outputLocales, mode, baseLocale, configuration) => {
	const appLogger = (0, __intlayer_config.getAppLogger)(configuration);
	const mergedDictionariesRecord = (0, __intlayer_dictionaries_entry.getDictionaries)(configuration);
	const unmergedDictionariesRecord = (0, __intlayer_unmerged_dictionaries_entry.getUnmergedDictionaries)(configuration);
	const dictionariesToProcess = Object.values(unmergedDictionariesRecord).flat().filter((dictionary) => localIds.includes(dictionary.localId));
	const maxKeyLength = Math.max(...dictionariesToProcess.map((dict) => dict.key.length));
	const translationTasks = [];
	for (const targetUnmergedDictionary of dictionariesToProcess) {
		const dictionaryPreset = (0, __intlayer_config.colon)([
			" - ",
			(0, __intlayer_config.colorize)("[", __intlayer_config.ANSIColors.GREY_DARK),
			(0, __intlayer_config.colorizeKey)(targetUnmergedDictionary.key),
			(0, __intlayer_config.colorize)("]", __intlayer_config.ANSIColors.GREY_DARK)
		].join(""), { colSize: maxKeyLength + 6 });
		const dictionaryKey = targetUnmergedDictionary.key;
		const dictionaryLocalId = targetUnmergedDictionary.localId;
		const mainDictionaryToProcess = mergedDictionariesRecord[dictionaryKey];
		if ((targetUnmergedDictionary.fill ?? configuration.dictionary?.fill ?? false) === false) continue;
		const sourceLocale = targetUnmergedDictionary.locale ?? baseLocale;
		if (!mainDictionaryToProcess) {
			appLogger(`${dictionaryPreset} Dictionary not found in dictionariesRecord. Skipping.`, { level: "warn" });
			continue;
		}
		if (!targetUnmergedDictionary.filePath) {
			appLogger(`${dictionaryPreset} Dictionary has no file path. Skipping.`, { level: "warn" });
			continue;
		}
		const sourceLocaleContent = (0, __intlayer_core.getFilterTranslationsOnlyDictionary)(mainDictionaryToProcess, sourceLocale);
		if (Object.keys(sourceLocaleContent).length === 0) {
			appLogger(`${dictionaryPreset} No content found for dictionary in source locale ${(0, __intlayer_chokidar.formatLocale)(sourceLocale)}. Skipping translation for this dictionary.`, { level: "warn" });
			continue;
		}
		/**
		* In 'complete' mode, filter only the missing locales to translate
		*
		* Skip the dictionary if there are no missing locales to translate
		*/
		let outputLocalesList = outputLocales;
		if (mode === "complete") {
			const isEmptyDictionary = typeof targetUnmergedDictionary.content === "object" && Object.keys(targetUnmergedDictionary.content).length === 0;
			if (Boolean(targetUnmergedDictionary.locale)) {
				const dictionaryLocale = targetUnmergedDictionary.locale;
				if (isEmptyDictionary) outputLocalesList = outputLocales.includes(dictionaryLocale) ? [dictionaryLocale] : [];
				else outputLocalesList = (0, __intlayer_core.getMissingLocalesContentFromDictionary)(targetUnmergedDictionary, outputLocales).includes(dictionaryLocale) ? [dictionaryLocale] : [];
			} else if (isEmptyDictionary) outputLocalesList = outputLocales;
			else outputLocalesList = (0, __intlayer_core.getMissingLocalesContentFromDictionary)(targetUnmergedDictionary, outputLocales);
		}
		if (outputLocalesList.length === 0) {
			appLogger(`${dictionaryPreset} No locales to fill, Skipping ${(0, __intlayer_config.colorizePath)((0, node_path.basename)(targetUnmergedDictionary.filePath))}`, { level: "warn" });
			continue;
		}
		translationTasks.push({
			dictionaryKey,
			dictionaryLocalId,
			sourceLocale,
			targetLocales: outputLocalesList,
			dictionaryPreset,
			dictionaryFilePath: targetUnmergedDictionary.filePath
		});
	}
	return translationTasks;
};

//#endregion
exports.listTranslationsTasks = listTranslationsTasks;
//# sourceMappingURL=listTranslationsTasks.cjs.map