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