import {escapeRegExp} from "./common";

export function highlightSearchTerm(text: string, term: string) {
  // Split on highlight term and include term into parts, ignore case
  const parts = text.split(new RegExp(`(${escapeRegExp(term)})`, "gi"));
  return <span> {parts.map((part, i) =>
    <span key={i} style={part.toLowerCase() === term.toLowerCase() ? {
      fontWeight: 'bold',
      backgroundColor: '#e6e6e6'
    } : {}}>
          {part}
      </span>)
  } </span>;
}
