/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
const require_runtime = require('../../../_virtual/_rolldown/runtime.cjs');
const require_analytics = require('../utils/analytics.cjs');
const require_config = require('../utils/rules/config.cjs');
const require_colors = require('../lib/colors.cjs');
const require_print = require('../lib/print.cjs');
let node_path = require("node:path");
let node_fs = require("node:fs");

//#region ../cli/dist/commands/editor-rules.mjs
/*! © 2026 Yahoo, Inc. UDS CLI v0.0.0-development */
var editor_rules_default = {
	name: "editor-rules",
	description: "🎯 Generate editor rules for various code editors and AI tools",
	alias: ["rules", "editor"],
	run: async ({ options }) => {
		if (process.argv.includes("--help") || process.argv.includes("-h")) {
			require_print.print(require_colors.blue("🎯 UDS Editor Rules Command"));
			require_print.print("");
			require_print.print(require_colors.green("Description: Generate editor rules for various code editors and AI tools"));
			require_print.print("");
			require_print.print(require_colors.yellow("Options:"));
			require_print.print("  --output, -o    Output directory (defaults to workspace root)");
			require_print.print("  --editor, -e    Specific editor/tool (defaults to all)");
			require_print.print("");
			require_print.print(require_colors.blue("Available editors/tools:"));
			const editors = require_config.getAvailableEditors();
			for (const editor of editors) {
				const config = require_config.getEditorConfig(editor);
				if (config) require_print.print(`  • ${editor}: ${config.description}`);
			}
			require_print.print("");
			require_print.print(require_colors.blue("Examples:"));
			require_print.print("  uds editor-rules                    # Generate all rules in current directory");
			require_print.print("  uds editor-rules --editor cursor    # Generate only Cursor rules");
			require_print.print("  uds editor-rules --editor claude    # Generate only Claude Code rules");
			require_print.print("  uds editor-rules --output /path     # Generate rules in specific directory");
			require_print.print("");
			require_print.print(require_colors.green("What it generates:"));
			require_print.print("  • Cursor Rules (.cursor/rules/uds/)");
			require_print.print("  • Claude Code Rules (.claude/rules/uds/)");
			return;
		}
		try {
			const outputDir = options.output || process.cwd();
			const selectedEditor = options.editor?.toLowerCase();
			require_print.print(require_colors.blue(`📁 Generating editor rules in: ${outputDir}`));
			if (selectedEditor) {
				const editorConfig = require_config.getEditorConfig(selectedEditor);
				if (!editorConfig) {
					require_print.print(require_colors.red(`❌ Unknown editor: ${selectedEditor}`));
					require_print.print(require_colors.yellow("Available editors:"));
					const editors = require_config.getAvailableEditors();
					for (const editor of editors) {
						const config = require_config.getEditorConfig(editor);
						if (config) require_print.print(`  • ${editor}: ${config.description}`);
					}
					return;
				}
				await generateEditorRules(outputDir, editorConfig);
			} else {
				const editors = require_config.getAvailableEditors();
				for (const editor of editors) {
					const editorConfig = require_config.getEditorConfig(editor);
					if (editorConfig) await generateEditorRules(outputDir, editorConfig);
				}
			}
			require_print.print(require_colors.green("🎉 Editor rules generated successfully!"));
			require_print.print(require_colors.blue("📝 Rules are now available for your development environment"));
			await require_analytics.trackEvent("editor_rules_generated", {
				output_dir: outputDir,
				editor: selectedEditor || "all"
			});
		} catch (error) {
			require_print.print(require_colors.red(`❌ Error generating editor rules: ${error}`));
			process.exitCode = 1;
		}
	}
};
async function generateEditorRules(outputDir, editorConfig) {
	require_print.print(require_colors.blue(`\n🔧 Generating ${editorConfig.name} rules...`));
	for (const rule of editorConfig.rules) {
		require_print.print(require_colors.yellow(`  📝 ${rule.name}: ${rule.description}`));
		for (const file of rule.files) {
			const targetPath = (0, node_path.join)(outputDir, file.target);
			const targetDir = (0, node_path.join)(targetPath, "..");
			if (!(0, node_fs.existsSync)(targetDir)) (0, node_fs.mkdirSync)(targetDir, { recursive: true });
			const exists = (0, node_fs.existsSync)(targetPath);
			try {
				const content = require_config.getRuleContent(file.source);
				if (exists) {
					if ((0, node_fs.readFileSync)(targetPath, "utf-8") === content) {
						require_print.print(require_colors.green(`    ✅ Up to date: ${file.target}`));
						continue;
					}
					(0, node_fs.writeFileSync)(targetPath, content);
					require_print.print(require_colors.green(`    ✅ Updated: ${file.target}`));
				} else {
					(0, node_fs.writeFileSync)(targetPath, content);
					require_print.print(require_colors.green(`    ✅ Created: ${file.target}`));
				}
			} catch (error) {
				require_print.print(require_colors.red(`    ❌ Error creating ${file.target}: ${error}`));
			}
		}
	}
}

//#endregion
exports.editor_rules_default = editor_rules_default;