"use client";import{useRouter as f}from"next/navigation";import{useCallback as h}from"react";import{isClient as S,useOverlayStore as y}from"@donotdev/core";function d(){let e=f(),r=y(t=>t.closeAll);return h((t,s)=>{if(t==="back")return r(),e.back();if(r(),s?.preserveScroll&&S()){let o=window.scrollY;s?.replace?e.replace(t):e.push(t),requestAnimationFrame(()=>{window.scrollTo({top:o,behavior:"auto"})});return}return s?.replace?e.replace(t):e.push(t)},[e,r])}function k(){let e=f();return h(()=>e.back(),[e])}function T(){let e=f();return h(()=>e.refresh(),[e])}function v(){let e=f();return h(r=>e.prefetch(r),[e])}import{usePathname as b,useSearchParams as N}from"next/navigation";function m(){let e=b(),t=N().toString(),s=t?`?${t}`:void 0;return{pathname:e||"/",search:s,hash:"",state:null}}import{useParams as w}from"next/navigation";function g(){let e=w();return e||{}}function C(e){let t=g()[e];if(typeof t=="string")return t;if(Array.isArray(t)&&t.length>0)return t[0]}import{useSearchParams as I}from"next/navigation";function R(){return I()}import{usePathname as G}from"next/navigation";function $(e){let r=G(),t=e.replace(/:[^/]+/g,"([^/]+)").replace(/\*/g,".*"),s=new RegExp(`^${t}$`),o=r.match(s);if(!o)return null;let n=e.match(/:[^/]+/g)?.map(u=>u.slice(1))||[],a={};return n.forEach((u,c)=>{a[u]=o[c+1]||""}),{params:a,pathname:r,pattern:e}}import{useCallback as P}from"react";function K(){let e=R(),r=d(),t=m(),s=P((a,u)=>{let c=new URLSearchParams(e.toString());c.set(a,u);let l=c.toString(),x=`${t.pathname||"/"}${l?`?${l}`:""}`;r(x)},[e,r,t.pathname]),o=P(a=>{let u=new URLSearchParams(e.toString());u.delete(a);let c=u.toString(),i=`${t.pathname||"/"}${c?`?${c}`:""}`;r(i)},[e,r,t.pathname]),n=P(()=>{let a=t.pathname||"/";r(a)},[r,t.pathname]);return{query:e,setQuery:s,removeQuery:o,clearQueries:n}}import{useMemo as E}from"react";import{isClient as Q,FEATURE_STATUS as F}from"@donotdev/core";import{useAuthConfig as M}from"@donotdev/core";import*as O from"@donotdev/auth";import{DEGRADED_AUTH_API as U}from"@donotdev/core";var A=O?.useAuth;function L(e){return U[e]}function p(e){return A?A(e):L(e)}function j(e={}){let{auth:r,redirectTo:t,condition:s}=e,o=m(),n=M(),a=p("user"),u=p("can"),c=p("status");return E(()=>{if(!Q())return{shouldRedirect:!1,redirectTo:null,isChecking:!1};if(c===F.INITIALIZING)return{shouldRedirect:!1,redirectTo:null,isChecking:!0};if(s){let i=s(a,c);return{shouldRedirect:i,redirectTo:i&&t||null,isChecking:!1}}if(r!==!1&&r!==void 0){if(!u)return{shouldRedirect:!1,redirectTo:null,isChecking:!1};if(!u.navigate(r)){let i=null;return typeof r=="object"&&r.required&&!a?o.search?.includes("code=")||o.search?.includes("state=")||o.search?.includes("error=")?i=`${n.authRoute}${o.search}`:i=n.authRoute:typeof r=="object"&&r.role?i=n.roleRoute:typeof r=="object"&&r.tier?i=n.tierRoute:i=n.roleRoute,{shouldRedirect:!0,redirectTo:t||i,isChecking:!1}}}return{shouldRedirect:!1,redirectTo:null,isChecking:!1}},[r,c,a,u,s,t,o.search,n.authRoute,n.roleRoute,n.tierRoute])}export{k as useBack,m as useLocation,$ as useMatch,d as useNavigate,g as useParams,v as usePrefetch,K as useQueryParams,j as useRedirectGuard,T as useRefresh,C as useRouteParam,R as useSearchParams};
