import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{Ci as t,ai as n,oi as r,ui as i}from"./vendor-DlcENO3s.js";import{r as a}from"./api-LV_VgyGF.js";var o=e(t(),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:t=`hover`,onMouseEnter:r,onFocus:a,...l}){let u=n(),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=>{t===`hover`&&p(),r?.(e)},[t,p,r]),h=(0,o.useCallback)(e=>{t===`hover`&&p(),a?.(e)},[t,p,a]);return(0,o.useEffect)(()=>{if(t!==`visible`)return;let e=d.current;if(!e||typeof IntersectionObserver>`u`)return;let n=new IntersectionObserver(e=>{for(let t of e)if(t.isIntersecting){p(),n.disconnect();break}},{rootMargin:`200px`});return n.observe(e),()=>n.disconnect()},[t,p]),(0,s.jsx)(i,{ref:d,to:e,onMouseEnter:m,onFocus:h,...l})}export{l as t};