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