const require_rolldown_runtime = require('../../../../../../../../_virtual/rolldown_runtime.cjs');
const require_normalizePath = require('../../../../../../../config/dist/esm/utils/normalizePath.cjs');
const require_getConfiguration = require('../../../../../../../config/dist/esm/configFile/getConfiguration.cjs');
const require_getFileHash = require('../utils/getFileHash.cjs');
let node_path = require("node:path");

//#region ../@intlayer/webpack/dist/esm/chokidar/dist/esm/createDictionaryEntryPoint/generateDictionaryListContent.mjs
/**
* This function generates the content of the dictionary list file
*/
const generateDictionaryListContent = (dictionaries, functionName, format = "esm", configuration = require_getConfiguration.getConfiguration()) => {
	const { mainDir } = configuration.content;
	let content = "";
	const dictionariesRef = dictionaries.map((dictionaryPath) => ({
		relativePath: require_normalizePath.normalizePath((0, node_path.relative)(mainDir, dictionaryPath)),
		id: (0, node_path.basename)(dictionaryPath, (0, node_path.extname)(dictionaryPath)),
		hash: `_${require_getFileHash.getFileHash(dictionaryPath)}`
	}));
	dictionariesRef.forEach((dictionary) => {
		if (format === "esm") content += `import ${dictionary.hash} from '${dictionary.relativePath}' with { type: 'json' };\n`;
		if (format === "cjs") content += `const ${dictionary.hash} = require('${dictionary.relativePath}');\n`;
	});
	content += "\n";
	const formattedDictionaryMap = dictionariesRef.map((dictionary) => `  "${dictionary.id}": ${dictionary.hash}`).join(",\n");
	content += `const dictionaries = {\n${formattedDictionaryMap}\n};\n`;
	content += `const ${functionName} = () => dictionaries;\n`;
	if (format === "esm") {
		content += `\n`;
		content += `export { ${functionName} };\n`;
		content += `export default dictionaries;\n`;
	}
	if (format === "cjs") {
		content += `\n`;
		content += `module.exports.${functionName} = ${functionName};\n`;
		content += `module.exports = dictionaries;\n`;
	}
	return content;
};

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