import e from"@babel/runtime/helpers/defineProperty";import t from"@babel/runtime/helpers/slicedToArray";import r from"@babel/runtime/helpers/objectWithoutProperties";import{jsx as i,jsxs as n}from"react/jsx-runtime";import{useState as o,useRef as c,useLayoutEffect as l,useEffect as s}from"react";import{makeStyles as u,Tooltip as a}from"@material-ui/core";import p from"classnames";import{truncateInTheMiddle as m}from"../../utils/formatting.js";var f=["children","className","showTooltip","customTooltipTitle"];function d(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,i)}return r}function h(t){for(var r=1;r<arguments.length;r++){var i=null!=arguments[r]?arguments[r]:{};r%2?d(Object(i),!0).forEach((function(r){e(t,r,i[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):d(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}var b=u({root:{position:"relative",overflow:"hidden",whiteSpace:"nowrap"},hiddenText:{position:"absolute",visibility:"hidden"}}),v=function(e){var u=e.children,d=e.className,v=e.showTooltip,O=void 0===v||v,y=e.customTooltipTitle,j=void 0===y?"":y,w=r(e,f),g=b(),W=o({elementWidth:0,textWidth:0}),P=t(W,2),T=P[0],x=P[1],D=c(null),N=c(null),S=c(!0);l((function(){var e="string"==typeof u||"number"==typeof u;if(D.current&&N.current&&e){var t=D.current.clientWidth,r=N.current.scrollWidth;return x({elementWidth:t,textWidth:r}),function(){S.current=!0}}}),[u]),s((function(){var e=new ResizeObserver((function(e){if(S.current)S.current=!1;else{var t=e[0].target.clientWidth;x((function(e){return h(h({},e),{},{elementWidth:t})}))}}));return D.current&&e.observe(D.current),function(){e.disconnect(),S.current=!0}}),[]);var E=T.textWidth,k=T.elementWidth,z=E>k,A=u.toString(),R=z?m(A,k,E):A;return i(a,{ref:D,title:O&&z?j||u:"",children:n("div",h(h({className:p(g.root,d)},w),{},{children:[R,i("div",{ref:N,className:p(g.hiddenText),children:u})]}))})};export{v as MiddleTruncatedText};
//# sourceMappingURL=MiddleTruncatedText.js.map
