"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.convertToInlineCss = convertToInlineCss;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
// Ignored via go/ees005
// eslint-disable-next-line require-unicode-regexp
var MS_PREFIX_REGEX = /^ms/;

/**
 * Converts a camelCased CSS property name to a hyphenated CSS property name.
 *
 * @param property - CamelCased CSS property name.
 * @returns Hyphenated CSS property name.
 */
function hyphenate(property) {
  // Ignored via go/ees005
  /* eslint-disable require-unicode-regexp */
  return property.replace(/[A-Z]/g, function (match) {
    return "-".concat(match.toLowerCase());
  }).replace(MS_PREFIX_REGEX, '-ms');
  /* eslint-enable require-unicode-regexp */
}

/**
 * Converts a CSS properties object to a CSS string.
 * @param properties - CSS properties object.
 * @returns CSS string.
 */
function convertToInlineCss(properties) {
  var cssString = Object.entries(properties).sort(function (_ref, _ref2) {
    var _ref3 = (0, _slicedToArray2.default)(_ref, 1),
      a = _ref3[0];
    var _ref4 = (0, _slicedToArray2.default)(_ref2, 1),
      b = _ref4[0];
    return a.localeCompare(b);
  }).map(function (_ref5) {
    var _ref6 = (0, _slicedToArray2.default)(_ref5, 2),
      property = _ref6[0],
      value = _ref6[1];
    return "".concat(property.startsWith('--') ? property : hyphenate(property), ": ").concat(value, ";");
  }).join(' ');
  return cssString;
}