"use strict";

exports.__esModule = true;
exports.default = void 0;

var _picocolors = _interopRequireDefault(require("picocolors"));

var _tokenize = _interopRequireDefault(require("./tokenize"));

var _input = _interopRequireDefault(require("./input"));

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

var HIGHLIGHT_THEME = {
  brackets: _picocolors.default.cyan,
  'at-word': _picocolors.default.cyan,
  comment: _picocolors.default.gray,
  string: _picocolors.default.green,
  class: _picocolors.default.yellow,
  call: _picocolors.default.cyan,
  hash: _picocolors.default.magenta,
  '(': _picocolors.default.cyan,
  ')': _picocolors.default.cyan,
  '{': _picocolors.default.yellow,
  '}': _picocolors.default.yellow,
  '[': _picocolors.default.yellow,
  ']': _picocolors.default.yellow,
  ':': _picocolors.default.yellow,
  ';': _picocolors.default.yellow
};

function getTokenType(_ref, processor) {
  var type = _ref[0],
      value = _ref[1];

  if (type === 'word') {
    if (value[0] === '.') {
      return 'class';
    }

    if (value[0] === '#') {
      return 'hash';
    }
  }

  if (!processor.endOfFile()) {
    var next = processor.nextToken();
    processor.back(next);
    if (next[0] === 'brackets' || next[0] === '(') return 'call';
  }

  return type;
}

function terminalHighlight(css) {
  var processor = (0, _tokenize.default)(new _input.default(css), {
    ignoreErrors: true
  });
  var result = '';

  var _loop = function _loop() {
    var token = processor.nextToken();
    var color = HIGHLIGHT_THEME[getTokenType(token, processor)];

    if (color) {
      result += token[1].split(/\r?\n/).map(function (i) {
        return color(i);
      }).join('\n');
    } else {
      result += token[1];
    }
  };

  while (!processor.endOfFile()) {
    _loop();
  }

  return result;
}

var _default = terminalHighlight;
exports.default = _default;
module.exports = exports.default;
//# sourceMappingURL=data:application/json;charset=utf8;base64,[encoded data, 4500 characters]
