import { formatLocale, formatPath } from "../chokidar/dist/esm/utils/formatter.mjs";
import { prepareIntlayer } from "../chokidar/dist/esm/prepareIntlayer.mjs";
import { listMissingTranslations } from "./listMissingTranslations.mjs";
import { ANSIColors, colon, colorize, colorizeKey, colorizeNumber, getAppLogger, getConfiguration } from "@intlayer/config";

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

//#endregion
export { testMissingTranslations };
//# sourceMappingURL=index.mjs.map