const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
const require_getConfiguration = require('../../../config/dist/esm/configFile/getConfiguration.cjs');
const require_listGitFiles = require('./chokidar/dist/esm/listGitFiles.cjs');
const require_index = require('./unmerged-dictionaries-entry/dist/esm/index.cjs');
let node_path = require("node:path");

//#region ../@intlayer/cli/dist/esm/getTargetDictionary.mjs
const ensureArray = (value) => [value].flat();
const getTargetUnmergedDictionaries = async (options) => {
	const configuration = require_getConfiguration.getConfiguration(options?.configOptions);
	const { baseDir } = configuration.content;
	const unmergedDictionariesRecord = require_index.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 require_listGitFiles.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