/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
import { isVariantConfigWithComponentStates } from "./variantConfigGuards.js";
import { cartesianProduct } from "./cartesianProduct.js";
import { getConfigComponentVariant } from "./getConfigComponentVariant.js";
import { entries } from "lodash-es";

//#region ../automated-config/dist/utils/getConfigVariantComponentStatesMatrix.js
/*! © 2026 Yahoo, Inc. UDS Default Config v0.0.0-development */
function getConfigVariantComponentStates(config, variantKey, subComponentName) {
	const componentVariant = getConfigComponentVariant(config, variantKey, subComponentName);
	if (!componentVariant || !isVariantConfigWithComponentStates(componentVariant)) return null;
	return componentVariant?.componentStates ?? null;
}
function getConfigVariantComponentStatesMatrix(config, variantKey, subComponentName) {
	const componentStates = getConfigVariantComponentStates(config, variantKey, subComponentName);
	if (!componentStates) return null;
	return cartesianProduct(entries(componentStates).map(([key, c]) => c.options.map((c) => ({ [key]: c })))).map((p) => Array.isArray(p) ? p.reduce((acc, curr) => ({
		...acc,
		...curr
	}), {}) : p);
}

//#endregion
export { getConfigVariantComponentStates, getConfigVariantComponentStatesMatrix };