"use client";
const require_use_props = require("../../core/MantineProvider/use-props/use-props.cjs");
const require_polymorphic_factory = require("../../core/factory/polymorphic-factory.cjs");
const require_Text = require("../Text/Text.cjs");
const require_Mark = require("../Mark/Mark.cjs");
const require_highlighter = require("./highlighter/highlighter.cjs");
let react_jsx_runtime = require("react/jsx-runtime");
//#region packages/@mantine/core/src/components/Highlight/Highlight.tsx
const defaultProps = {
	color: "yellow",
	wholeWord: false,
	caseInsensitive: true,
	accentInsensitive: true
};
const Highlight = require_polymorphic_factory.polymorphicFactory((_props) => {
	const { unstyled, children, highlight, highlightStyles, color, wholeWord, caseInsensitive, accentInsensitive, ...others } = require_use_props.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 = require_highlighter.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 = require_highlighter.highlighter(children, highlightStrings, {
		wholeWord,
		caseInsensitive,
		accentInsensitive
	});
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Text.Text, {
		unstyled,
		...others,
		__staticSelector: "Highlight",
		children: highlightChunks.map(({ chunk, highlighted }, i) => highlighted ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_Mark.Mark, {
			unstyled,
			color: colorMap.get(normalizeKey(chunk)) || color,
			style: highlightStyles,
			"data-highlight": chunk,
			children: chunk
		}, i) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: chunk }, i))
	});
});
Highlight.classes = require_Text.Text.classes;
Highlight.displayName = "@mantine/core/Highlight";
//#endregion
exports.Highlight = Highlight;

//# sourceMappingURL=Highlight.cjs.map