"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),r=require("react"),t=require("@material-ui/core"),n=require("classnames"),i=require("../../constants/mixpanel.js");require("../DevCenter/DevCenterRouterContext/DevCenterRouterContext.js");var s=require("../DevCenter/DevCenterRouterContext/UniversalLink/UniversalLink.js");require("@babel/runtime/helpers/defineProperty"),require("@babel/runtime/helpers/objectWithoutProperties"),require("react-router");var u=require("../../utils/formatting.js"),a=require("./AssetNameLabel.styles.css.js");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=c(n),o=t.makeStyles({assetName:{maxWidth:function(e){return e.chipMaxWidth}}}),d=r.memo((function(n){var c,d=n.assetName,f=n.classes,m=n.coordinatesPixelWidth,v=n.dataTestId,h=n.href,p=n.icon,x=n.statusBadge,j=r.useState(d),q=j[0],C=j[1],N=r.useRef(),b=r.useRef(),R=(c=m)>=1024?244:c>=768?184:c>=420?134:44,A=r.useRef(R),D=o({chipMaxWidth:R});return r.useEffect((function(){C(d),b.current=null}),[d]),r.useEffect((function(){b.current||(b.current=N.current.scrollWidth)}),[b.current]),r.useEffect((function(){if(N.current&&b.current){if(R>A.current)return C(d),b.current=null,void(A.current=R);var e=u.truncateInTheMiddle(d,N.current.clientWidth,b.current);C(e),A.current=R}}),[d,R,N.current,b.current]),e.jsx(t.Tooltip,{title:d||"",children:e.jsx("div",{className:l.default(a.wrapper),children:e.jsxs(s.UniversalLink,{className:l.default(a.item,null==f?void 0:f.item),"data-testid":v,href:h,onClick:function(){var e;null===(e=window[Symbol.for("logToMixpanel")])||void 0===e||e.call(window,i.MIXPANEL_ACTION_TYPES.REDIRECT.ASSET_DASHBOARD,{referer:"Asset Chip"})},children:[p&&e.jsx("div",{className:a.startIcon,children:p}),e.jsx("span",{className:l.default(a.assetName,D.assetName),ref:N,children:q}),x]})})})}));exports.AssetNameLabel=d;
