/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
const require_runtime = require('../../../_virtual/_rolldown/runtime.cjs');
const require_subcomponents = require('./subcomponents.cjs');
const require_coalesceConfigVariant = require('./coalesceConfigVariant.cjs');
let lodash_es = require("lodash-es");

//#region ../automated-config/dist/utils/getConfigVariants.js
/*! © 2026 Yahoo, Inc. UDS Default Config v0.0.0-development */
function getConfigVariants(config, variantKey = "variant") {
	const result = require_coalesceConfigVariant.coalesceConfigVariant(config, variantKey);
	if (result.type === "no-variants") return {
		type: "no-variants",
		description: "No variants"
	};
	if (result.type === "no-sub-components") {
		if (require_subcomponents.getConfigSubcomponents(config)) throw new Error("A config with a root variants.variant defintion cannot have subcomponents");
		return {
			type: "no-sub-components",
			description: result.variant.description,
			variantNames: [...result.variant.options]
		};
	}
	const variantToSubcomponentNames = (0, lodash_es.entries)(result.variants).reduce((acc, [subComponentName, subComponentVariantDef]) => {
		for (const variant of subComponentVariantDef.options) {
			acc[variant] ??= [];
			if (!acc[variant].includes(subComponentName)) acc[variant].push(subComponentName);
		}
		return acc;
	}, {});
	return {
		type: "has-sub-components",
		description: Object.values(result.variants).map((c) => c.description).filter((c) => c)[0] ?? "",
		variantNames: Object.keys(variantToSubcomponentNames),
		variantToSubcomponentNames
	};
}

//#endregion
exports.getConfigVariants = getConfigVariants;