"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require('./../../ext-esm/tslib/tslib.es6.js'),t=require("react/jsx-runtime"),n=require("react"),a=require("moment"),i=require("classnames"),o=require("@material-ui/core"),s=require("../Tooltip/Tooltip.js");require("../Tooltip/ScrollableTooltip.js");var r=require("./constants.js"),c=require("./components/DQStatusIcon.js"),u=require("./components/DQUnvalidatedContent.js");function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var p=l(a),d=l(i),g=window.innerHeight-212,m=o.makeStyles((function(e){return{statusBadgeWrapper:{backgroundColor:e.palette.background.b4,display:"flex",height:30},statusBadgeContent:{display:"flex",padding:function(e){var t=e.isSuccessTypeIcon,n=e.isErrorTypeIcon,a=e.isIssueTypeIcon;return"12px 0 2px ".concat(t||n||a?6:2,"px")},whiteSpace:"nowrap",width:"calc(100% - 140px)"},text:{fontSize:"10px",lineHeight:"12px",alignSelf:"center"},timestamp:{color:e.palette.primary.text6,marginLeft:function(e){return e.isIconExist&&4}},warningMessage:{color:e.palette.primary.text1,marginLeft:4,textOverflow:"ellipsis",overflow:"hidden",fontSize:"12px"},badgeIconWarning:{marginLeft:8},popper:{zIndex:function(e){return e.maximized?500:400},"& .MuiTooltip-tooltip":{position:"absolute",bottom:function(e){return e.tooltipPlacement.includes("top")?0:"auto"},top:function(e){return e.tooltipPlacement.includes("bottom")?0:"auto"},left:function(e){return e.tooltipPlacement.includes("right")?0:"auto"},right:function(e){return e.tooltipPlacement.includes("left")?0:"auto"},width:"max-content",transformOrigin:"center top",maxWidth:"none",padding:4,fontSize:12,boxShadow:"none",fontWeight:400,lineHeight:"16px",letterSpacing:0,backgroundColor:e.palette.background.b9}},DQIconWrapper:{display:"flex",alignItems:"center",alignSelf:"center",justifyContent:"center",height:24,width:24,minWidth:24,borderRadius:12,"&:hover":{backgroundColor:function(e){var t=e.isErrorTypeIcon,n=e.isSuccessTypeIcon,a=e.isIssueTypeIcon;return t?"rgba(244, 67, 54, 0.1)":n?"rgba(117, 219, 41, 0.2)":a?"rgba(255, 193, 7, 0.16)":"transparent"}}}}}));exports.StatusBadge=function(a){var i=a.assetsData,l=void 0===i?{}:i,f=a.setAssetsData,x=void 0===f?function(){}:f,_=a.appWidth,S=a.DQIssueTooltipMaxHeight,h=void 0===S?g:S,T=a.iconType,I=a.className,b=a.lastTimestamp,v=a.warningData,y=a.hasSubscriptionsData,N=a.maximized,D=a.statusBadgeContentClassName,E=a.tooltipPlacement,j=void 0===E?"top-start":E,A=n.useState(!1),w=A[0],C=A[1],W=n.useRef(null),M=null==v?void 0:v.message,B=T===r.BADGE_ICON_STATUSES.error,q=T===r.BADGE_ICON_STATUSES.success,L=T===r.BADGE_ICON_STATUSES.issue,O=_<r.MAX_MOBILE_WIDTH,Q=m({isIconExist:!!T,isSuccessTypeIcon:q,isErrorTypeIcon:B,isIssueTypeIcon:L,maximized:N,tooltipPlacement:j}),G=n.useRef(null),P=function(e){W.current&&!W.current.contains(e.target)&&C(!1)};n.useEffect((function(){return function(){x({hasSubscriptionsData:!1})}}),[]),n.useEffect((function(){return document.addEventListener("click",P),function(){document.removeEventListener("click",P),clearTimeout(G.current)}}),[]);var k=function(){clearTimeout(G.current),C(!0)},R=function(e,t){void 0===t&&(t=700),G.current=setTimeout((function(){return C(!1)}),t)};return n.useEffect((function(){y&&(k(),R(0,1e4))}),[JSON.stringify(l)]),t.jsx("div",e.__assign({"data-testid":"Status_badge",className:d.default(Q.statusBadgeWrapper,"c-status-badge--".concat(T),I)},{children:t.jsxs("div",e.__assign({className:d.default(Q.statusBadgeContent,D),ref:W},{children:[T&&t.jsx(s.Tooltip,e.__assign({disableHoverListener:!0,open:w,onMouseEnter:k,onMouseLeave:R,PopperProps:{className:Q.popper},placement:j,title:t.jsx(u.DQUnvalidatedContent,{tooltipRef:W,onMouseEnter:k,onMouseLeave:R,assetsData:l,maxHeight:h})},{children:t.jsx("div",e.__assign({className:Q.DQIconWrapper,"data-testid":"".concat("Status_badge","__DQ_icon_").concat(T)},{children:t.jsx(c.DQStatusIcon,{color:T,iconType:T})}))})),Number.isFinite(b)&&t.jsxs(o.Typography,e.__assign({className:d.default(Q.text,Q.timestamp),variant:"body1"},{children:["Last Update: ",p.default.unix(b).format("MMM D YYYY, hh:mm A")]})),v&&t.jsxs(t.Fragment,{children:[t.jsx(s.Tooltip,e.__assign({placement:"top",title:M?"".concat(r.WARNING,". ").concat(M):r.WARNING},{children:t.jsx("div",e.__assign({"data-testid":"".concat("Status_badge","__DQ_icon_warning")},{children:t.jsx(c.DQStatusIcon,{className:Q.badgeIconWarning,color:r.BADGE_ICON_STATUSES.warning,iconType:r.BADGE_ICON_STATUSES.warning})}))})),!O&&t.jsx(o.Typography,e.__assign({className:d.default(Q.text,Q.warningMessage),variant:"body1"},{children:M?"".concat(r.WARNING,". ").concat(M):r.WARNING}))]})]}))}))};
