import{i as e}from"./rolldown-runtime-B1FJdls4.js";import{m as t}from"./vendor-dnd-C1cICjTT.js";import{qt as n}from"./vendor-misc-z3YbaCT0.js";import{t as r}from"./queryKeys-1VqzQyJo.js";import{R as i}from"./index-BvvB7abB.js";var a=e(t(),1),o=5e3,s=6e4;function c(e){if(!Number.isFinite(e)||e<=0)return`0 B`;let t=[`B`,`KB`,`MB`,`GB`,`TB`],n=e,r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r++;return`${n>=10||r===0?n.toFixed(0):n.toFixed(1)} ${t[r]}`}function l(e){return`${c(e)}/s`}function u(e=15e3,t=!1){let{data:c,error:l,isFetching:u,isLoading:d,refetch:f}=n({queryKey:r.machineHealth(),enabled:!t,queryFn:async({signal:e})=>({...await i(`/api/machine-health`,{signal:e,cache:`no-store`}),clientReceivedAt:Date.now()}),refetchInterval:()=>t?!1:document.visibilityState===`hidden`?Math.max(e,s):Math.max(e,o),refetchIntervalInBackground:!0,refetchOnWindowFocus:`always`,staleTime:o});(0,a.useEffect)(()=>{if(t)return;let e=()=>{document.visibilityState===`visible`&&f({cancelRefetch:!0})};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[t,f]);let p=(0,a.useCallback)(()=>{f({cancelRefetch:!0})},[f]);return{data:c??null,loading:d||u,error:l instanceof Error?l.message:l?String(l):null,refresh:p}}export{l as n,u as r,c as t};