import{__assign as t}from'./../../ext-esm/tslib/tslib.es6.js';import{jsxs as e,jsx as n,Fragment as o}from"react/jsx-runtime";import{useState as i,useRef as r,useEffect as a}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 f}from"./constants.js";import{DQStatusIcon as g}from"./components/DQStatusIcon.js";import{DQUnvalidatedContent as x}from"./components/DQUnvalidatedContent.js";import{ReportIssueModal as h}from"./components/ReportIssueModal.js";import{postReportError as b}from"./api.js";var v=window.innerHeight-212,I=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"}}}}})),y=function(p){var y=p.assetsData,T=void 0===y?{}:y,S=p.setAssetsData,w=void 0===S?function(){}:S,D=p.appWidth,C=p.DQIssueTooltipMaxHeight,M=void 0===C?v:C,_=p.iconType,j=p.className,N=p.lastTimestamp,k=p.onReportErrorClick,E=p.warningData,W=p.hasSubscriptionsData,L=p.currentUser,P=p.segment,z=p.maximized,Q=p.statusBadgeContentClassName,H=p.tooltipPlacement,B=void 0===H?"top-start":H,O=i(!1),R=O[0],Y=O[1],U=i(!1),A=U[0],F=U[1],J=r(null),q=null==E?void 0:E.message,G=_===d.error,K=_===d.success,V=_===d.issue,X=D<f,Z=I({isIconExist:!!_,isSuccessTypeIcon:K,isErrorTypeIcon:G,isIssueTypeIcon:V,maximized:z,tooltipPlacement:B}),$=r(null),tt=function(t){J.current&&!J.current.contains(t.target)&&F(!1)};a((function(){return function(){w({hasSubscriptionsData:!1})}}),[]),a((function(){return document.addEventListener("click",tt),function(){document.removeEventListener("click",tt),clearTimeout($.current)}}),[]);var et=function(){clearTimeout($.current),F(!0)},nt=function(t,e){void 0===e&&(e=700),$.current=setTimeout((function(){return F(!1)}),e)};return a((function(){W&&(et(),nt(0,1e4))}),[JSON.stringify(T)]),e("div",t({"data-testid":"Status_badge",className:c(Z.statusBadgeWrapper,"c-status-badge--".concat(_),j)},{children:[e("div",t({className:c(Z.statusBadgeContent,Q),ref:J},{children:[_&&n(u,t({disableHoverListener:!0,open:A,onMouseEnter:et,onMouseLeave:nt,PopperProps:{className:Z.popper},placement:B,title:n(x,{tooltipRef:J,onMouseEnter:et,onMouseLeave:nt,assetsData:T,maxHeight:M,onClick:function(){return Y(!0)}})},{children:n("div",t({className:Z.DQIconWrapper,"data-testid":"".concat("Status_badge","__DQ_icon_").concat(_)},{children:n(g,{color:_,iconType:_})}))})),Number.isFinite(N)&&e(l,t({className:c(Z.text,Z.timestamp),variant:"body1"},{children:["Last Update: ",s.unix(N).format("MMM D YYYY, hh:mm A")]})),E&&e(o,{children:[n(u,t({placement:"top",title:q?"".concat(m,". ").concat(q):m},{children:n("div",t({"data-testid":"".concat("Status_badge","__DQ_icon_warning")},{children:n(g,{className:Z.badgeIconWarning,color:d.warning,iconType:d.warning})}))})),!X&&n(l,t({className:c(Z.text,Z.warningMessage),variant:"body1"},{children:q?"".concat(m,". ").concat(q):m}))]})]})),R&&n(h,{assets:Object.keys(T).map((function(t){return{name:t,id:T[t][0].alert.assetId}})),onSave:k||function(t,e){b(e,t,L,P)},onClose:function(){return Y(!1)}})]}))};export{y as StatusBadge};
