import{u as b,a6 as y,a7 as E,a8 as D,w as C,l as f,a5 as L,a9 as h,O as d,aa as P,ab as p,ac as $}from"./index-BebFsTBB.js";function U(s){const w=b(),m=f(()=>p(s.filters)||w.state),o=f(()=>p(s.enabled)??!0),u=f(()=>$(m.value)),l=d(!0),a=d([]),i=d(null);async function c(){if(o.value){l.value=!0,i.value=null;try{const e=await fetch(`${L()}/api/events?${u.value}`);if(!e.ok)throw new Error(`HTTP error! status: ${e.status}`);const n=(await e.json()).events??[];a.value=n.filter(t=>t.remote_addr).map(h).sort((t,v)=>t.time.getTime()-v.time.getTime()),s.onLoaded?.()}catch(e){i.value=e instanceof Error?e:new Error(String(e)),a.value=[]}finally{l.value=!1}}}const{connect:S,disconnect:T,connectionStatus:g}=y(e=>{if(!o.value)return;const r=P(e,m.value);if(r.length===0)return;const n=r.filter(t=>t.remote_addr).map(h).sort((t,v)=>t.time.getTime()-v.time.getTime());a.value.push(...n),s.onLoaded?.()});return E(()=>{o.value&&c()}),D(()=>{a.value=[]}),C(()=>[u.value,o.value],([e,r],[n,t])=>{r&&(e!==n||!t)&&c()}),{loading:l,chartData:a,error:i,fetchData:c,queryString:u,connectionStatus:g,connect:S,disconnect:T}}export{U as u};