const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
const require_utils_checkAccess = require('./utils/checkAccess.cjs');
const require_reviewDocBlockAware = require('./reviewDocBlockAware.cjs');
const require_utils_checkFileModifiedRange = require('./utils/checkFileModifiedRange.cjs');
const require_utils_getOutputFilePath = require('./utils/getOutputFilePath.cjs');
let __intlayer_chokidar = require("@intlayer/chokidar");
let __intlayer_config = require("@intlayer/config");
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 src/reviewDoc.ts
/**
* 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 = (0, __intlayer_config.getConfiguration)(configOptions);
	const appLogger = (0, __intlayer_config.getAppLogger)(configuration);
	if (!await require_utils_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 (0, __intlayer_chokidar.listGitFiles)(gitOptions);
		if (gitChangedFiles) docList = docList.filter((path) => gitChangedFiles.some((gitFile) => (0, node_path.join)(process.cwd(), path) === gitFile));
	}
	appLogger(`Base locale is ${(0, __intlayer_chokidar.formatLocale)(baseLocale)}`);
	appLogger(`Reviewing ${(0, __intlayer_config.colorizeNumber)(locales.length)} locales: [ ${(0, __intlayer_chokidar.formatLocale)(locales)} ]`);
	appLogger(`Reviewing ${(0, __intlayer_config.colorizeNumber)(docList.length)} files:`);
	appLogger(docList.map((path) => ` - ${(0, __intlayer_chokidar.formatPath)(path)}\n`));
	await (0, __intlayer_chokidar.parallelize)(docList.flatMap((docPath) => locales.map((locale) => async () => {
		appLogger(`Reviewing file: ${(0, __intlayer_chokidar.formatPath)(docPath)} to ${(0, __intlayer_chokidar.formatLocale)(locale)}`);
		const absoluteBaseFilePath = (0, node_path.join)(configuration.content.baseDir, docPath);
		const outputFilePath = require_utils_getOutputFilePath.getOutputFilePath(absoluteBaseFilePath, locale, baseLocale);
		if (skipIfExists && (0, node_fs.existsSync)(outputFilePath)) {
			const relativePath = (0, node_path.relative)(configuration.content.baseDir, outputFilePath);
			appLogger(`${(0, __intlayer_config.colorize)("⊘", __intlayer_config.ANSIColors.YELLOW)} File ${(0, __intlayer_chokidar.formatPath)(relativePath)} already exists, skipping.`);
			return;
		}
		const fileModificationData = require_utils_checkFileModifiedRange.checkFileModifiedRange(outputFilePath, {
			skipIfModifiedBefore,
			skipIfModifiedAfter
		});
		if (fileModificationData.isSkipped) {
			appLogger(fileModificationData.message);
			return;
		}
		let changedLines;
		if (gitOptions) {
			const gitChangedLines = await (0, __intlayer_chokidar.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