'use strict';

var isVariantLabel = require('./is-variant-label.js');
var variantProps = require('./variant-props.js');

const numVariantProps = variantProps.variantProps.length;
/**
 * Get variant context from a visual element's parent chain.
 * Uses `any` type for visualElement to avoid circular dependencies.
 */
function getVariantContext(visualElement) {
    if (!visualElement)
        return undefined;
    if (!visualElement.isControllingVariants) {
        const context = visualElement.parent
            ? getVariantContext(visualElement.parent) || {}
            : {};
        if (visualElement.props.initial !== undefined) {
            context.initial = visualElement.props.initial;
        }
        return context;
    }
    const context = {};
    for (let i = 0; i < numVariantProps; i++) {
        const name = variantProps.variantProps[i];
        const prop = visualElement.props[name];
        if (isVariantLabel.isVariantLabel(prop) || prop === false) {
            context[name] = prop;
        }
    }
    return context;
}

exports.getVariantContext = getVariantContext;
