import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
import './HighlightText.scss';
import classNames from 'classnames';
import { Fragment } 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, { children: part }, `normal-${index}-${part}`))) }));
};
export default HighlightText;
//# sourceMappingURL=HighlightText.js.map