'use strict';

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.highlight = highlight;
exports.handleTextParts = handleTextParts;
exports.addHighLightTags = addHighLightTags;

var _react = _interopRequireDefault(require("react"));

function highlight(regExp, text, title) {
  if (regExp === void 0) {
    regExp = null;
  }

  if (text === void 0) {
    text = null;
  }

  if (regExp === null || text === null) {
    return _react.default.createElement("span", {
      title: title
    }, text);
  }

  var highlightedText = String(text).replace(regExp, handleTextParts);
  return _react.default.createElement("span", {
    title: title,
    dangerouslySetInnerHTML: {
      __html: highlightedText
    }
  });
}

function handleTextParts() {
  var parts = [].slice.call(arguments, 1, -2);
  return parts.map(addHighLightTags).join('');
}

function addHighLightTags(part, index) {
  return index % 2 === 1 ? "<strong>" + part + "</strong>" : part;
}