"use strict";
const escapeRegExp = require("../../../../../../lodash@4.17.21/node_modules/lodash/escapeRegExp.js");
const React = require("react");
const is = require("./is.js");
const emotionReactJsxRuntime_browser_esm = require("../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js");
function getHighlightText(_a) {
  var nodeList = _a.nodeList, pattern = _a.pattern, highlightClassName = _a.highlightClassName;
  if (!pattern) {
    return nodeList;
  }
  var transformNode = function(node) {
    if (node && node.props && typeof node.props.children === "string") {
      return React.cloneElement(node, void 0, /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(HighlightText, {
        text: node.props.children,
        keyword: pattern,
        highlightClassName
      }));
    }
    return node;
  };
  return is.isArray(nodeList) ? nodeList.map(function(node) {
    return transformNode(node);
  }) : transformNode(nodeList);
}
function HighlightText(_a) {
  var text = _a.text, keyword = _a.keyword, highlightClassName = _a.highlightClassName;
  if (!keyword)
    return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(emotionReactJsxRuntime_browser_esm.Fragment, {
      children: text
    });
  var re = new RegExp("(" + escapeRegExp(keyword) + ")", "i");
  var strArr = text.split(re);
  return /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx(emotionReactJsxRuntime_browser_esm.Fragment, {
    children: strArr.map(function(item, index) {
      return re.test(item) ? /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("span", {
        className: highlightClassName,
        children: item
      }, index) : /* @__PURE__ */ emotionReactJsxRuntime_browser_esm.jsx("span", {
        children: item
      }, index);
    })
  });
}
module.exports = getHighlightText;
//# sourceMappingURL=getHighlightText.js.map
