/*! © 2026 Yahoo, Inc. UDS Tailwind and Purger v0.0.0-development */
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
const require_index = require('../../css-tokens/dist/index.cjs');
const require_purgeCSS = require('./purgeCSS.cjs');
let ts_morph = require("ts-morph");

//#region src/purger/legacy/purgeFromCode.ts
const COLOR_MODE_CLASSES = {
	dark: require_index.DARK_COLOR_MODE_CLASSNAME,
	light: require_index.LIGHT_COLOR_MODE_CLASSNAME
};
/**
* Run the legacy purger on a code string and return the safelist.
* This uses the same logic as the CLI `uds purge` command but with in-memory files.
*
* @param code - The TypeScript/TSX code to analyze
* @param options - Configuration options for color modes
* @returns The purge result containing safelist, imports, and components
*/
function purgeFromCode(code, options) {
	const { colorModes = ["dark", "light"] } = options;
	try {
		const project = new ts_morph.Project({
			useInMemoryFileSystem: true,
			compilerOptions: {
				jsx: ts_morph.ts.JsxEmit.ReactJSX,
				jsxImportSource: "react",
				target: ts_morph.ts.ScriptTarget.ESNext,
				module: ts_morph.ts.ModuleKind.ESNext,
				moduleResolution: ts_morph.ts.ModuleResolutionKind.NodeJs,
				esModuleInterop: true,
				strict: true
			}
		});
		const imports = require_purgeCSS.parseFiles(project, [project.createSourceFile("user-code.tsx", code).getFilePath()]);
		const components = require_purgeCSS.getComponentsToConvertToTW(imports, options.generatedPurgeCssData);
		const safelist = require_purgeCSS.getTailwindSafelist(project, components, options.variants, options.generatedPurgeCssData, options.packageJson);
		for (const mode of colorModes) {
			const cls = COLOR_MODE_CLASSES[mode];
			if (cls) safelist.push(cls);
		}
		safelist.push(require_index.LARGE_SCALE_MODE_CLASSNAME);
		return {
			safelist: Array.from(new Set(safelist)),
			imports,
			components
		};
	} catch (error) {
		return {
			safelist: [],
			imports: [],
			components: [],
			error: error instanceof Error ? error.message : "Unknown error"
		};
	}
}

//#endregion
exports.purgeFromCode = purgeFromCode;