const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
let __intlayer_chokidar = require("@intlayer/chokidar");
let __intlayer_config = require("@intlayer/config");
let node_path = require("node:path");
let __intlayer_unmerged_dictionaries_entry = require("@intlayer/unmerged-dictionaries-entry");

//#region src/getTargetDictionary.ts
const ensureArray = (value) => [value].flat();
const getTargetUnmergedDictionaries = async (options) => {
	const configuration = (0, __intlayer_config.getConfiguration)(options?.configOptions);
	const { baseDir } = configuration.content;
	const unmergedDictionariesRecord = (0, __intlayer_unmerged_dictionaries_entry.getUnmergedDictionaries)(configuration);
	let result = Object.values(unmergedDictionariesRecord).flat();
	if (typeof options?.file !== "undefined") {
		const relativeFilePaths = ensureArray(options?.file).map((file) => file.startsWith("/") ? (0, node_path.relative)(baseDir, file) : (0, node_path.join)("./", file));
		result = result.filter((dict) => dict.filePath && relativeFilePaths.includes(dict.filePath));
	}
	if (typeof options?.keys !== "undefined") result = result.filter((dict) => ensureArray(options?.keys)?.includes(dict.key));
	if (typeof options?.excludedKeys !== "undefined") result = result.filter((dict) => !ensureArray(options?.excludedKeys)?.includes(dict.key));
	if (typeof options?.pathFilter !== "undefined") result = result.filter((dict) => ensureArray(options?.pathFilter)?.includes(dict.filePath ?? ""));
	if (typeof options?.filter !== "undefined") result = result.filter(options?.filter);
	const gitOptions = options?.gitOptions;
	if (gitOptions) {
		const gitChangedFiles = await (0, __intlayer_chokidar.listGitFiles)(gitOptions);
		if (gitChangedFiles) result = result.filter((dict) => {
			if (!dict.filePath) return false;
			return gitChangedFiles.some((gitFile) => dict.filePath === gitFile);
		});
	}
	return result;
};

//#endregion
exports.ensureArray = ensureArray;
exports.getTargetUnmergedDictionaries = getTargetUnmergedDictionaries;
//# sourceMappingURL=getTargetDictionary.cjs.map