'use strict';

var is = require('./is.js');
var globalConfig = require('../../../../../../../motion-utils@12.36.0/node_modules/motion-utils/dist/es/global-config.js');

function addValueToWillChange(visualElement, key) {
    const willChange = visualElement.getValue("willChange");
    /**
     * It could be that a user has set willChange to a regular MotionValue,
     * in which case we can't add the value to it.
     */
    if (is.isWillChangeMotionValue(willChange)) {
        return willChange.add(key);
    }
    else if (!willChange && globalConfig.MotionGlobalConfig.WillChange) {
        const newWillChange = new globalConfig.MotionGlobalConfig.WillChange("auto");
        visualElement.addValue("willChange", newWillChange);
        newWillChange.add(key);
    }
}

exports.addValueToWillChange = addValueToWillChange;
