"use client";
import { useProps } from "../../core/MantineProvider/use-props/use-props.mjs";
import { polymorphicFactory } from "../../core/factory/polymorphic-factory.mjs";
import { Text } from "../Text/Text.mjs";
import { Mark } from "../Mark/Mark.mjs";
import { foldAccents, highlighter } from "./highlighter/highlighter.mjs";
import { jsx } from "react/jsx-runtime";
//#region packages/@mantine/core/src/components/Highlight/Highlight.tsx
const defaultProps = {
	color: "yellow",
	wholeWord: false,
	caseInsensitive: true,
	accentInsensitive: true
};
const Highlight = polymorphicFactory((_props) => {
	const { unstyled, children, highlight, highlightStyles, color, wholeWord, caseInsensitive, accentInsensitive, ...others } = useProps("Highlight", defaultProps, _props);
	const isTermArray = Array.isArray(highlight) && typeof highlight[0] === "object";
	const colorMap = /* @__PURE__ */ new Map();
	const normalizeKey = (s) => {
		let key = s;
		if (caseInsensitive) key = key.toLowerCase();
		if (accentInsensitive) key = foldAccents(key);
		return key;
	};
	let highlightStrings;
	if (isTermArray) highlightStrings = highlight.map((term) => {
		if (term.color) colorMap.set(normalizeKey(term.text), term.color);
		return term.text;
	});
	else if (Array.isArray(highlight)) highlightStrings = highlight;
	else highlightStrings = [highlight];
	const highlightChunks = highlighter(children, highlightStrings, {
		wholeWord,
		caseInsensitive,
		accentInsensitive
	});
	return /* @__PURE__ */ jsx(Text, {
		unstyled,
		...others,
		__staticSelector: "Highlight",
		children: highlightChunks.map(({ chunk, highlighted }, i) => highlighted ? /* @__PURE__ */ jsx(Mark, {
			unstyled,
			color: colorMap.get(normalizeKey(chunk)) || color,
			style: highlightStyles,
			"data-highlight": chunk,
			children: chunk
		}, i) : /* @__PURE__ */ jsx("span", { children: chunk }, i))
	});
});
Highlight.classes = Text.classes;
Highlight.displayName = "@mantine/core/Highlight";
//#endregion
export { Highlight };

//# sourceMappingURL=Highlight.mjs.map