/*! © 2026 Yahoo, Inc. UDS Tailwind and Purger v0.0.0-development */
import { green } from "../cli/dist/lib/colors.js";
import { print } from "../cli/dist/lib/print.js";
import { addAutoVariantsToComponentClasses, convertVariantsIntoTailwindClass, getComponentsDependencies, getComponentsProps, getExportedComponents, getExportsToFilePath, getTwClassesInComponent } from "../utils/generatePurgeCSSData.js";
import path from "node:path";

//#region src/commands/generatePurgeCSSData.ts
const makeGeneratePurgeCSSDataCommand = (getContext) => ({
	name: "generatePurgeCSSData",
	description: `Generates purge CSS data for UDS components. This is an internal command used to generate the data needed to purge unused CSS in UDS. It should not be used directly by users.`,
	tag: "hidden",
	run: async (_props) => {
		const { project, variants, UDS, UDS_EXPERIMENTAL } = await getContext();
		const exportedComponents = getExportedComponents(UDS, UDS_EXPERIMENTAL);
		const exportsToFilePath = getExportsToFilePath(project);
		const variantsList = convertVariantsIntoTailwindClass(variants);
		const componentToVariants = getComponentsProps(project, exportedComponents, variants, variantsList, exportsToFilePath);
		const componentsDependencies = getComponentsDependencies(project, exportedComponents, exportsToFilePath);
		let componentToTwClasses = await getTwClassesInComponent(exportedComponents, exportsToFilePath);
		componentToTwClasses = addAutoVariantsToComponentClasses(componentToTwClasses);
		const outputFilePath = path.resolve(process.cwd(), "./generated/tailwindPurge.ts");
		const fileContent = `
//! This file is generated by \`uds purge\` from @yahoo/uds
//! Do not edit directly
//! If there is issue with this file please report to #ask-uds

export type PropToUsedOptions = [string, string[]];
export type ComponentToVariants = { [key: string]: PropToUsedOptions[] };
export type VariantsList = string[];
export type ComponentDependencies = { [key: string]: string[] };
export type ComponentToTwClasses = { [key: string]: string };

export const variantsList: VariantsList = ${JSON.stringify(variantsList)};
export const componentToVariants: ComponentToVariants = ${JSON.stringify(componentToVariants)};
export const componentToTwClasses: ComponentToTwClasses = ${JSON.stringify(componentToTwClasses)};
export const componentsDependencies: ComponentDependencies = ${JSON.stringify(componentsDependencies)};
`;
		await Bun.write(outputFilePath, fileContent);
		print(green(`✅ Purge CSS Data saved ${outputFilePath}`));
	}
});

//#endregion
export { makeGeneratePurgeCSSDataCommand };
//# sourceMappingURL=generatePurgeCSSData.js.map