const require_rolldown_runtime = require('../../../../../_virtual/rolldown_runtime.cjs');
const require_logger = require('../../../../config/dist/esm/logger.cjs');
const require_formatter = require('../chokidar/dist/esm/utils/formatter.cjs');
const require_index = require('../unmerged-dictionaries-entry/dist/esm/index.cjs');
const require_getFilterTranslationsOnlyContent = require('../core/dist/esm/deepTransformPlugins/getFilterTranslationsOnlyContent.cjs');
const require_getMissingLocalesContent = require('../core/dist/esm/deepTransformPlugins/getMissingLocalesContent.cjs');
const require_index$1 = require('../dictionaries-entry/dist/esm/index.cjs');
let node_path = require("node:path");

//#region ../@intlayer/cli/dist/esm/fill/listTranslationsTasks.mjs
const listTranslationsTasks = (localIds, outputLocales, mode, baseLocale, configuration) => {
	const appLogger = require_logger.getAppLogger(configuration);
	const mergedDictionariesRecord = require_index$1.getDictionaries(configuration);
	const unmergedDictionariesRecord = require_index.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 = require_logger.colon([
			" - ",
			require_logger.colorize("[", require_logger.ANSIColors.GREY_DARK),
			require_logger.colorizeKey(targetUnmergedDictionary.key),
			require_logger.colorize("]", require_logger.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 = require_getFilterTranslationsOnlyContent.getFilterTranslationsOnlyDictionary(mainDictionaryToProcess, sourceLocale);
		if (Object.keys(sourceLocaleContent).length === 0) {
			appLogger(`${dictionaryPreset} No content found for dictionary in source locale ${require_formatter.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 = require_getMissingLocalesContent.getMissingLocalesContentFromDictionary(targetUnmergedDictionary, outputLocales).includes(dictionaryLocale) ? [dictionaryLocale] : [];
			} else if (isEmptyDictionary) outputLocalesList = outputLocales;
			else outputLocalesList = require_getMissingLocalesContent.getMissingLocalesContentFromDictionary(targetUnmergedDictionary, outputLocales);
		}
		if (outputLocalesList.length === 0) {
			appLogger(`${dictionaryPreset} No locales to fill, Skipping ${require_logger.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