const require_logger = require('../../../../config/dist/esm/logger.cjs');
const require_getConfiguration = require('../../../../config/dist/esm/configFile/getConfiguration.cjs');
const require_formatter = require('../chokidar/dist/esm/utils/formatter.cjs');
const require_prepareIntlayer = require('../chokidar/dist/esm/prepareIntlayer.cjs');
const require_listMissingTranslations = require('./listMissingTranslations.cjs');

//#region ../@intlayer/cli/dist/esm/test/index.mjs
const testMissingTranslations = async (options) => {
	const config = require_getConfiguration.getConfiguration(options?.configOptions);
	const { locales, requiredLocales } = config.internationalization;
	const appLogger = require_logger.getAppLogger(config, { config: { prefix: "" } });
	if (options?.build === true) await require_prepareIntlayer.prepareIntlayer(config, { forceRun: true });
	else if (typeof options?.build === "undefined") await require_prepareIntlayer.prepareIntlayer(config);
	const result = require_listMissingTranslations.listMissingTranslations(options?.configOptions);
	const maxKeyColSize = result.missingTranslations.map((t) => ` - ${t.key}`).reduce((max, t) => Math.max(max, t.length), 0);
	const maxLocalesColSize = result.missingTranslations.map((t) => require_formatter.formatLocale(t.locales, false)).reduce((max, t) => Math.max(max, t.length), 0);
	const formattedMissingTranslations = result.missingTranslations.map((translation) => [
		require_logger.colon(` - ${require_logger.colorizeKey(translation.key)}`, {
			colSize: maxKeyColSize,
			maxSize: 40
		}),
		" - ",
		require_logger.colon(require_formatter.formatLocale(translation.locales, require_logger.ANSIColors.RED), {
			colSize: maxLocalesColSize,
			maxSize: 40
		}),
		translation.filePath ? ` - ${require_formatter.formatPath(translation.filePath)}` : "",
		translation.id ? " - remote" : ""
	].join(""));
	appLogger(`Missing translations:`, { level: "info" });
	formattedMissingTranslations.forEach((t) => {
		appLogger(t, { level: "info" });
	});
	appLogger(`Locales: ${require_formatter.formatLocale(locales)}`);
	appLogger(`Required locales: ${require_formatter.formatLocale(requiredLocales ?? locales)}`);
	appLogger(`Missing locales: ${result.missingLocales.length === 0 ? require_logger.colorize("-", require_logger.ANSIColors.GREEN) : require_formatter.formatLocale(result.missingLocales, require_logger.ANSIColors.RED)}`);
	appLogger(`Missing required locales: ${result.missingRequiredLocales.length === 0 ? require_logger.colorize("-", require_logger.ANSIColors.GREEN) : require_formatter.formatLocale(result.missingRequiredLocales, require_logger.ANSIColors.RED)}`);
	appLogger(`Total missing locales: ${require_logger.colorizeNumber(result.missingLocales.length, {
		one: require_logger.ANSIColors.RED,
		other: require_logger.ANSIColors.RED,
		zero: require_logger.ANSIColors.GREEN
	})}`);
	appLogger(`Total missing required locales: ${require_logger.colorizeNumber(result.missingRequiredLocales.length, {
		one: require_logger.ANSIColors.RED,
		other: require_logger.ANSIColors.RED,
		zero: require_logger.ANSIColors.GREEN
	})}`);
};

//#endregion
exports.testMissingTranslations = testMissingTranslations;
//# sourceMappingURL=index.cjs.map