"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),r=require("classnames"),t=require("react"),n=require("lodash"),i=require("../Tooltip/Tooltip.js"),u=require("./TextMiddleTruncated.scss.js"),s=require("../../utils/formatting.js");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var a=c(r);exports.TextMiddleTruncated=function(r){var c=r.children,d=r.testId,l=r.className,o=r.disableTooltip,f=String(c),v=t.useRef(null),b=t.useRef(null),h=t.useState(f),j=h[0],x=h[1];return t.useLayoutEffect((function(){var e=n.debounce((function(){if(v.current&&b.current){var e=v.current.clientWidth,r=b.current,t=r.clientWidth,n=r.textContent;x(s.truncateInTheMiddle(n,e,t))}}),200,{leading:!0}),r=new ResizeObserver(e),t=new MutationObserver(e);return v.current&&b.current&&(r.observe(v.current),r.observe(b.current),t.observe(b.current,{characterData:!0})),function(){r.disconnect(),t.disconnect()}}),[]),e.jsx(i.Tooltip,{title:f,disabled:o||j===f,children:e.jsxs("div",{className:a.default(u.root,l),ref:v,"data-testid":d,children:[j,e.jsx("div",{className:u.hiddenElement,ref:b,children:f})]})})};
