import{d as b,u as C,a7 as S,w as z,ae as B,e as D,f as _,k as L,j as E,B as F,O as y,ac as d,ao as x,a5 as O,a1 as P,o as v,L as R}from"./index-BebFsTBB.js";import{C as j,P as g,D as A,m as T,h as M,l as n,t as i,E as N,i as p,F as U}from"./chart-BJS5fRTR.js";const V={class:"flex h-full flex-col gap-4 pt-2"},$={class:"chart-container"},Q=b({__name:"ActivityChart",props:{chartData:{},loading:{type:Boolean},connectionStatus:{}},setup(q){const t=C(),s=F("chartContainer"),u=y(!1),f=y([]);async function h(){u.value=!0;try{const a=d(t.state),o=new URLSearchParams(a);!o.get("time_start")&&t.state.x_range?.[0]&&o.set("time_start",x(t.state.x_range[0])),!o.get("time_end")&&t.state.x_range?.[1]&&o.set("time_end",x(t.state.x_range[1])),o.set("limit",j.toString());const l=await fetch(`${O()}/api/stats/activity-over-time?${o.toString()}`);if(!l.ok)throw new Error("Failed to fetch activity");f.value=await l.json(),k()}catch(a){console.error(a)}finally{u.value=!1}}function k(){if(!s.value)return;if(f.value.length===0){g.purge(s.value);return}const a={};f.value.forEach(e=>{a[e.type]||(a[e.type]={x:[],y:[]});const r=a[e.type];r.x.push(new Date(e.time)),r.y.push(e.count)});const o=Object.entries(a).map(([e,r],c)=>({x:r.x,y:r.y,name:P(e)?.label||e,type:"scatter",mode:"lines",line:{shape:"linear",width:2,color:A(c,Object.keys(a).length)},hoverlabel:{bgcolor:"#141210",font:{color:"#ccc",size:12}}})),l={xaxis:{title:{text:"Time",font:{size:n,color:i}},type:"date",gridcolor:p,range:t.state.x_range&&t.state.x_range.length===2?[...t.state.x_range]:void 0,tickfont:{color:i,size:n},showspikes:!0,spikemode:"across",spikecolor:U,spikethickness:-2},yaxis:{title:{text:"Events per Minute",font:{size:n,color:i}},gridcolor:p,zerolinecolor:p,tickfont:{color:i,size:n}},margin:N,paper_bgcolor:"transparent",plot_bgcolor:"transparent",font:{color:i},showlegend:!0,legend:{orientation:"h",y:-.2,font:{size:n}},hovermode:"x unified",hoverlabel:M,modebar:T},w={responsive:!0,displaylogo:!1,modeBarButtonsToRemove:["lasso2d","select2d"]};g.react(s.value,o,l,w);const m=s.value;m.removeAllListeners?.("plotly_relayout"),m.on("plotly_relayout",e=>{if(e["xaxis.range[0]"]&&e["xaxis.range[1]"]){const r=e["xaxis.range[0]"].toString(),c=e["xaxis.range[1]"].toString();t.state.x_range=[r,c],t.state.sync_time_with_chart&&(t.state.time_start=r,t.state.time_end=c)}e["xaxis.autorange"]&&(t.state.x_range=[],t.state.sync_time_with_chart&&(t.state.time_start="",t.state.time_end=""))})}return S(()=>{h()}),z([()=>d(t.state),()=>t.state.x_range],()=>{h()},{deep:!0}),B(s,()=>{s.value&&g.Plots.resize(s.value)}),(a,o)=>(v(),D("div",V,[_("div",$,[u.value?(v(),L(R,{key:0})):E("",!0),_("div",{ref_key:"chartContainer",ref:s,class:"h-full w-full rounded-lg"},null,512)])]))}});export{Q as default};