let brandingProperties = {};

export function style(customProperty, defaultValue) {
    const val =
        (Object.hasOwnProperty.call(brandingProperties, customProperty) &&
            brandingProperties[customProperty]) ||
        defaultValue;
    if (!val) {
        return `var(${customProperty}${defaultValue ? `, ${defaultValue}` : ''})`;
    }
    return val;
}

export function setBrandingProperties(props) {
    brandingProperties = props;

    if (process.env.LWC_TARGET !== 'es5') {
        Object.entries(brandingProperties).forEach(([key, value]) => setCSSVariable(key, value));
    }
}

function setCSSVariable(key, value) {
    document.documentElement.style.setProperty(key, value);
}

export default { setBrandingProperties, style };
