import{D as x,B as M,r as p,ak as w,j as d,M as m,s as R}from"./index-B-YXshIJ.js";import{b as D}from"./query-hooks-C0Pc4MKj.js";const O={large:{width:300,height:60,strokeDasharray:[7,5],lineWidth:1,hoverPointRadius:8,hoverPointStroke:4},medium:{width:161,height:33,strokeDasharray:[7,5],lineWidth:1,hoverPointRadius:6,hoverPointStroke:2},small:{width:50,height:32,strokeDasharray:[7,5],lineWidth:1,hoverPointRadius:8,hoverPointStroke:3}},v={good:{line:"rgba(var(--color-text-success), 1)",area:"rgba(var(--color-bg-success), 0.2)"},bad:{line:"rgba(var(--color-text-danger), 1)",area:"rgba(var(--color-bg-danger), 0.2)"},neutral:{line:"rgba(var(--color-text-icon), 1)",area:"rgba(var(--color-text-icon), 0.2)"}},S=({color:n,itemTooltipLabel:e,itemToValue:r,data:u,yCoord:o,xCoord:l,options:h,dateForIndex:s})=>e?u.map((i,t)=>{const a=r(i);return a?d.jsx("circle",{cx:l(t),cy:o(a),r:h.hoverPointRadius,fill:(n||v.neutral).line,strokeWidth:h.hoverPointStroke,stroke:"#fff",className:"opacity-0 hover:opacity-100 drop-shadow","data-tooltip-id":"react-tooltip","data-tooltip-html":[e(i),'<div className="mt-2">'.concat(R(s(t)),"</div>")].join(" ")},t):null}):null,$=({color:n,data:e,itemToValue:r,yCoord:u,xCoord:o})=>{const l=p.useMemo(()=>{const h=e.map(r).find(s=>s!==void 0)||0;return e.reduce((s,i,t)=>{var a;return t===0&&s.push([t,0]),s.push([t,(a=r(i))!=null?a:t===0?h:s[t][1]]),t===e.length-1&&s.push([t,0]),s},[]).map(s=>"".concat(o(s[0]),",").concat(u(s[1]))).join(" ")},[e,r,o,u]);return d.jsx("polygon",{points:l,fill:(n||v.neutral).area},"poly")},B=({color:n,itemToValue:e,data:r,yCoord:u,xCoord:o,options:l})=>{const h=p.useMemo(()=>r.map(e).map((i,t)=>"".concat(t===0?"M":"L"," ").concat(o(t)," ").concat(u(i))).join(" "),[r,e,o,u]);return d.jsx("path",{className:"transition-all duration-200",d:h,fill:"none",stroke:(n||v.neutral).line,strokeWidth:l.lineWidth})},L=n=>n==null,G=({color:n,data:e,itemToValue:r,yCoord:u,xCoord:o,options:l})=>{const[h,s]=p.useMemo(()=>{const t=f=>({p1:g,p2:k,index:P})=>d.jsx("line",{x1:g[0],y1:g[1],x2:k[0],y2:k[1],stroke:(n||v.neutral).line,strokeWidth:l.lineWidth,strokeDasharray:f?"":l.strokeDasharray.join(",")},P),a=t(!1),c=t(!0);return[a,c]},[n,l.lineWidth,l.strokeDasharray]),i=p.useMemo(()=>e.map((t,a)=>L(r(t))?void 0:[o(a),u(r(t))]).reduce((t,a)=>t.length===0&&a===void 0?[]:a===void 0?x(t)===void 0?t:[...t,void 0]:[...t,a],[]),[e,r,o,u]);if(i.length)return[...i.reduce((t,a,c)=>{if(c===0)return t;if(a===void 0){const g=i[c-1],k=i[c+1];return k?(t.push(d.jsx(h,{p1:g,p2:k,index:c},t.length)),t):(t.push(d.jsx(h,{p1:g,p2:[o(e.length-1),g[1]],index:c},t.length)),t)}const f=i[c-1];return f===void 0||t.push(d.jsx(s,{p1:f,p2:a,index:c},t.length)),t},[d.jsx(h,{p1:[o(0),i[0][1]],p2:i[0],index:-1},"first")])]},F=({data:n,itemToValue:e,graphConfig:r,itemTooltipLabel:u,...o})=>{const{Renderer:l,rendererProps:h}=p.useMemo(()=>{const s=n==null?void 0:n.map(e),i=Math.max(...(s||[]).filter(m)),t=s!=null&&s.includes(void 0)?G:B,a=Math.ceil(r.lineWidth/2),c=Math.ceil((r.hoverPointRadius+r.hoverPointStroke)/2),f=Math.max(a,c),g=Math.ceil((r.hoverPointRadius+r.hoverPointStroke)/2),k=Math.ceil((r.hoverPointRadius+r.hoverPointStroke)/2),P=(r.width-g-k)/((n||[]).length-1),b=j=>j*P+g,y=j=>r.height-j/i*(r.height-f),{width:H,height:N,...W}=r;return{rendererProps:{data:n||[],itemToValue:e,itemTooltipLabel:u,yCoord:y,xCoord:b,options:W,...o},Renderer:t}},[n,r,e,u,o]);return n?d.jsxs(d.Fragment,{children:[d.jsx($,{...h}),d.jsx(l,{...h}),d.jsx(S,{...h}),","]}):null},U=n=>{const e=x(n)||0,r=M(n)||0;return e-r>0?v.good:e-r===0?v.neutral:v.bad},Q=n=>{const e=x(n)||0,r=M(n)||0;return e-r<0?v.good:e-r===0?v.neutral:v.bad},Y=({className:n,...e})=>{const r=D()[3],u=p.useCallback(h=>{if(!e.data)return;const i=e.data.length-h-1;return new Date(r.getTime()-i*w)},[r,e.data]),[o,l]=p.useMemo(()=>[e.graphConfig.height,e.graphConfig.width],[e.graphConfig.height,e.graphConfig.width]);return d.jsx("svg",{height:o,width:l,viewBox:"0 0 ".concat(l," ").concat(o),className:n,children:d.jsx(F,{dateForIndex:u,...e})})};export{Y as T,v as a,Q as d,O as g,U as i};
