/** @license MIT | @cube-dev/ui-kit v0.0.0-canary-b67433b | Cube Dev Team */
import { extractStyles } from "../../../utils/styles.js";
import { TEXT_PROP_MAP, _Text } from "../Text.js";
import { highlightText } from "../highlightText.js";
import { useAutoTooltip } from "../use-auto-tooltip.js";
import { BASE_STYLES, COLOR_STYLES, TEXT_STYLES, filterBaseProps, tasty } from "@tenphi/tasty";
import { forwardRef, useMemo } from "react";
import { jsx } from "react/jsx-runtime";

//#region src/components/content/TextItem/TextItem.tsx
const STYLE_LIST = [
	...BASE_STYLES,
	...TEXT_STYLES,
	...COLOR_STYLES
];
const TextItemElement = tasty(_Text, {
	qa: "TextItem",
	styles: {
		display: "inline-block",
		verticalAlign: "bottom",
		width: "max 100%",
		whiteSpace: "nowrap",
		overflow: "hidden",
		textOverflow: "ellipsis"
	}
});
const TextItem = forwardRef(function TextItem(props, ref) {
	const { children, highlight, highlightCaseSensitive = false, highlightStyles, tooltip = true, tooltipPlacement = "top", ...restProps } = props;
	const styles = extractStyles(restProps, STYLE_LIST, {}, TEXT_PROP_MAP);
	const { labelRef, renderWithTooltip } = useAutoTooltip({
		tooltip,
		children
	});
	const processedChildren = useMemo(() => {
		if (typeof children === "string" && highlight) return highlightText(children, highlight, highlightCaseSensitive, highlightStyles);
		return children;
	}, [
		children,
		highlight,
		highlightCaseSensitive,
		highlightStyles
	]);
	const renderElement = (tooltipTriggerProps, tooltipRef) => {
		const handleRef = (element) => {
			if (typeof ref === "function") ref(element);
			else if (ref) ref.current = element;
			if (tooltipRef) tooltipRef.current = element;
			labelRef(element);
		};
		return /* @__PURE__ */ jsx(TextItemElement, {
			...filterBaseProps(restProps, { eventProps: true }),
			...tooltipTriggerProps,
			ref: handleRef,
			styles,
			children: processedChildren
		});
	};
	return renderWithTooltip(renderElement, tooltipPlacement);
});
TextItem.displayName = "TextItem";

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