import{jsx as i}from"react/jsx-runtime";import{forwardRef as t,useRef as e,useMemo as r,useLayoutEffect as o}from"react";import s from"classnames";import n from"../Tooltip/Tooltip.js";import l from"../../hooks/useIsOverflowing.js";import a from"../../hooks/useMergeRefs.js";import"./TextWithHighlight.scss.js";var p=function(t,e,r){var o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"em",n=arguments.length>4?arguments[4]:void 0,l=o;return r?i(l,Object.assign({className:s("highlight-text",n)},{children:t}),e):i("span",{children:t},e)},m=t((function(t,m){var h=t.className,c=t.id,g=t.text,f=void 0===g?"":g,d=t.highlightTerm,u=t.limit,v=t.useEllipsis,j=void 0===v||v,T=t.linesToClamp,x=void 0===T?3:T,w=t.ignoreCase,E=void 0===w||w,N=t.allowTermSplit,O=void 0===N||N,b=t.nonEllipsisTooltip,C=t.tooltipPosition,k=t.wrappingTextTag,y=void 0===k?"em":k,P=t.wrappingElementClassName,R=e(null),H=a({refs:[m,R]}),I=r((function(){if(!f||!d||0===u)return f;var i=d;O&&(i=d.split(" ").join("|"));for(var t=f.split(RegExp("(".concat(i,")"),E?"i":"")),e=[],r=0,o=0,s=0;t.length>s;s++)if(t[s]){var n=s%2==1;e.push(p(t[s],o++,n&&(!u||0>u||u>r),y,P)),n&&r++}return e}),[f,d,u,E,O,y,P]),M=l({ref:j&&R});o((function(){R.current&&R.current.style.setProperty("--heading-clamp-lines",x)}),[R,x]);var S=i("div",Object.assign({ref:H,className:s("text-with-highlight--wrapper",h,{"with-ellipsis":j}),id:c},{children:I}));return M||b?i(n,Object.assign({content:M?f:b,position:C},{children:S})):S}));export{m as default};
