import { jsx, Fragment } from 'react/jsx-runtime';
import classNames from '../../_virtual/index.js';
import { Fragment as Fragment$1 } from 'react';

// Function to escape special characters in the search term
const escapeRegExp = (text) => {
    return text?.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
};
const HighlightText = ({ text = '', highlight = '', onlyExactMatch = false, }) => {
    if (!highlight)
        return jsx("span", { children: text });
    const escapedHighlight = escapeRegExp(highlight); // Escape special characters
    const parts = text?.split(new RegExp(`(${escapedHighlight})`, 'gi')); // Use escaped string in the regex
    if (onlyExactMatch) {
        const isTextEqualsHighlight = text.toLowerCase() === highlight.toLowerCase();
        return (jsx("span", { className: classNames(isTextEqualsHighlight ? 'ff-highlight-bg' : ''), children: text }));
    }
    return (jsx(Fragment, { children: parts.map((part, index) => part?.toLowerCase() === highlight?.toLowerCase() ? (jsx("span", { className: "ff-highlight-bg", children: part }, `highlight-${index}-${part}`)) : (jsx(Fragment$1, { children: part }, `normal-${index}-${part}`))) }));
};

export { HighlightText as default };
//# sourceMappingURL=HighlightText.js.map
