import{jsx as e}from"react/jsx-runtime";import t from"classnames";import{useRef as r,useState as i,useLayoutEffect as n}from"react";import{debounce as o}from"lodash";import{Tooltip as s}from"../Tooltip/Tooltip.js";import c from"./TextTruncated.scss.js";var l=function(l){var a=l.children,d=l.disableTooltip,m=l.maxLines,u=void 0===m?1:m,f=l.testId,p=l.className,v=u>1,h=r(null),b=r(v),x=i(null),L=x[0],T=x[1],g=i(!0),j=g[0],W=g[1];return b.current=v,n((function(){var e=o((function(){var e=h.current;e&&(T(e.textContent),W(e.scrollWidth<=e.clientWidth&&(e.scrollHeight<=e.clientHeight||!b.current)))}),200),t=new ResizeObserver(e),r=new MutationObserver(e);return h.current&&(t.observe(h.current),r.observe(h.current,{childList:!0,subtree:!0,characterData:!0})),function(){t.disconnect(),r.disconnect()}}),[]),e(s,{title:L,disabled:j||d,children:e("div",{className:t(c.root,v?c.multiLine:c.singleLine,p),style:v?{WebkitLineClamp:u}:void 0,ref:h,"data-testid":f,children:a})})};export{l as TextTruncated};
