"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require('./../../ext-esm/tslib/tslib.es6.js'),r=require("react/jsx-runtime"),t=require("react"),s=require("@material-ui/core"),n=require("classnames"),i=require("../../constants/mixpanel.js");require("../DevCenter/DevCenterRouterContext/DevCenterRouterContext.js");var a=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"),c=require("./AssetNameLabel.styles.css.js");function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=l(n),d=s.makeStyles({assetName:{maxWidth:function(e){return e.chipMaxWidth}}}),f=t.memo((function(n){var l,f=n.assetName,m=n.classes,v=n.coordinatesPixelWidth,h=n.dataTestId,p=n.href,x=n.icon,_=n.statusBadge,j=t.useState(f),q=j[0],b=j[1],C=t.useRef(),N=t.useRef(),R=(l=v)>=1024?244:l>=768?184:l>=420?134:44,g=t.useRef(R),A=d({chipMaxWidth:R});return t.useEffect((function(){b(f),N.current=null}),[f]),t.useEffect((function(){N.current||(N.current=C.current.scrollWidth)}),[N.current]),t.useEffect((function(){if(C.current&&N.current){if(R>g.current)return b(f),N.current=null,void(g.current=R);var e=u.truncateInTheMiddle(f,C.current.clientWidth,N.current);b(e),g.current=R}}),[f,R,C.current,N.current]),r.jsx(s.Tooltip,e.__assign({title:f||""},{children:r.jsx("div",e.__assign({className:o.default(c.wrapper)},{children:r.jsxs(a.UniversalLink,e.__assign({className:o.default(c.item,null==m?void 0:m.item),"data-testid":h,href:p,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:[x&&r.jsx("div",e.__assign({className:c.startIcon},{children:x})),r.jsx("span",e.__assign({className:o.default(c.assetName,A.assetName),ref:C},{children:q})),_]}))}))}))}));exports.AssetNameLabel=f;
