/*! © 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_getCommandHelp = require("../../utils/getCommandHelp.cjs");
const require_getDirChoices = require("../../utils/getDirChoices.cjs");
let prompts = require("prompts");
prompts = require_runtime.__toESM(prompts, 1);
//#region ../cli/dist/commands/codemod/codemod.mjs
/*! © 2026 Yahoo, Inc. UDS CLI v0.0.0-development */
var codemod_default = {
	name: "codemod",
	description: `Apply a codemod`,
	run: async (props) => {
		const subCommands = await require_getCommandHelp.getSubCommandsChoices(props);
		const subCommandIsValid = subCommands.some(({ value }) => props?.first === value);
		const wantsHelp = props.options.help || props.options.h;
		const isRootCommand = Boolean(!props?.first);
		const dirChoices = require_getDirChoices.getDirChoices();
		if (wantsHelp) return require_getCommandHelp.getCommandHelp(props);
		const runCodeMod = async (codemod, selectedDirs) => {
			return (await import(`./${codemod}`)).default.run({
				...props,
				selectedDirs
			});
		};
		if (isRootCommand) {
			const { selectedDirs, selectedCodemods, didConfirm } = await (0, prompts.default)([
				{
					type: "multiselect",
					name: "selectedDirs",
					instructions: false,
					message: "Where are your sourcefiles?",
					hint: "(Space to select. Return to submit)",
					choices: dirChoices
				},
				{
					type: "multiselect",
					name: "selectedCodemods",
					instructions: false,
					message: "Select the codemods you want to run",
					hint: "(Space to select. Return to submit)",
					choices: subCommands
				},
				{
					type: "toggle",
					name: "didConfirm",
					message: "Are you ready?",
					initial: true,
					active: "yes",
					inactive: "no"
				}
			]);
			if (!selectedDirs?.length || !selectedCodemods?.length || !didConfirm) process.exit(1);
			await Promise.all(selectedCodemods.map(async (codemod) => {
				await runCodeMod(codemod, selectedDirs);
				return require_analytics.trackEvent("codemod", { codemod });
			}));
			return;
		} else if (subCommandIsValid) {
			const { selectedDirs } = await (0, prompts.default)({
				type: "multiselect",
				name: "selectedDirs",
				instructions: false,
				message: "Where are your sourcefiles?",
				hint: "(Space to select. Return to submit)",
				choices: dirChoices
			});
			if (!selectedDirs?.length) process.exit(1);
			const codemod = props.first;
			await runCodeMod(codemod, selectedDirs);
			return require_analytics.trackEvent("codemod", { codemod });
		} else await require_getCommandHelp.getCommandHelp({
			...props,
			notes: `That codemod does not exist. Try one of the codemods listed above!`
		});
	}
};
//#endregion
exports.codemod_default = codemod_default;
