import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
/**
 * Converts an inline style string into an object of React style properties
 *
 * @param {String} inlineStyle='' The inline style to convert
 * @returns {Object} The converted style
 */
export default function InlineStyleToObject() {
  var inlineStyle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  // just return empty object if the inlineStyle is empty
  if (inlineStyle === '') {
    return {};
  }
  return inlineStyle.split(';').reduce(function (styleObject, stylePropertyValue) {
    // extract the style property name and value
    var _stylePropertyValue$s = stylePropertyValue.split(/^([^:]+):/).filter(function (val, i) {
        return i > 0;
      }).map(function (item) {
        return item.trim().toLowerCase();
      }),
      _stylePropertyValue$s2 = _slicedToArray(_stylePropertyValue$s, 2),
      property = _stylePropertyValue$s2[0],
      value = _stylePropertyValue$s2[1];

    // if there is no value (i.e. no : in the style) then ignore it
    if (value === undefined) {
      return styleObject;
    }

    // convert the property name into the correct React format
    // remove all hyphens and convert the letter immediately after each hyphen to upper case
    // additionally don't uppercase any -ms- prefix
    // e.g. -ms-style-property = msStyleProperty
    //      -webkit-style-property = WebkitStyleProperty
    property = property.replace(/^-ms-/, 'ms-').replace(/-(.)/g, function (_, character) {
      return character.toUpperCase();
    });

    // add the new style property and value to the style object
    styleObject[property] = value;
    return styleObject;
  }, {});
}