"use strict";

var _postcss = _interopRequireDefault(require("postcss"));

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

module.exports = _postcss.default.plugin('postcss-value-replacer', (valueReplacer = {}) => // Work with options here
root => {
  root.walkDecls(decl => {
    valueReplacer.forEach(obj => {
      if (obj.props.indexOf(decl.prop) !== -1) {
        const ks = Object.keys(obj.values).sort((a, b) => b.length - a.length);
        ks.forEach(k => {
          // if (/^\^.*\$$/gi.test(k)) {
          if (k.startsWith('^') && k.endsWith('$')) {
            decl.value = decl.value.replace(new RegExp(k), obj.values[k]);
          } else {
            decl.value = decl.value.replace(k, obj.values[k]);
          }
        }); //decl.value = obj.values[decl.value];
      }
    }); //console.log({root, roots:root+""}, root+"")
    // Transform CSS AST here
  });
});