/*! © 2026 Yahoo, Inc. UDS Tailwind and Purger v0.0.0-development */
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
const require_entryPoints = require('../utils/entryPoints.cjs');
const require_safelist = require('../icons/src/safelist.cjs');
const require_plugin = require('../plugin.cjs');
const require_optimizeCSS = require('../utils/optimizeCSS.cjs');
const require_postcssPreserveVars = require('../utils/postcssPreserveVars.cjs');
const require_postcss = require('./postcss.cjs');
const require_utils = require('./utils.cjs');
let node_path = require("node:path");
node_path = require_runtime.__toESM(node_path);
let postcss = require("postcss");
postcss = require_runtime.__toESM(postcss);
let autoprefixer = require("autoprefixer");
autoprefixer = require_runtime.__toESM(autoprefixer);
let postcss_prune_var = require("postcss-prune-var");
postcss_prune_var = require_runtime.__toESM(postcss_prune_var);
let postcss_scope = require("postcss-scope");
postcss_scope = require_runtime.__toESM(postcss_scope);
let tailwindcss = require("tailwindcss");
tailwindcss = require_runtime.__toESM(tailwindcss);

//#region src/css/generate.helpers.ts
const getPruneVarSafelist = (cssOptions) => {
	const pruneVars = cssOptions?.optimization?.pruneVars;
	const configuredSafelist = pruneVars && typeof pruneVars === "object" ? pruneVars.safelist ?? [] : [];
	return [...require_safelist.iconPruneVarsSafelist, ...configuredSafelist];
};
const getCssFeatureFlags = (cssOptions) => {
	const optimizationConfig = cssOptions?.optimization;
	const shouldOptimize = optimizationConfig?.enabled !== false;
	const pruneVars = optimizationConfig?.pruneVars;
	return {
		enablePreflight: cssOptions?.preflight !== false,
		enableFontFaceDeclarations: cssOptions?.fontFaceDeclarations !== false,
		shouldOptimize,
		shouldPruneVars: shouldOptimize && pruneVars !== false
	};
};
const getContentGlobs = (contentDir) => {
	return (Array.isArray(contentDir) ? contentDir : [contentDir]).map((dir) => require_entryPoints.hasAllowedEntryFileExtension(dir) ? dir : node_path.default.join(dir, "**/*.{js,jsx,ts,tsx}"));
};
const getRawContentEntries = (rawContents) => rawContents.map((rawContent) => ({
	raw: rawContent,
	extension: "html"
}));
const createTailwindPlugin = (options) => {
	return (0, tailwindcss.default)({
		content: [...getContentGlobs(options.contentDir), ...getRawContentEntries(options.rawContents ?? [])],
		safelist: options.safelist,
		corePlugins: { preflight: options.enablePreflight },
		plugins: [require_plugin.tailwindPlugin({
			config: options.config,
			disableFontFaceDeclarations: !options.enableFontFaceDeclarations,
			ignorePluginSafelists: true
		})]
	});
};
const getPruneVarPlugins = (safeVarPrefixes) => {
	if (safeVarPrefixes.length === 0) return [(0, postcss_prune_var.default)()];
	return [
		require_postcssPreserveVars.preserveVars({ preserve: safeVarPrefixes }),
		(0, postcss_prune_var.default)(),
		require_postcssPreserveVars.preserveVarsCleanup()
	];
};
const buildPostcssPlugins = (options) => {
	const plugins = [options.tailwindPlugin, (0, autoprefixer.default)()];
	if (options.shouldPruneVars) plugins.push(...getPruneVarPlugins(options.safeVarPrefixes));
	if (options.scopeClass) plugins.push((0, postcss_scope.default)(options.scopeClass));
	return plugins;
};
const applyScopedColorModeFix = async (css, scopeClass) => {
	if (!scopeClass) return css;
	return (await (0, postcss.default)([require_postcss.fixScopedColorModeSelectorsPlugin(scopeClass)]).process(css, { from: void 0 })).css;
};
const optimizeGeneratedCss = async (options) => {
	if (!options.shouldOptimize) return { css: options.css };
	const optimizationOptions = {
		removeUnusedFonts: options.optimizationConfig?.removeUnusedFonts,
		removeEmptyRules: options.optimizationConfig?.removeEmptyRules,
		aggregateDuplicateSelectors: options.optimizationConfig?.aggregateDuplicateSelectors,
		referenceCss: options.referenceCss,
		scopeClass: options.scopeClass
	};
	const optimized = await require_optimizeCSS.optimizeCSS(options.css, optimizationOptions);
	return {
		css: optimized.css,
		optimizationStats: {
			originalSize: optimized.stats.originalSize,
			originalSizeGzip: optimized.stats.originalSizeGzip,
			fontFacesRemoved: optimized.stats.fontFacesRemoved,
			emptyRulesRemoved: optimized.stats.emptyRulesRemoved,
			validationErrors: optimized.validation.errors
		}
	};
};
const printSimpleModeStats = (options) => {
	const { print, magenta, cyan, yellow } = options;
	print("");
	print(`${magenta("Output:")} ${cyan(options.outputPath)}`);
	print(`${magenta("Stats:")}`);
	print(`   Files scanned: ${options.totalFilesScanned}`);
	print(`   Classes: ${options.classCount}`);
	print(`   Size: ${require_utils.formatBytes(options.sizeBytes)} (${require_utils.formatBytes(options.sizeGzipBytes)} gzipped)`);
	const optimizationStats = options.optimizationStats;
	if (optimizationStats) {
		const savedBytesGzip = optimizationStats.originalSizeGzip - options.sizeGzipBytes;
		if (savedBytesGzip > 0) print(`   Optimized: saved ${require_utils.formatBytes(savedBytesGzip)} gzip (${optimizationStats.fontFacesRemoved} unused @font-face, ${optimizationStats.emptyRulesRemoved} empty rules removed)`);
		if (optimizationStats.validationErrors.length > 0) {
			print(`   ${yellow("Validation warnings:")}`);
			optimizationStats.validationErrors.forEach((error) => print(`      ${yellow("•")} ${error}`));
		}
	}
	print(`   Time: ${options.duration}ms`);
	if (options.scope) print(`   Scope: ${cyan(options.scope)}`);
};

//#endregion
exports.applyScopedColorModeFix = applyScopedColorModeFix;
exports.buildPostcssPlugins = buildPostcssPlugins;
exports.createTailwindPlugin = createTailwindPlugin;
exports.getCssFeatureFlags = getCssFeatureFlags;
exports.getPruneVarSafelist = getPruneVarSafelist;
exports.optimizeGeneratedCss = optimizeGeneratedCss;
exports.printSimpleModeStats = printSimpleModeStats;