/*! © 2026 Yahoo, Inc. UDS Tailwind and Purger v0.0.0-development */
import { ALWAYS_PREFIX, deprecatedAlwaysPalette, newAlwaysPalette } from "../../palette/dist/index.js";
import { BACKGROUND_COLOR_PREFIX, DARK_COLOR_MODE_CLASSNAME, INVERT_COLOR_MODE_CLASSNAME, LIGHT_COLOR_MODE_CLASSNAME, SYSTEM_COLOR_MODE_CLASSNAME } from "../../css-tokens/dist/index.js";
import { mapValues } from "../../utils/mapValues.js";
import { parseTokens } from "../../utils/parseTokens.js";
import { DEFAULT_COLOR_MODE } from "../../modes/dist/index.js";
import { addColorModeVars } from "../base/addColorModeVars.js";
import { addColorModeVarsV2 } from "../base/addColorModeVarsV2.js";
import { getTailwindAsUdsColors } from "./getTailwindAsUdsColors.js";
import { mapKeys } from "lodash-es";
import plugin from "tailwindcss/plugin.js";

//#region src/tailwind/plugins/colors.ts
const tailwindColorsAsUds = getTailwindAsUdsColors();
const colorsPlugin = plugin.withOptions(({ config, enableSystemColorMode = false }) => (api) => {
	const tokens = parseTokens(config);
	if (enableSystemColorMode) addColorModeVarsV2(tokens, api);
	else addColorModeVars(tokens, api);
}, ({ config }) => {
	const colorModeToken = parseTokens(config).colorMode[DEFAULT_COLOR_MODE].tailwindConfig;
	const spectrumWithTailwind = mapValues(colorModeToken.spectrum, (hueConfig, hue) => {
		return {
			...hueConfig,
			...tailwindColorsAsUds[hue]
		};
	});
	const nestedNewAlwaysPalette = mapKeys(newAlwaysPalette, (_, key) => key.replace(ALWAYS_PREFIX, ""));
	const colors = {
		...tailwindColorsAsUds,
		...spectrumWithTailwind,
		...deprecatedAlwaysPalette,
		always: nestedNewAlwaysPalette
	};
	const textColors = colorModeToken.palette.foreground;
	const backgroundColors = colorModeToken.palette.background;
	const borderColors = colorModeToken.palette.line;
	const elevationBackgroundColors = config.elevation ? Object.fromEntries(Object.keys(config.elevation).map((level) => [`elevation-${level}`, `var(--${BACKGROUND_COLOR_PREFIX}-elevation-${level})`])) : {};
	return {
		darkMode: ["class", DARK_COLOR_MODE_CLASSNAME],
		safelist: [
			LIGHT_COLOR_MODE_CLASSNAME,
			DARK_COLOR_MODE_CLASSNAME,
			INVERT_COLOR_MODE_CLASSNAME,
			SYSTEM_COLOR_MODE_CLASSNAME
		],
		theme: { extend: {
			outlineColor: {
				...borderColors,
				DEFAULT: colors.gray["15"]
			},
			colors,
			backgroundColor: backgroundColors,
			textColor: textColors,
			borderColor: borderColors,
			fill: backgroundColors,
			caretColor: textColors,
			placeholderColor: textColors,
			textDecorationColor: textColors,
			divideColor: borderColors,
			ringColor: borderColors,
			ringOffsetColor: borderColors,
			stroke: borderColors,
			gradientColorStops: {
				...backgroundColors,
				...elevationBackgroundColors,
				...colors
			}
		} }
	};
});

//#endregion
export { colorsPlugin };
//# sourceMappingURL=colors.js.map