import t from"@babel/runtime/helpers/defineProperty";import e from"@babel/runtime/helpers/slicedToArray";import i from"prop-types";import{useRef as n,useState as r,useMemo as o,useEffect as a,createRef as c}from"react";import l from"classnames";import{makeStyles as s,Typography as d,Tooltip as p}from"@material-ui/core";import{sumBy as u,upperFirst as h}from"lodash";import{drawRadicalGradient as m,drawDonutSlice as g}from"./utils.js";import{Regular14 as f}from"../Typography.js";import{jsxs as x,jsx as v,Fragment as b}from"react/jsx-runtime";var y=s((function(t){return{root:{width:"228px",height:"228px",borderRadius:"50%",padding:"6px",position:"relative",background:"url(".concat("/static/media/9bda514bfc837939d0b6f7d8dbe94d03.svg",")"),backgroundRepeat:"no-repeat"},backgroundRoot:{width:"100%",height:"100%",borderRadius:"50%",border:"2px solid #616161",padding:"2px",display:"flex",alignItems:"center",justifyContent:"center",overflow:"hidden",background:"url(".concat("/static/media/49092309a3fda5ecf77311bd794ac103.svg",")")},emptyStateBackground:{background:"radial-gradient(50% 50% at 50% 50%, rgba(100, 181, 246, 0) 54.4%, rgba(100, 181, 246, 0.01) 76.49%, rgba(100, 181, 246, 0.06) 100%)"},dropShadowRoot:{width:"100%",height:"100%",borderRadius:"50%",filter:"blur(36px)",border:"2px solid #64B5F6",display:"flex",alignItems:"center",justifyContent:"center"},content:function(t){return{position:"absolute",width:"100%",height:"100%",display:"flex",alignItems:"center",flexDirection:"column",left:0,top:t.activitiesLength?40:57}},lastActivityRoot:{width:"90px",height:"90px",background:"#3B3B3B",boxShadow:"0px 2px 2px rgba(0, 0, 0, 0.1), inset 0px 1px 1px rgba(255, 255, 255, 0.05)",borderRadius:"50%",display:"flex",alignItems:"center",justifyContent:"center",margin:"8px 0"},activityDuration:{marginTop:"9px",color:t.palette.primary.text1,fontSize:"36px",lineHeight:"24px",fontWeight:300,letterSpacing:"0.4px"},durationUnit:{fontSize:"12px",lineHeight:"24px",fontWeight:500,letterSpacing:"0.4px"},activityTimeRange:{fontSize:"10px",textTransform:"uppercase",color:"#9E9E9E",lineHeight:"24px",fontWeight:500,letterSpacing:"1px"},activityName:{width:"106px",textAlign:"center",fontSize:"12px",lineHeight:"14px",fontWeight:500,letterSpacing:"0.4px",color:t.palette.primary.text1},noOperationsRoot:{width:90,height:90},noOperationsText:{marginTop:24,color:"#9E9E9E"},chart:{position:"absolute",left:2,top:2,width:"100%",height:"100%",padding:"12px"},canvas:{width:"100%",height:"100%"},activities:{position:"absolute",left:12,top:12}}}));function w(i){var s=i.title,w=i.currentActivityName,N=i.activities,R=i.showTooltip,S=y({activitiesLength:N.length}),T=n(null),k=n([]),E=r(null),A=e(E,2),j=A[0],B=A[1],C=o((function(){return N.filter((function(t){return t.duration}))}),[N]),I=o((function(){return u(N,"duration")}),[N]),O=o((function(){return null===j?N.find((function(t){return t.name===w})):C[j]}),[N,w,C,j]),P=function(t){var e=!1;k.current.forEach((function(i,n){var r=i.current;if(r&&!e){var o=r.getContext("2d");(e=o.isPointInPath(t.offsetX,t.offsetY))&&B(n)}})),e||B(null)},z=function(){B(null)};return a((function(){var t=T.current,e=t.getContext("2d");t.width=200,t.height=200,t.style.width="".concat(200,"px"),t.style.height="".concat(200,"px");var i=C.length;k.current.length!==i&&(k.current=Array(i).fill().map((function(t,e){return k.current[e]||c()})));var n=0;C.forEach((function(t,i){var r=n,o=r+t.duration/I*Math.PI*2;(null===j&&t.name===w||i===j)&&m(e,100,100,100,r,o);var a=k.current[i].current;if(a){a.width=200,a.height=200,a.style.width="".concat(200,"px"),a.style.height="".concat(200,"px"),R&&(a.onmousemove=P,a.onmouseleave=z);var c=a.getContext("2d");g(c,100,100,100,r,o,t.color||"#000000",!0)}else g(e,100,100,100,r,o,t.color||"#000000",!0);n=o}))})),x("div",{className:S.root,children:[v("div",{className:l(S.backgroundRoot,t({},S.emptyStateBackground,!N.length)),children:v("div",{className:S.dropShadowRoot})}),x("div",{className:S.content,children:[v(d,{className:S.activityTimeRange,children:s}),N.length?x(b,{children:[v("div",{className:S.lastActivityRoot,children:O&&O.duration?x(d,{className:S.activityDuration,children:[(O.duration/3600).toFixed(1),v("span",{className:S.durationUnit,children:" h"})]}):null}),v(d,{className:S.activityName,children:h((null==O?void 0:O.name)||"")})]}):v("div",{className:S.noOperationsRoot,children:v(f,{className:S.noOperationsText,children:"No operations"})})]}),v(p,{title:null!==j?"".concat(C[j].name,": ").concat((C[j].duration/3600).toFixed(3),"h"):"",placement:"bottom",children:x("div",{className:S.chart,children:[v("canvas",{ref:T,className:S.canvas}),C.map((function(t,e){return v("canvas",{ref:k.current[e],className:S.activities})}))]})})]})}w.propTypes={title:i.string,activities:i.arrayOf(i.shape({name:i.string,day:i.number,night:i.number})).isRequired,currentActivityName:i.string.isRequired,showTooltip:i.bool},w.defaultProps={title:"Last 24hrs",showTooltip:!1};export{w as default};
