import{r as p}from"./vendor-react-Dvs43sk9.js";import{D as L,j as f,b7 as T,T as j,ak as k,W as t}from"./vendor-mui-core-CnXrAOs3.js";import{E as C}from"./index-NomqB6Iy.js";import{a as D}from"./vendor-utils-cJEl_UEd.js";const A=a=>{const h=new Date(Math.min(...a)),r=(new Date(Math.max(...a))-h)/(1e3*60);return u=>{if(r<=10){const c=(a.length-a.length%r)/r;return u%c===0}const d=(a.length-a.length%6)/6;return u%d===0}};function S({title:a="",total:h=0,history:s=[],valueFn:b=n=>n,xAxisFormat:r=n=>n,visualMapPieces:u=[],markLineData:v={},extraInfo:d=null,empty:w=null,onHover:c=()=>{},hoverIndex:i=null}){const n=L(),o=p.useRef(null),y=p.useMemo(()=>D(s)?[]:s.map(e=>r(e.date)),[s,r]);p.useEffect(()=>{if(!o.current||i?.ref===o)return;const e=o.current.getEchartsInstance(),l=i?.seriesIndex,x=y.findIndex(g=>g===i?.dataValue);i&&x!==-1?e.dispatchAction({type:"showTip",seriesIndex:l,dataIndex:x}):(e.dispatchAction({type:"hideTip"}),e.dispatchAction({type:"showTip",seriesIndex:0,dataIndex:-1}))},[i?.dataIndex]);const m=p.useCallback(()=>{c?.(null)},[c]);if(p.useEffect(()=>{if(o.current){const e=o.current.getEchartsInstance(),l=e.getDom();return l.addEventListener("mouseleave",m),()=>{l.removeEventListener("mouseleave",m),e.dispose()}}},[m]),D(s))return w||null;const E=Math.max(...s.map(e=>e.value),h||0,0),M={tooltip:{trigger:"axis",formatter(e){const l=e[0].data,x=b(l),{seriesIndex:g,dataIndex:I}=e[0];return c?.({seriesIndex:g,dataIndex:I,dataValue:y[I],ref:i?.ref||o}),`${e[0].name}: <b>${x}</b>`},backgroundColor:n.palette.background.paper,borderColor:n.palette.divider,textStyle:{color:n.palette.text.primary},extraCssText:`box-shadow: ${n.shadows[2]}; border-radius: 4px;`},grid:{top:"48px",left:"16px",right:"16px",bottom:"0px",containLabel:!0},xAxis:{type:"category",boundaryGap:!1,data:y,axisTick:{show:!1},splitLine:{show:!1},axisLabel:{interval:A(s.map(e=>new Date(e.date)))}},yAxis:{type:"value",axisTick:{show:!1},splitLine:{show:!1},min:0,max:E,interval:Math.ceil(E/2),axisLabel:{formatter:b,padding:[5,0,0,0]}},visualMap:{show:!1,type:"piecewise",dimension:1,seriesIndex:0,pieces:u},series:[{name:`${a} Usage`,type:"line",smooth:!0,symbol:"none",lineStyle:{color:n.palette.primary.main,width:2.5},areaStyle:{},itemStyle:{},emphasis:{disabled:!0},data:s.map(e=>e.value),markLine:v}]};return f.jsxs(T,{sx:{p:1,position:"relative"},children:[f.jsx(j,{sx:{fontSize:"16px",fontWeight:"bold",color:"text.secondary",position:"absolute",top:8,left:16,zIndex:10},children:a}),f.jsx(C,{ref:o,option:M,style:{width:"100%",height:"200px"},onEvents:{globalout:m}}),d&&f.jsx(k,{sx:{color:"text.secondary",ml:2,mt:1,fontSize:12},children:d})]})}S.propTypes={title:t.string,total:t.number,history:t.array,valueFn:t.func,xAxisFormat:t.func,visualMapPieces:t.array,markLineData:t.object,extraInfo:t.node,empty:t.node,onHover:t.func,hoverIndex:t.object};export{S as B};
