/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
import { filterPseudoStatesByExclusion, getExcludedLayersForComponentStateOption, getExcludedPseudoStatesForComponentStateOption } from "./componentStatePseudoStates.js";
import { resolvePropertyStates } from "./resolvePropertyStates.js";
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 */
/**
* Returns a map of state key → reactive properties for a variant. The state
* set comes from `resolvePropertyStates` — rest, atoms, and auto-generated
* compounds (modifier × interactive, modifier × modifier × interactive,
* etc.). The Configurator's StateBuilder caps user composition at the same
* depth, so every selectable state is in this map.
*/
function getConfigVariantPseudoStates(config, variantKey, state, subComponentName, componentStateValue) {
	const componentVariant = getConfigComponentVariant(config, variantKey, subComponentName);
	if (!componentVariant) return null;
	const componentStateConfig = state && isVariantConfigWithComponentStates(componentVariant) ? componentVariant.componentStates[state] : void 0;
	const excludedPseudoStates = componentStateConfig && componentStateValue ? getExcludedPseudoStatesForComponentStateOption(componentStateConfig, componentStateValue) : [];
	const excludedLayers = componentStateConfig && componentStateValue ? getExcludedLayersForComponentStateOption(componentStateConfig, componentStateValue) : [];
	const variantLayers = isVariantConfigWithProperties(componentVariant) ? Object.entries(componentVariant?.layers ?? {}) : [];
	const stateLayers = isVariantConfigWithComponentStates(componentVariant) && state ? Object.entries(componentVariant.componentStates[state].layers ?? {}) : [];
	const excludedLayerSet = new Set(excludedLayers);
	return [...variantLayers, ...stateLayers].filter(([layerKey]) => !excludedLayerSet.has(layerKey)).flatMap(([layerKey, layer]) => Object.entries(layer.properties).map(([propertyKey, property]) => [
		layerKey,
		layer,
		propertyKey,
		property
	])).flatMap(([layerKey, layer, propertyKey, property]) => filterPseudoStatesByExclusion(resolvePropertyStates(layer, property), excludedPseudoStates).map((pseudoState) => [
		layerKey,
		propertyKey,
		property,
		pseudoState
	])).reduce((acc, [layerKey, propertyKey, property, pseudoState]) => {
		acc[pseudoState] = acc[pseudoState] ?? [];
		acc[pseudoState].push([
			layerKey,
			propertyKey,
			property
		]);
		return acc;
	}, {});
}
//#endregion
export { getConfigVariantPseudoStates };
