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

//#region ../automated-config/dist/utils/getConfigVariantProperties.js
/*! © 2026 Yahoo, Inc. UDS Default Config v0.0.0-development */
/**
* Gets the properties of a variant config grouped by layer.
*
* @param variant - The variant config to get the properties from
* @returns A Record of layer names to their properties, or null if no properties are found
*/
function getConfigVariantProperties(variant) {
	if (!variant || !isVariantConfigWithProperties(variant)) return null;
	const result = mapValues(variant.layers, (layer) => layer.properties);
	for (const layerKey in result) {
		const layerProperties = result[layerKey];
		if (!layerProperties || Object.keys(layerProperties).length === 0) delete result[layerKey];
	}
	if (Object.keys(result).length === 0) return null;
	return result;
}

//#endregion
export { getConfigVariantProperties };