/** @license MIT | @cube-dev/ui-kit v0.0.0-canary-e634e55 | Cube Dev Team */
import { _Text } from "./Text.js";
import { jsx } from "react/jsx-runtime";

//#region src/components/content/highlightText.tsx
/**
* Highlights occurrences of a search string within text.
* Returns an array of ReactNodes with highlighted portions wrapped in Text.Highlight.
*/
function highlightText(text, highlight, caseSensitive, highlightStyles) {
	if (!highlight) return [text];
	const flags = caseSensitive ? "g" : "gi";
	const escapedHighlight = highlight.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
	const regex = new RegExp(`(${escapedHighlight})`, flags);
	return text.split(regex).map((part, index) => {
		if (caseSensitive ? part === highlight : part.toLowerCase() === highlight.toLowerCase()) return /* @__PURE__ */ jsx(_Text.Highlight, {
			styles: highlightStyles,
			children: part
		}, index);
		return part;
	});
}

//#endregion
export { highlightText };
//# sourceMappingURL=highlightText.js.map