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