const require_rolldown_runtime = require('../../../../../_virtual/rolldown_runtime.cjs');
let node_path = require("node:path");

//#region ../@intlayer/cli/dist/esm/fill/formatAutoFilledFilePath.mjs
const formatAutoFilledFilePath = (autoFillField, dictionaryKey, dictionaryFilePath, baseDir, locale) => {
	if (!autoFillField || typeof autoFillField !== "string") throw new Error("autoFillField must be a non-empty string");
	if (!dictionaryKey || typeof dictionaryKey !== "string") throw new Error("dictionaryKey must be a non-empty string");
	if (!dictionaryFilePath || typeof dictionaryFilePath !== "string") throw new Error("dictionaryFilePath must be a non-empty string");
	if (!baseDir || typeof baseDir !== "string") throw new Error("baseDir must be a non-empty string");
	const originalFileName = (0, node_path.basename)(dictionaryFilePath).split(".").slice(0, -2).join(".");
	let result = autoFillField.replace(/\{\{key\}\}/g, originalFileName).replace(/\{\{fileName\}\}/g, originalFileName);
	if (locale) result = result.replace(/\{\{locale\}\}/g, locale);
	const absoluteDictionaryPath = (0, node_path.isAbsolute)(dictionaryFilePath) ? dictionaryFilePath : (0, node_path.resolve)(baseDir, dictionaryFilePath);
	if (result.startsWith("./") || result.startsWith("../")) return (0, node_path.resolve)((0, node_path.dirname)(absoluteDictionaryPath), result);
	if ((0, node_path.isAbsolute)(result)) {
		const normalizedResult = (0, node_path.normalize)(result);
		const normalizedBaseDir = (0, node_path.normalize)(baseDir);
		if (result.startsWith("/") && !normalizedResult.startsWith(normalizedBaseDir)) {
			const relativeToBase = (0, node_path.resolve)(baseDir, result.substring(1));
			if (!result.startsWith("/usr/") && !result.startsWith("/etc/") && !result.startsWith("/var/") && !result.startsWith("/home/") && !result.startsWith("/Users/")) return relativeToBase;
		}
		return normalizedResult;
	}
	return (0, node_path.normalize)(result);
};

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