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