import{$u as e,Qu as t,nd as n}from"./messages-BOl-zx8S.js";import{a as r,i,t as a}from"./useRouter-DS97kuA5.js";import{l as o,s as ee,t as te,u as s}from"./useStore-pgHsvR0E.js";import{a as ne,c,n as re}from"./ClientOnly-COESZSX_.js";import{r as l}from"./dist-DJhZSa1-.js";var ie=`Error preloading route! ☝️`,u=n(e(),1);t();var ae=n(l(),1);function d(e,t){let n=a(),l=i(t),{activeProps:d,inactiveProps:g,activeOptions:_,to:v,preload:pe,preloadDelay:me,preloadIntentProximity:he,hashScrollIntoView:ge,replace:y,startTransition:_e,resetScroll:b,viewTransition:ve,children:x,target:S,disabled:C,style:w,className:T,onClick:E,onBlur:D,onFocus:O,onMouseEnter:k,onMouseLeave:A,onTouchStart:j,ignoreBlocker:M,params:ye,search:be,hash:xe,state:Se,mask:Ce,reloadDocument:we,unsafeRelative:Te,from:Ee,_fromLocation:De,...N}=e,P=re(),F=u.useMemo(()=>e,[n,e.from,e._fromLocation,e.hash,e.to,e.search,e.params,e.state,e.mask,e.unsafeRelative]),I=te(n.stores.location,e=>e,(e,t)=>e.href===t.href),L=u.useMemo(()=>{let e={_fromLocation:I,...F};return n.buildLocation(e)},[n,I,F]),R=L.maskedLocation?L.maskedLocation.publicHref:L.publicHref,z=L.maskedLocation?L.maskedLocation.external:L.external,B=u.useMemo(()=>ue(R,z,n.history,C),[C,z,R,n.history]),V=u.useMemo(()=>{if(B?.external)return s(B.href,n.protocolAllowlist)?void 0:B.href;if(!de(v)&&!(typeof v!=`string`||v.indexOf(`:`)===-1))try{return new URL(v),s(v,n.protocolAllowlist)?void 0:v}catch{}},[v,B,n.protocolAllowlist]),H=u.useMemo(()=>{if(V)return!1;if(_?.exact){if(!ne(I.pathname,L.pathname,n.basepath))return!1}else{let e=c(I.pathname,n.basepath),t=c(L.pathname,n.basepath);if(!(e.startsWith(t)&&(e.length===t.length||e[t.length]===`/`)))return!1}return(_?.includeSearch??!0)&&!ee(I.search,L.search,{partial:!_?.exact,ignoreUndefined:!_?.explicitUndefined})?!1:_?.includeHash?P&&I.hash===L.hash:!0},[_?.exact,_?.explicitUndefined,_?.includeHash,_?.includeSearch,I,V,P,L.hash,L.pathname,L.search,n.basepath]),U=H?o(d,{})??oe:f,W=H?f:o(g,{})??f,G=[T,U.className,W.className].filter(Boolean).join(` `),K=(w||U.style||W.style)&&{...w,...U.style,...W.style},[Oe,q]=u.useState(!1),J=u.useRef(!1),Y=e.reloadDocument||V?!1:pe??n.options.defaultPreload,X=me??n.options.defaultPreloadDelay??0,Z=u.useCallback(()=>{n.preloadRoute({...F,_builtLocation:L}).catch(e=>{console.warn(e),console.warn(ie)})},[n,F,L]);r(l,u.useCallback(e=>{e?.isIntersecting&&Z()},[Z]),m,{disabled:!!C||Y!==`viewport`}),u.useEffect(()=>{J.current||!C&&Y===`render`&&(Z(),J.current=!0)},[C,Z,Y]);let ke=e=>{let t=e.currentTarget.getAttribute(`target`),r=S===void 0?t:S;if(!C&&!fe(e)&&!e.defaultPrevented&&(!r||r===`_self`)&&e.button===0){e.preventDefault(),(0,ae.flushSync)(()=>{q(!0)});let t=n.subscribe(`onResolved`,()=>{t(),q(!1)});n.navigate({...F,replace:y,resetScroll:b,hashScrollIntoView:ge,startTransition:_e,viewTransition:ve,ignoreBlocker:M})}};if(V)return{...N,ref:l,href:V,...x&&{children:x},...S&&{target:S},...C&&{disabled:C},...w&&{style:w},...T&&{className:T},...E&&{onClick:E},...D&&{onBlur:D},...O&&{onFocus:O},...k&&{onMouseEnter:k},...A&&{onMouseLeave:A},...j&&{onTouchStart:j}};let Q=e=>{if(C||Y!==`intent`)return;if(!X){Z();return}let t=e.currentTarget;if(p.has(t))return;let n=setTimeout(()=>{p.delete(t),Z()},X);p.set(t,n)},Ae=e=>{C||Y!==`intent`||Z()},$=e=>{if(C||!Y||!X)return;let t=e.currentTarget,n=p.get(t);n&&(clearTimeout(n),p.delete(t))};return{...N,...U,...W,href:B?.href,ref:l,onClick:h([E,ke]),onBlur:h([D,$]),onFocus:h([O,Q]),onMouseEnter:h([k,Q]),onMouseLeave:h([A,$]),onTouchStart:h([j,Ae]),disabled:!!C,target:S,...K&&{style:K},...G&&{className:G},...C&&se,...H&&ce,...P&&Oe&&le}}var f={},oe={className:`active`},se={role:`link`,"aria-disabled":!0},ce={"data-status":`active`,"aria-current":`page`},le={"data-transitioning":`transitioning`},p=new WeakMap,m={rootMargin:`100px`},h=e=>t=>{for(let n of e)if(n){if(t.defaultPrevented)return;n(t)}};function ue(e,t,n,r){if(!r)return t?{href:e,external:!0}:{href:n.createHref(e)||`/`,external:!1}}function de(e){if(typeof e!=`string`)return!1;let t=e.charCodeAt(0);return t===47?e.charCodeAt(1)!==47:t===46}var g=u.forwardRef((e,t)=>{let{_asChild:n,...r}=e,{type:i,...a}=d(r,t),o=typeof r.children==`function`?r.children({isActive:a[`data-status`]===`active`}):r.children;if(!n){let{disabled:e,...t}=a;return u.createElement(`a`,t,o)}return u.createElement(n,a,o)});function fe(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}export{g as t};