/*! © 2026 Yahoo, Inc. UDS Tailwind and Purger v0.0.0-development */
import { print } from "../cli/dist/lib/print.js";
import { spinStart, spinStop } from "../cli/dist/lib/spinner.js";
import { purgeOptimized } from "../purger/optimized/purge.js";
import { purge } from "../purger/legacy/purgeCSS.js";

//#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) {
			spinStart("Purging CSS with optimized purger...");
			try {
				const result = await purgeOptimized({
					entry: typeof entry === "string" || Array.isArray(entry) ? entry : void 0,
					output: typeof output === "string" ? output : void 0,
					variants,
					autoVariants,
					componentData
				});
				spinStop("✅", `Purging done (optimized)! Generated ${result.stats.classesGenerated} classes in ${result.stats.timeMs}ms`);
				print(`   Files scanned: ${result.stats.filesScanned}`);
				print(`   Spreads traced: ${result.stats.spreadsTraced}`);
				print(`   Expressions resolved: ${result.stats.expressionsResolved}`);
				return;
			} catch (error) {
				if (error instanceof Error) spinStop("❌", error.message);
				else spinStop("❌", "Purging css failed! Please reach out to #uds-ask channel for support.");
				process.exitCode = 1;
			}
		} else {
			spinStart("Purging css started...");
			try {
				await 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
				});
				spinStop("✅", "Purging css done!");
				return;
			} catch (error) {
				if (error instanceof Error) spinStop("❌", error.message);
				else spinStop("❌", "Purging css failed! Please reach out to #uds-ask channel for support.");
				process.exitCode = 1;
			}
		}
	}
});

//#endregion
export { makePurgeCommand };
//# sourceMappingURL=purge.js.map