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

//#region ../automated-config/dist/utils/getConfigVariantPseudoStates.js
/*! © 2026 Yahoo, Inc. UDS Default Config v0.0.0-development */
const DEFAULT_PSEUDO_STATES = ["rest"];
function getConfigVariantPseudoStates(config, variantKey, state, subComponentName) {
	const componentVariant = getConfigComponentVariant(config, variantKey, subComponentName);
	if (!componentVariant) return null;
	const variantLayers = isVariantConfigWithProperties(componentVariant) ? Object.entries(componentVariant?.layers ?? {}) : [];
	const stateLayers = isVariantConfigWithComponentStates(componentVariant) && state ? Object.entries(componentVariant.componentStates[state].layers ?? {}) : [];
	return [...variantLayers, ...stateLayers].flatMap(([layerKey, layer]) => Object.entries(layer.properties).map(([propertyKey, property]) => [
		layerKey,
		propertyKey,
		property
	])).flatMap(([layerKey, propertyKey, property]) => [...property.skipRestState ? DEFAULT_PSEUDO_STATES.filter((s) => s !== "rest") : DEFAULT_PSEUDO_STATES, ...property.pseudoStates ?? []].map((pseudoState) => [
		layerKey,
		propertyKey,
		property,
		pseudoState
	])).reduce((acc, [layerKey, propertyKey, property, pseudoState]) => {
		acc[pseudoState] = acc[pseudoState] ?? [];
		const info = [
			layerKey,
			propertyKey,
			property
		];
		acc[pseudoState].push(info);
		return acc;
	}, {});
}

//#endregion
export { getConfigVariantPseudoStates };