import { warning } from '../warning';
import { hasOwnProperty } from '../hasOwn';
var warnValidStyle = function () { };
if (process.env.NODE_ENV !== 'production') {
    var badVendoredStyleNamePattern_1 = /^(?:webkit|moz|o)[A-Z]/;
    var msPattern_1 = /^-ms-/;
    var hyphenPattern_1 = /-(.)/g;
    var badStyleValueWithSemicolonPattern_1 = /;\s*$/;
    var warnedStyleNames_1 = {};
    var warnedStyleValues_1 = {};
    var warnedForNaNValue_1 = false;
    var warnedForInfinityValue_1 = false;
    var utils_1 = {
        camelize: function (str) {
            return str.replace(hyphenPattern_1, function (_, character) {
                return character.toUpperCase();
            });
        },
        warnHyphenatedStyleName: function (name) {
            if (hasOwnProperty(warnedStyleNames_1, name) && warnedStyleNames_1[name]) {
                return;
            }
            warnedStyleNames_1[name] = true;
            warning(false, 'Unsupported style property %s. Did you mean %s?', name, utils_1.camelize(name.replace(msPattern_1, 'ms-')));
        },
        warnBadVendoredStyleName: function (name) {
            if (hasOwnProperty(warnedStyleNames_1, name) && warnedStyleNames_1[name]) {
                return;
            }
            warnedStyleNames_1[name] = true;
            warning(false, 'Unsupported vendor-prefixed style property %s. Did you mean %s?', name, name.charAt(0).toUpperCase() + name.slice(1));
        },
        warnStyleValueWithSemicolon: function (name, value) {
            if (hasOwnProperty(warnedStyleValues_1, value) &&
                warnedStyleValues_1[value]) {
                return;
            }
            warnedStyleValues_1[value] = true;
            warning(false, "Style property values shouldn't contain a semicolon. " +
                'Try "%s: %s" instead.', name, value.replace(badStyleValueWithSemicolonPattern_1, ''));
        },
        warnStyleValueIsNaN: function (name) {
            if (warnedForNaNValue_1) {
                return;
            }
            warnedForNaNValue_1 = true;
            warning(false, '`NaN` is an invalid value for the `%s` css style property.', name);
        },
        warnStyleValueIsInfinity: function (name) {
            if (warnedForInfinityValue_1) {
                return;
            }
            warnedForInfinityValue_1 = true;
            warning(false, '`Infinity` is an invalid value for the `%s` css style property.', name);
        },
    };
    warnValidStyle = function (name, value) {
        if (name.indexOf('-') > -1) {
            utils_1.warnHyphenatedStyleName(name);
        }
        else if (badVendoredStyleNamePattern_1.test(name)) {
            utils_1.warnBadVendoredStyleName(name);
        }
        else if (badStyleValueWithSemicolonPattern_1.test(value)) {
            utils_1.warnStyleValueWithSemicolon(name, value);
        }
        if (typeof value === 'number') {
            if (isNaN(value)) {
                utils_1.warnStyleValueIsNaN(name);
            }
            else if (!isFinite(value)) {
                utils_1.warnStyleValueIsInfinity(name);
            }
        }
    };
}
export default warnValidStyle;
