import{jsx as r,jsxs as e}from"react/jsx-runtime";import t from"classnames";import{useRef as n,useState as i,useLayoutEffect as o}from"react";import{debounce as c}from"lodash";import{Tooltip as s}from"../Tooltip/Tooltip.js";import a from"./TextMiddleTruncated.scss.js";import{truncateInTheMiddle as l}from"../../utils/formatting.js";var d=function(d){var m=d.children,u=d.testId,f=d.className,p=d.disableTooltip,v=String(m),h=n(null),b=n(null),T=i(v),j=T[0],x=T[1];return o((function(){var r=c((function(){if(h.current&&b.current){var r=h.current.clientWidth,e=b.current,t=e.clientWidth,n=e.textContent;x(l(n,r,t))}}),200,{leading:!0}),e=new ResizeObserver(r),t=new MutationObserver(r);return h.current&&b.current&&(e.observe(h.current),e.observe(b.current),t.observe(b.current,{characterData:!0})),function(){e.disconnect(),t.disconnect()}}),[]),r(s,{title:v,disabled:p||j===v,children:e("div",{className:t(a.root,f),ref:h,"data-testid":u,children:[j,r("div",{className:a.hiddenElement,ref:b,children:v})]})})};export{d as TextMiddleTruncated};
