import { j as d } from "../../node_modules/react/jsx-runtime.mjs";
import { useMemo as I } from "react";
import "./index.less.mjs";
const U = ({ autoEscape: c = !0, caseSensitive: f = !1, highlightClass: m = "", highlightTag: u = "span", keywords: r, sourceString: s, tagClass: $ = "", tag: j = "div", unhighlightClass: T = "", unhighlightTag: z = "span" }) => {
  const o = (i) => i ? ` ${i}` : "", H = I(() => {
    const i = f ? "g" : "gi";
    let h = (Array.isArray(r) ? r : [r]).filter((t) => t).reduce((t, e) => {
      c && (e = e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
      const n = new RegExp(e, i);
      let g;
      for (; g = n.exec(s); ) {
        const a = g.index, x = n.lastIndex;
        if (a >= x) {
          n.lastIndex++;
          continue;
        }
        t.push({
          start: a,
          end: x,
          highlight: !0
        });
      }
      return t;
    }, []);
    h = h.sort((t, e) => t.start - e.start).reduce((t, e) => {
      const n = t[t.length - 1];
      if (!n || e.start > n.end) {
        const g = n ? n.end : 0, a = e.start;
        g !== a && t.push({
          start: g,
          end: a,
          highlight: !1
        }), t.push(e);
      } else
        n.end = Math.max(n.end, e.end);
      return t;
    }, []);
    const l = h[h.length - 1];
    return l && l.end < s.length && h.push({
      start: l.end,
      end: s.length,
      highlight: !1
    }), h;
  }, [c, f, r, s]), b = u, A = z, B = () => H.map((i) => {
    const { start: p, end: h, highlight: l } = i, t = s.slice(p, h);
    return l ? d.jsx(b, { className: `bitzHighlightTag${o(m)}`, children: t }) : d.jsx(A, { className: `bitzUnhighlightTag${o(T)}`, children: t });
  }), E = j;
  return d.jsx(E, { className: `bitzHighlightBlock${o($)}`, children: B() });
};
export {
  U as default
};
