/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
require("../../../_virtual/_rolldown/runtime.cjs");
const require_runtime$1 = require("../_virtual/_rolldown/runtime.cjs");
const require_plugin$1 = require("../node_modules/.bun/tailwindcss@3.4.19_7500dce058369e0a/node_modules/tailwindcss/plugin.cjs");
const require_entries = require("../packages/utils/dist/entries.cjs");
let lodash_es = require("lodash-es");
//#region ../tailwind-internal/dist/utils/composeTailwindPlugins.js
/*! © 2026 Yahoo, Inc. UDS Tailwind Internal v0.0.0-development */
var import_plugin = /* @__PURE__ */ require_runtime$1.__toESM(require_plugin$1.require_plugin(), 1);
const shouldNotMergeTokensIntoTailwindTheme = (disableOverrideTailwindTheme, feature) => {
	return disableOverrideTailwindTheme === true || Array.isArray(disableOverrideTailwindTheme) && disableOverrideTailwindTheme.includes(feature);
};
const composeTailwindPlugins = (...plugins) => import_plugin.default.withOptions((options) => {
	if (!options.config) throw new Error("`tailwindPlugin` requires a config object. If your project has not yet sync'd a config, you can import `defaultTokensConfig` from `@yahoo/uds/defaultTokensConfig` and pass it to `tailwindPlugin`.");
	options.disableOverrideTailwindTheme ??= false;
	options.onlyTheme ??= false;
	options.ignorePluginSafelists ??= false;
	return (api) => {
		if (options.onlyTheme) return;
		const { addBase, addComponents, addUtilities, config } = api;
		const parentConfigImportant = config().important;
		const useImportNamespace = (0, lodash_es.isString)(parentConfigImportant);
		const rootSelector = useImportNamespace ? parentConfigImportant : ":root";
		const fns = {
			...api,
			addBase(css) {
				const [vars, classes] = (Array.isArray(css) ? css : [css]).map((rule) => require_entries.entries(rule)).map((pairs) => (0, lodash_es.partition)(pairs, ([key]) => key.startsWith("--"))).reduce((acc, [vars, classes]) => [{
					...acc[0],
					...Object.fromEntries(vars)
				}, {
					...acc[1],
					...Object.fromEntries(classes)
				}], [{}, {}]);
				addBase({ [rootSelector]: vars });
				addBase(classes);
			},
			addComponents(css, options = {}) {
				addComponents(css, {
					respectImportant: useImportNamespace,
					...options
				});
			},
			addUtilities(css, options = {}) {
				addUtilities(css, {
					respectPrefix: true,
					respectImportant: useImportNamespace,
					...options
				});
			}
		};
		for (const plugin of plugins) plugin(options).handler(fns);
	};
}, (options) => {
	if (!options.config) throw new Error("`tailwindPlugin` requires a config object. If your project has not yet sync'd a config, you can import `defaultTokensConfig` from `@yahoo/uds/defaultTokensConfig` and pass it to `tailwindPlugin`.");
	const pluginConfigs = plugins.map((plugin) => plugin(options).config ?? {});
	for (const config of pluginConfigs) for (const [key, value] of require_entries.entries(config.theme?.extend ?? {})) {
		if (!(0, lodash_es.isFunction)(value)) continue;
		throw new Error(`The theme.extend.${key} value cannot be a function when using composeTailwindPlugins. Please resolve the function to an object instead.`);
	}
	const mergedConfig = (0, lodash_es.merge)({}, ...pluginConfigs);
	mergedConfig.safelist = options.ignorePluginSafelists ? options.safelist : Array.from(new Set([...options.safelist ?? [], ...pluginConfigs.flatMap((c) => c.safelist ?? [])]));
	return mergedConfig;
});
//#endregion
exports.composeTailwindPlugins = composeTailwindPlugins;
exports.shouldNotMergeTokensIntoTailwindTheme = shouldNotMergeTokensIntoTailwindTheme;
