const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
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_parallelize = require('./chokidar/dist/esm/utils/parallelize.cjs');
const require_listGitFiles = require('./chokidar/dist/esm/listGitFiles.cjs');
const require_checkAccess = require('./utils/checkAccess.cjs');
const require_reviewDocBlockAware = require('./reviewDocBlockAware.cjs');
const require_checkFileModifiedRange = require('./utils/checkFileModifiedRange.cjs');
const require_getOutputFilePath = require('./utils/getOutputFilePath.cjs');
let node_path = require("node:path");
let node_fs = require("node:fs");
let fast_glob = require("fast-glob");
fast_glob = require_rolldown_runtime.__toESM(fast_glob);

//#region ../@intlayer/cli/dist/esm/reviewDoc.mjs
/**
* Main audit function: scans all .md files in "en/" (unless you specified DOC_LIST),
* then audits them to each locale in LOCALE_LIST.
*/
const reviewDoc = async ({ docPattern, locales, excludedGlobPattern, baseLocale, aiOptions, nbSimultaneousFileProcessed, configOptions, customInstructions, skipIfModifiedBefore, skipIfModifiedAfter, skipIfExists, gitOptions }) => {
	const configuration = require_getConfiguration.getConfiguration(configOptions);
	const appLogger = require_logger.getAppLogger(configuration);
	if (!await require_checkAccess.checkAIAccess(configuration, aiOptions)) return;
	if (nbSimultaneousFileProcessed && nbSimultaneousFileProcessed > 10) {
		appLogger(`Warning: nbSimultaneousFileProcessed is set to ${nbSimultaneousFileProcessed}, which is greater than 10. Setting it to 10.`);
		nbSimultaneousFileProcessed = 10;
	}
	let docList = await (0, fast_glob.default)(docPattern, { ignore: excludedGlobPattern });
	if (gitOptions) {
		const gitChangedFiles = await require_listGitFiles.listGitFiles(gitOptions);
		if (gitChangedFiles) docList = docList.filter((path) => gitChangedFiles.some((gitFile) => (0, node_path.join)(process.cwd(), path) === gitFile));
	}
	appLogger(`Base locale is ${require_formatter.formatLocale(baseLocale)}`);
	appLogger(`Reviewing ${require_logger.colorizeNumber(locales.length)} locales: [ ${require_formatter.formatLocale(locales)} ]`);
	appLogger(`Reviewing ${require_logger.colorizeNumber(docList.length)} files:`);
	appLogger(docList.map((path) => ` - ${require_formatter.formatPath(path)}\n`));
	await require_parallelize.parallelize(docList.flatMap((docPath) => locales.map((locale) => async () => {
		appLogger(`Reviewing file: ${require_formatter.formatPath(docPath)} to ${require_formatter.formatLocale(locale)}`);
		const absoluteBaseFilePath = (0, node_path.join)(configuration.content.baseDir, docPath);
		const outputFilePath = require_getOutputFilePath.getOutputFilePath(absoluteBaseFilePath, locale, baseLocale);
		if (skipIfExists && (0, node_fs.existsSync)(outputFilePath)) {
			const relativePath = (0, node_path.relative)(configuration.content.baseDir, outputFilePath);
			appLogger(`${require_logger.colorize("⊘", require_logger.ANSIColors.YELLOW)} File ${require_formatter.formatPath(relativePath)} already exists, skipping.`);
			return;
		}
		const fileModificationData = require_checkFileModifiedRange.checkFileModifiedRange(outputFilePath, {
			skipIfModifiedBefore,
			skipIfModifiedAfter
		});
		if (fileModificationData.isSkipped) {
			appLogger(fileModificationData.message);
			return;
		}
		let changedLines;
		if (gitOptions) {
			const gitChangedLines = await require_listGitFiles.listGitLines(absoluteBaseFilePath, gitOptions);
			appLogger(`Git changed lines: ${gitChangedLines.join(", ")}`);
			changedLines = gitChangedLines;
		}
		await require_reviewDocBlockAware.reviewFileBlockAware(absoluteBaseFilePath, outputFilePath, locale, baseLocale, aiOptions, configOptions, customInstructions, changedLines);
	})), (task) => task(), nbSimultaneousFileProcessed ?? 3);
};

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