"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react/jsx-runtime"),t=require("react"),n=require("moment"),a=require("classnames"),o=require("@material-ui/core"),i=require("../Tooltip/Tooltip.js");require("../Tooltip/ScrollableTooltip.js");var r=require("./constants.js"),s=require("./components/DQStatusIcon.js"),c=require("./components/DQUnvalidatedContent.js");function u(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var l=u(n),p=u(a),d=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(n){var a=n.assetsData,u=void 0===a?{}:a,f=n.setAssetsData,g=void 0===f?function(){}:f,x=n.appWidth,S=n.DQIssueTooltipMaxHeight,h=void 0===S?d:S,T=n.iconType,I=n.className,v=n.lastTimestamp,b=n.warningData,y=n.hasSubscriptionsData,_=n.maximized,N=n.statusBadgeContentClassName,D=n.tooltipPlacement,E=void 0===D?"top-start":D,j=t.useState(!1),A=j[0],w=j[1],C=t.useRef(null),W=null==b?void 0:b.message,M=T===r.BADGE_ICON_STATUSES.error,B=T===r.BADGE_ICON_STATUSES.success,q=T===r.BADGE_ICON_STATUSES.issue,L=x<r.MAX_MOBILE_WIDTH,O=m({isIconExist:!!T,isSuccessTypeIcon:B,isErrorTypeIcon:M,isIssueTypeIcon:q,maximized:_,tooltipPlacement:E}),Q=t.useRef(null),G=function(e){C.current&&!C.current.contains(e.target)&&w(!1)};t.useEffect((function(){return function(){g({hasSubscriptionsData:!1})}}),[]),t.useEffect((function(){return document.addEventListener("click",G),function(){document.removeEventListener("click",G),clearTimeout(Q.current)}}),[]);var P=function(){clearTimeout(Q.current),w(!0)},k=function(e,t){void 0===t&&(t=700),Q.current=setTimeout((function(){return w(!1)}),t)};return t.useEffect((function(){y&&(P(),k(0,1e4))}),[JSON.stringify(u)]),e.jsx("div",{"data-testid":"Status_badge",className:p.default(O.statusBadgeWrapper,"c-status-badge--".concat(T),I),children:e.jsxs("div",{className:p.default(O.statusBadgeContent,N),ref:C,children:[T&&e.jsx(i.Tooltip,{disableHoverListener:!0,open:A,onMouseEnter:P,onMouseLeave:k,PopperProps:{className:O.popper},placement:E,title:e.jsx(c.DQUnvalidatedContent,{tooltipRef:C,onMouseEnter:P,onMouseLeave:k,assetsData:u,maxHeight:h}),children:e.jsx("div",{className:O.DQIconWrapper,"data-testid":"".concat("Status_badge","__DQ_icon_").concat(T),children:e.jsx(s.DQStatusIcon,{color:T,iconType:T})})}),Number.isFinite(v)&&e.jsxs(o.Typography,{className:p.default(O.text,O.timestamp),variant:"body1",children:["Last Update: ",l.default.unix(v).format("MMM D YYYY, hh:mm A")]}),b&&e.jsxs(e.Fragment,{children:[e.jsx(i.Tooltip,{placement:"top",title:W?"".concat(r.WARNING,". ").concat(W):r.WARNING,children:e.jsx("div",{"data-testid":"".concat("Status_badge","__DQ_icon_warning"),children:e.jsx(s.DQStatusIcon,{className:O.badgeIconWarning,color:r.BADGE_ICON_STATUSES.warning,iconType:r.BADGE_ICON_STATUSES.warning})})}),!L&&e.jsx(o.Typography,{className:p.default(O.text,O.warningMessage),variant:"body1",children:W?"".concat(r.WARNING,". ").concat(W):r.WARNING})]})]})})};
