import{s as c,j as a,B as b,z as f,T as y,N as h,a as m,a$ as S,r as u,C,hG as j,hH as I,hI as L,hJ as v,hK as w,hL as k,hM as z,hN as R,hO as A}from"./index-DxWYYOj0.js";import{L as B}from"./index-COns9WGJ.js";const P=c("ul")(({theme:e})=>({listStyle:"none",margin:0,padding:0})),T=c("li")(({theme:e})=>({marginBottom:e.spacing(.5),display:"flex",alignItems:"center"})),E=c("span")(({theme:e})=>({display:"inline-block",width:8,height:8,borderRadius:"50%",marginRight:e.spacing(1)})),g=16,D=e=>e==="left"?"flex-start":e==="right"?"flex-end":"center",M=(e=0,t)=>t==="left"?e+g:t==="right"?e-g:e,p=({tooltip:e,children:t})=>a.jsx(b,{sx:n=>({top:((e==null?void 0:e.caretY)||0)+g,left:M(e==null?void 0:e.caretX,e==null?void 0:e.align),width:"1px",position:"absolute",display:e?"flex":"none",pointerEvents:"none",zIndex:n.zIndex.tooltip,flexDirection:"column",alignItems:D(e==null?void 0:e.align)}),children:t}),O=({tooltip:e})=>a.jsx(p,{tooltip:e,children:a.jsxs(f,{elevation:3,sx:t=>({width:220,padding:t.spacing(1.5,2)}),children:[a.jsx(y,{variant:"body2",sx:t=>({marginBottom:t.spacing(1),color:t.palette.text.secondary}),children:e==null?void 0:e.title}),a.jsx(P,{children:e==null?void 0:e.body.map(t=>a.jsxs(T,{children:[a.jsx(E,{sx:{backgroundColor:t.color},children:" "}),a.jsx(y,{variant:"body2",sx:{display:"inline-block"},children:t.title})]},h(t)))})]})}),Y=e=>t=>{var s,r;const n=t.tooltip;if(n.opacity===0){e(null);return}e({caretX:n==null?void 0:n.caretX,caretY:n==null?void 0:n.caretY,title:((s=n==null?void 0:n.title)==null?void 0:s.join(" "))||"",align:n==null?void 0:n.xAlign,body:((r=n==null?void 0:n.body)==null?void 0:r.map((i,o)=>{var l,d,x;return{title:(l=i==null?void 0:i.lines)==null?void 0:l.join(" "),color:(x=(d=n==null?void 0:n.labelColors)==null?void 0:d[o])==null?void 0:x.borderColor,value:""}}))||[],dataPoints:(n==null?void 0:n.dataPoints)||[]})},_={position:"bottom",labels:{boxWidth:12,padding:30,generateLabels:e=>{var o;const t=e.data.datasets,{labels:{usePointStyle:n,pointStyle:s,textAlign:r,color:i}}=((o=e==null?void 0:e.legend)==null?void 0:o.options)||{labels:{}};return e._getSortedDatasetMetas().map(l=>{const d=l.controller.getStyle(n?0:void 0);return{text:t[l.index].label,fillStyle:d.borderColor,fontColor:i,hidden:!l.visible,lineWidth:0,borderRadius:6,strokeStyle:d.borderColor,pointStyle:s||d.pointStyle,textAlign:r||d.textAlign,datasetIndex:l.index}})}}},G=(e,t,n,s)=>({responsive:!0,...s?{animation:{duration:0}}:{},plugins:{legend:{..._,display:!s},tooltip:{enabled:!1,position:"nearest",interaction:{axis:"xy",mode:"nearest"},external:Y(n)}},locale:t.locale,interaction:{intersect:!1,axis:"xy",mode:"nearest"},elements:{point:{radius:0,hitRadius:15}},tension:.1,color:e.palette.text.secondary,scales:{y:{beginAtZero:!0,type:"linear",grid:{color:e.palette.divider,borderColor:e.palette.divider},ticks:{color:e.palette.text.secondary,display:!s,precision:0}},x:{type:"time",time:{unit:"week",tooltipFormat:"PPP"},grid:{color:"transparent",borderColor:"transparent"},ticks:{color:e.palette.text.secondary,display:!s,source:"data",maxRotation:90,minRotation:23.5}}}}),H=c("div")(({theme:e})=>({position:"relative"})),N=c("div")(({theme:e})=>({position:"absolute",inset:0,display:"flex",zIndex:e.zIndex.appBar,"&::before":{zIndex:e.zIndex.fab,content:'""',position:"absolute",inset:0,backgroundColor:e.palette.background.paper,opacity:.8}})),W=c("div")(({theme:e})=>({zIndex:e.zIndex.modal,margin:"auto",color:e.palette.text.secondary,textAlign:"center"})),X={id:"customLine",afterDraw:e=>{var n;if((n=e.tooltip)!=null&&n.opacity&&e.tooltip.x){const s=e.tooltip.caretX,r=e.scales.y,i=e.ctx;i.save();const o=i.createLinearGradient(s,r.top,s,r.bottom);o.addColorStop(0,"rgba(129, 122, 254, 0)"),o.addColorStop(1,"rgba(129, 122, 254, 0.12)"),i.fillStyle=o,i.fillRect(s-26/2,r.top,26,r.bottom-r.top),i.restore()}}},K=({data:e,aspectRatio:t=2.5,cover:n,overrideOptions:s,TooltipComponent:r})=>{const i=m(),{locationSettings:o}=S(),[l,d]=u.useState(null),x=u.useMemo(()=>({...G(i,o,d,!!n),...s}),[i,o,s,n]);return a.jsxs(H,{children:[a.jsx(B,{options:x,data:e,plugins:[X],height:100,width:100*t},n?"cover":"chart"),a.jsx(C,{condition:!n,show:r?a.jsx(p,{tooltip:l,children:a.jsx(r,{tooltip:l})}):a.jsx(O,{tooltip:l}),elseShow:a.jsx(N,{children:a.jsx(W,{children:n!==!0?n:" "})})})]})};j.register(I,L,v,w,k,z,R,A);export{K as default};
