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