import escapeRegExp_1 from "../../../../../../lodash@4.17.21/node_modules/lodash/escapeRegExp.js";
import { cloneElement } from "react";
import { isArray } from "./is.js";
import { jsx, Fragment } from "../../../../../../@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 cloneElement(node, void 0, /* @__PURE__ */ jsx(HighlightText, {
        text: node.props.children,
        keyword: pattern,
        highlightClassName
      }));
    }
    return node;
  };
  return 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__ */ jsx(Fragment, {
      children: text
    });
  var re = new RegExp("(" + escapeRegExp_1(keyword) + ")", "i");
  var strArr = text.split(re);
  return /* @__PURE__ */ jsx(Fragment, {
    children: strArr.map(function(item, index) {
      return re.test(item) ? /* @__PURE__ */ jsx("span", {
        className: highlightClassName,
        children: item
      }, index) : /* @__PURE__ */ jsx("span", {
        children: item
      }, index);
    })
  });
}
export {
  getHighlightText as default
};
//# sourceMappingURL=getHighlightText.js.map
