"use client"; import React from "react"; interface KeywordHighlighterProps { text: string; keyword: string | null | undefined; } export function KeywordHighlighter({ text, keyword }: KeywordHighlighterProps) { if (!keyword || !text || keyword.trim() === "") { return <>{text}; } const escapedKeyword = keyword.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&"); const regex = new RegExp(`(${escapedKeyword})`, "gi"); const parts = text.split(regex); return ( <> {parts.map((part, i) => regex.test(part) ? ( {part} ) : ( part ) )} ); }