import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{$r as t,_i as n,ei as r,ii as i}from"./vendor-DkM0BOLc.js";import{n as a}from"./api--bJYSUUx.js";var o=e(n(),1),s=r();function c(e,t){try{let n=(t.startsWith(`/`)?t:`/${t}`).split(`?`)[0].split(`#`)[0].split(`/`).filter(Boolean);if(n.length<2)return;let[r,i,...o]=n;if(i===`matches`&&o[0]){let t=o[0];e.prefetchQuery({queryKey:[`match`,r,t],queryFn:()=>a(`/games/${r}/matches/${t}`),staleTime:300*1e3});return}if(i===`teams`&&o[0]){let t=o[0];e.prefetchQuery({queryKey:[`team`,r,t],queryFn:()=>a(`/games/${r}/teams/${t}`),staleTime:300*1e3});return}if(i===`players`&&o[0]&&o[0]!==`rankings`){let t=o[0];e.prefetchQuery({queryKey:[`player`,r,t,20],queryFn:()=>a(`/games/${r}/players/${t}?limit=20`),staleTime:300*1e3});return}if(i===`tournaments`&&o[0]){let t=o[0];e.prefetchQuery({queryKey:[`tournament`,r,t],queryFn:()=>a(`/games/${r}/tournaments/${t}`),staleTime:300*1e3});return}}catch{}}function l({to:e,prefetch:n=`hover`,onMouseEnter:r,onFocus:a,...l}){let u=t(),d=(0,o.useRef)(null),f=(0,o.useRef)(!1),p=(0,o.useCallback)(()=>{f.current||(f.current=!0,typeof e==`string`&&c(u,e))},[u,e]),m=(0,o.useCallback)(e=>{n===`hover`&&p(),r?.(e)},[n,p,r]),h=(0,o.useCallback)(e=>{n===`hover`&&p(),a?.(e)},[n,p,a]);return(0,o.useEffect)(()=>{if(n!==`visible`)return;let e=d.current;if(!e||typeof IntersectionObserver>`u`)return;let t=new IntersectionObserver(e=>{for(let n of e)if(n.isIntersecting){p(),t.disconnect();break}},{rootMargin:`200px`});return t.observe(e),()=>t.disconnect()},[n,p]),(0,s.jsx)(i,{ref:d,to:e,onMouseEnter:m,onFocus:h,...l})}export{l as t};