/*! © 2026 Yahoo, Inc. UDS Tailwind and Purger v0.0.0-development */
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
const require_entries = require('../../utils/entries.cjs');
let lodash_isString_js = require("lodash/isString.js");
lodash_isString_js = require_runtime.__toESM(lodash_isString_js);
let tailwindcss_plugin_js = require("tailwindcss/plugin.js");
tailwindcss_plugin_js = require_runtime.__toESM(tailwindcss_plugin_js);
let lodash_isFunction_js = require("lodash/isFunction.js");
lodash_isFunction_js = require_runtime.__toESM(lodash_isFunction_js);
let lodash_merge_js = require("lodash/merge.js");
lodash_merge_js = require_runtime.__toESM(lodash_merge_js);
let lodash_partition_js = require("lodash/partition.js");
lodash_partition_js = require_runtime.__toESM(lodash_partition_js);

//#region src/tailwind/utils/composeTailwindPlugins.ts
const shouldNotMergeTokensIntoTailwindTheme = (disableOverrideTailwindTheme, feature) => {
	return disableOverrideTailwindTheme === true || Array.isArray(disableOverrideTailwindTheme) && disableOverrideTailwindTheme.includes(feature);
};
const composeTailwindPlugins = (...plugins) => tailwindcss_plugin_js.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_isString_js.default)(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_partition_js.default)(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_isFunction_js.default)(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_merge_js.default)({}, ...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;