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