'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.cssvarKey = undefined;

var _keys = require('babel-runtime/core-js/object/keys');

var _keys2 = _interopRequireDefault(_keys);

var _flat = require('flat');

var _flat2 = _interopRequireDefault(_flat);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// Convert a JSON key that has been flattened (colors.primary.default)
// into a css var key (--colors-primary-default).
var cssvarKey = exports.cssvarKey = function cssvarKey(k) {
  return '--' + k.replace(/\./g, '-').replace(/[A-Z]/g, function (g) {
    return '-' + g[0].toLowerCase();
  });
};

/**
Converts nested dictionary of keys with css values into a flat dictionary
of cssvars to those same values. For example:

{
  colors: {
    black: "#000"
  }
}

becomes

{
  "--colors-black": "#000"
}
*/

exports.default = function (obj) {
  if (!obj) {
    return '';
  }
  var flatObj = (0, _flat2.default)(obj);
  return (0, _keys2.default)(flatObj).map(function (k) {
    return cssvarKey(k) + ': ' + flatObj[k] + ';';
  });
};