/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const require_colors = require("../dist/lib/colors.cjs");
const require_print = require("../dist/lib/print.cjs");
const require_spinner = require("../dist/lib/spinner.cjs");
const require_purge = require("../../css/dist/purger/optimized/purge.cjs");
const require_purgeCSS = require("../../tailwind-v3/dist/purger/legacy/purgeCSS.cjs");
const require_cli_commands_purge_helpers = require("./purge.helpers.cjs");
//#region src/cli/commands/purge.ts
const showHelp = () => {
	require_print.print("");
	require_print.print(`${require_colors.green("uds purge")} - Generate a Tailwind safelist from UDS usage`);
	require_print.print("");
	require_print.print(`${require_colors.magenta("Usage:")}`);
	require_print.print(`  ${require_colors.cyan("uds purge")} [options]`);
	require_print.print("");
	require_print.print(`${require_colors.magenta("Options:")}`);
	require_print.print(`  ${require_colors.cyan("--entry <path>")}       Entry directory or file to scan (default: ./src)`);
	require_print.print(`  ${require_colors.cyan("--output <path>")}      Output safelist file (default: dist/safelist.ts)`);
	require_print.print(`  ${require_colors.cyan("--config <path>")}      Path to uds.config.ts for legacy purge mode`);
	require_print.print(`  ${require_colors.cyan("--optimized")}          Use the optimized AST-based purger implementation`);
	require_print.print(`  ${require_colors.cyan("--help, -h")}           Show this help message`);
	require_print.print("");
	require_print.print(`${require_colors.magenta("Examples:")}`);
	require_print.print(`  ${require_colors.gray("uds purge")}`);
	require_print.print(`  ${require_colors.gray("uds purge --optimized")}`);
	require_print.print(`  ${require_colors.gray("uds purge --entry ./src --output ./dist/safelist.ts")}`);
	require_print.print(`  ${require_colors.gray("uds purge --config ./uds.config.ts")}`);
	require_print.print("");
};
const makePurgeCommand = (getContext) => ({
	name: "purge",
	description: "Purge unused CSS",
	run: async (props) => {
		if (require_cli_commands_purge_helpers.shouldShowHelp(props.options)) {
			showHelp();
			return;
		}
		const { config, entry, optimized, output } = require_cli_commands_purge_helpers.getPurgeRunOptions(props.options);
		const { variants, autoVariants, componentData, packageJson, generatedPurgeCssData } = await getContext();
		if (optimized) {
			require_spinner.spinStart("Purging CSS with optimized purger...");
			try {
				const result = await require_purge.purgeOptimized({
					entry,
					output,
					variants,
					autoVariants,
					componentData
				});
				require_spinner.spinStop("✅", `Purging done (optimized)! Generated ${result.stats.classesGenerated} classes in ${result.stats.timeMs}ms`);
				require_print.print(`   Files scanned: ${result.stats.filesScanned}`);
				require_print.print(`   Spreads traced: ${result.stats.spreadsTraced}`);
				require_print.print(`   Expressions resolved: ${result.stats.expressionsResolved}`);
				return;
			} catch (error) {
				if (error instanceof Error) require_spinner.spinStop("❌", error.message);
				else require_spinner.spinStop("❌", "Purging css failed! Please reach out to #uds-ask channel for support.");
				process.exitCode = 1;
				return;
			}
		}
		require_spinner.spinStart("Purging css started...");
		try {
			await require_purgeCSS.purge(variants, packageJson, generatedPurgeCssData, {
				config,
				entry,
				output
			});
			require_spinner.spinStop("✅", "Purging css done!");
		} catch (error) {
			if (error instanceof Error) require_spinner.spinStop("❌", error.message);
			else require_spinner.spinStop("❌", "Purging css failed! Please reach out to #uds-ask channel for support.");
			process.exitCode = 1;
		}
	}
});
//#endregion
exports.makePurgeCommand = makePurgeCommand;
