/*! © 2026 Yahoo, Inc. UDS Tailwind and Purger v0.0.0-development */
const require_print = require('../cli/dist/lib/print.cjs');
const require_spinner = require('../cli/dist/lib/spinner.cjs');
const require_purge = require('../purger/optimized/purge.cjs');
const require_purgeCSS = require('../purger/legacy/purgeCSS.cjs');

//#region src/commands/purge.ts
const makePurgeCommand = (getContext) => ({
	name: "purge",
	description: `Purge unused CSS`,
	run: async (props) => {
		const { entry, output, optimized, config } = props.options;
		const useOptimized = optimized === "true" || optimized === true;
		const { variants, autoVariants, packageJson, generatedPurgeCssData, componentData } = await getContext();
		if (useOptimized) {
			require_spinner.spinStart("Purging CSS with optimized purger...");
			try {
				const result = await require_purge.purgeOptimized({
					entry: typeof entry === "string" || Array.isArray(entry) ? entry : void 0,
					output: typeof output === "string" ? output : void 0,
					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;
			}
		} else {
			require_spinner.spinStart("Purging css started...");
			try {
				await require_purgeCSS.purge(variants, packageJson, generatedPurgeCssData, {
					config: typeof config === "string" ? config : void 0,
					entry: typeof entry === "string" || Array.isArray(entry) ? entry : void 0,
					output: typeof output === "string" ? output : void 0
				});
				require_spinner.spinStop("✅", "Purging css done!");
				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;
			}
		}
	}
});

//#endregion
exports.makePurgeCommand = makePurgeCommand;