/*! © 2026 Yahoo, Inc. UDS Tailwind and Purger v0.0.0-development */
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
const require_purgeFromCode = require('./purgeFromCode.cjs');
const require_entryPoints = require('../../utils/entryPoints.cjs');
const require_safelist = require('./utils/safelist.cjs');
const require_files = require('./utils/files.cjs');
let node_fs = require("node:fs");
node_fs = require_runtime.__toESM(node_fs);
let node_path = require("node:path");
node_path = require_runtime.__toESM(node_path);

//#region src/purger/optimized/purge.ts
const warnedLocations = /* @__PURE__ */ new Set();
/**
* Clear warned locations (call at start of new purge run)
*/
const clearWarnings = () => {
	warnedLocations.clear();
};
/**
* Main purge function - optimized version
*
* Uses purgeFromCodeOptimized internally to ensure consistent behavior
* between CLI and playground.
*/
const purgeOptimized = async (options) => {
	const { entry = require_entryPoints.DEFAULT_ENTRY, output = "dist/safelist.ts", colorModes = ["dark"], variants, autoVariants, componentData } = options;
	const startTime = performance.now();
	clearWarnings();
	const workspaceDir = process.env.PWD ?? process.cwd();
	const files = await require_files.scanForFiles(entry);
	const allClasses = [];
	const allImports = /* @__PURE__ */ new Set();
	const allComponents = /* @__PURE__ */ new Set();
	const stats = {
		filesScanned: files.length,
		timeMs: 0,
		classesGenerated: 0,
		spreadsTraced: 0,
		expressionsResolved: 0
	};
	(await Promise.all(files.map(async (filePath) => {
		return require_purgeFromCode.purgeFromCodeOptimized(node_fs.default.readFileSync(filePath, "utf-8"), {
			colorModes,
			variants,
			autoVariants,
			componentData
		});
	}))).forEach((result) => {
		allClasses.push(...result.safelist);
		result.imports.forEach((imp) => allImports.add(imp));
		result.components.forEach((comp) => allComponents.add(comp));
		stats.spreadsTraced += result.stats.spreadsTraced;
		stats.expressionsResolved += result.stats.expressionsResolved;
	});
	allClasses.push(...require_safelist.getThemeAndScaleClasses(colorModes));
	const finalSafelist = require_safelist.deduplicateSafelist(allClasses).sort();
	await require_safelist.saveSafelistToFile(finalSafelist, node_path.default.join(workspaceDir, output));
	stats.timeMs = Math.round(performance.now() - startTime);
	stats.classesGenerated = finalSafelist.length;
	return {
		safelist: finalSafelist,
		imports: [...allImports],
		components: [...allComponents],
		stats
	};
};

//#endregion
exports.purgeOptimized = purgeOptimized;