import{__rest as t,__assign as e}from'./../../ext-esm/tslib/tslib.es6.js';import{jsx as r,jsxs as i}from"react/jsx-runtime";import{useState as n,useRef as o,useLayoutEffect as l,useEffect as c}from"react";import{makeStyles as s,Tooltip as u}from"@material-ui/core";import d from"classnames";import{truncateInTheMiddle as m}from"../../utils/formatting.js";var a=s({root:{position:"relative",overflow:"hidden",whiteSpace:"nowrap"},hiddenText:{position:"absolute",visibility:"hidden"}}),h=function(s){var h=s.children,f=s.className,p=s.showTooltip,v=void 0===p||p,W=s.customTooltipTitle,T=void 0===W?"":W,b=t(s,["children","className","showTooltip","customTooltipTitle"]),x=a(),w=n({elementWidth:0,textWidth:0}),g=w[0],N=w[1],j=o(null),y=o(null),S=o(!0);l((function(){var t="string"==typeof h||"number"==typeof h;if(j.current&&y.current&&t){var e=j.current.clientWidth,r=y.current.scrollWidth;return N({elementWidth:e,textWidth:r}),function(){S.current=!0}}}),[h]),c((function(){var t=new ResizeObserver((function(t){if(S.current)S.current=!1;else{var r=t[0].target.clientWidth;N((function(t){return e(e({},t),{elementWidth:r})}))}}));return j.current&&t.observe(j.current),function(){t.disconnect(),S.current=!0}}),[]);var z=g.textWidth,O=g.elementWidth,R=z>O,_=h.toString(),k=R?m(_,O,z):_;return r(u,e({ref:j,title:v&&R?T||h:""},{children:i("div",e({className:d(x.root,f)},b,{children:[k,r("div",e({ref:y,className:d(x.hiddenText)},{children:h}))]}))}))};export{h as MiddleTruncatedText};
