"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}),x=p[0],T=p[1],_=r.useRef(null),W=r.useRef(null),b=r.useRef(!0);r.useLayoutEffect((function(){var e="string"==typeof u||"number"==typeof u;if(_.current&&W.current&&e){var t=_.current.clientWidth,r=W.current.scrollWidth;return T({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;T((function(t){return e.__assign(e.__assign({},t),{elementWidth:r})}))}}));return _.current&&t.observe(_.current),function(){t.disconnect(),b.current=!0}}),[]);var j=x.textWidth,g=x.elementWidth,y=j>g,q=u.toString(),w=y?s.truncateInTheMiddle(q,g,j):q,N=d&&y?h||u:"";return t.jsx(i.Tooltip,{ref:_,title:N,children:t.jsxs("div",e.__assign({className:o.default(m.root,c)},v,{children:[w,t.jsx("div",{ref:W,className:o.default(m.hiddenText),children:u})]}))})};
