text: "use strict";
  var __importDefault = (this && this.__importDefault) || function (mod) {
      return (mod && mod.__esModule) ? mod : { "default": mod };
  };
  Object.defineProperty(exports, "__esModule", { value: true });
  var react_1 = __importDefault(require("react"));
  var SearchQueryContext_1 = __importDefault(require("../../SearchQueryContext"));
  var elasticlunr_1 = __importDefault(require("elasticlunr"));
  var highlight_words_1 = __importDefault(require("highlight-words"));
  var react_markdown_1 = __importDefault(require("react-markdown"));
  // @ts-ignore
  var html_parser_1 = __importDefault(require("react-markdown/plugins/html-parser"));
  var allQueryWords = function (queryWords) {
      return queryWords.reduce(function (allWords, word) {
          var stem = elasticlunr_1.default.stemmer(word);
          allWords.push(word);
          if (stem !== word) {
              allWords.push(stem);
          }
          return allWords;
      }, []);
  };
  var parseHtml = html_parser_1.default();
  var HighLight = function (_a) {
      var text = _a.text, _b = _a.markdown, markdown = _b === void 0 ? false : _b, _c = _a.className, className = _c === void 0 ? '' : _c;
      var searchQueryContext = react_1.default.useContext(SearchQueryContext_1.default);
      var query = allQueryWords(searchQueryContext.query ? searchQueryContext.query.split(' ') : []).join(' ');
      var appliedClassName = className ? "highlight " + className : 'highlight';
      var chunks = highlight_words_1.default({ text: text, query: query });
      if (markdown) {
          var highlightedText = chunks
              .map(function (_a) {
              var text = _a.text, match = _a.match;
              return (match ? "<mark>" + text + "</mark>" : text);
          })
              .join('');
          return (react_1.default.createElement("div", { className: appliedClassName },
              react_1.default.createElement(react_markdown_1.default, { astPlugins: [parseHtml], allowDangerousHtml: true }, highlightedText)));
      }
      return (react_1.default.createElement("span", { className: appliedClassName }, chunks.map(function (_a) {
          var text = _a.text, match = _a.match, key = _a.key;
          return match ? react_1.default.createElement("mark", { key: key }, text) : text;
      })));
  };
  exports.default = HighLight;
  //# sourceMappingURL=HighLight.js.map