"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[20313],{20313:(e,n,t)=>{t.d(n,{SessionProvider:()=>k,CI:()=>C,wV:()=>U});var s,a,o,i,r,l=t(5717),c=t(77169),u=t.t(c,2),d=t(52353);class v extends d.lR{}class f extends d.lR{}async function h(e,n,t){let s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{},a="".concat(w(n),"/").concat(e);try{var o;let e={headers:{"Content-Type":"application/json",...(null==s||null==(o=s.headers)?void 0:o.cookie)?{cookie:s.headers.cookie}:{}}};(null==s?void 0:s.body)&&(e.body=JSON.stringify(s.body),e.method="POST");let n=await fetch(a,e),t=await n.json();if(!n.ok)throw t;return t}catch(e){return t.error(new v(e.message,e)),null}}function w(e){return"undefined"==typeof window?"".concat(e.baseUrlServer).concat(e.basePathServer):e.basePath}function g(){return Math.floor(Date.now()/1e3)}function _(e){let n=new URL("http://localhost:3000/api/auth");e&&!e.startsWith("http")&&(e="https://".concat(e));let t=new URL(e||n),s=("/"===t.pathname?n.pathname:t.pathname).replace(/\/$/,""),a="".concat(t.origin).concat(s);return{origin:t.origin,host:t.host,path:s,base:a,toString:()=>a}}var p=t(37811);let E={baseUrl:_(null!=(a=p.env.NEXTAUTH_URL)?a:p.env.VERCEL_URL).origin,basePath:_(p.env.NEXTAUTH_URL).path,baseUrlServer:_(null!=(i=null!=(o=p.env.NEXTAUTH_URL_INTERNAL)?o:p.env.NEXTAUTH_URL)?i:p.env.VERCEL_URL).origin,basePathServer:_(null!=(r=p.env.NEXTAUTH_URL_INTERNAL)?r:p.env.NEXTAUTH_URL).path,_lastSync:0,_session:void 0,_getSession:()=>{}},S=null;function b(){return"undefined"==typeof BroadcastChannel?{postMessage:()=>{},addEventListener:()=>{},removeEventListener:()=>{},name:"next-auth",onmessage:null,onmessageerror:null,close:()=>{},dispatchEvent:()=>!1}:new BroadcastChannel("next-auth")}function y(){return null===S&&(S=b()),S}let L={debug:console.debug,error:console.error,warn:console.warn},m=null==(s=c.createContext)?void 0:s.call(u,void 0);function U(e){if(!m)throw Error("React Context is unavailable in Server Components");let n=c.useContext(m),{required:t,onUnauthenticated:s}=null!=e?e:{},a=t&&"unauthenticated"===n.status;return(c.useEffect(()=>{if(a){let e="".concat(E.basePath,"/signin?").concat(new URLSearchParams({error:"SessionRequired",callbackUrl:window.location.href}));s?s():window.location.href=e}},[a,s]),a)?{data:n.data,update:n.update,status:"loading"}:n}async function R(e){var n;let t=await h("session",E,L,e);return(null==(n=null==e?void 0:e.broadcast)||n)&&b().postMessage({event:"session",data:{trigger:"getSession"}}),t}async function T(){var e;let n=await h("csrf",E,L);return null!=(e=null==n?void 0:n.csrfToken)?e:""}async function C(e){var n,t;let{redirect:s=!0,redirectTo:a=null!=(n=null==e?void 0:e.callbackUrl)?n:window.location.href}=null!=e?e:{},o=w(E),i=await T(),r=await fetch("".concat(o,"/signout"),{method:"post",headers:{"Content-Type":"application/x-www-form-urlencoded","X-Auth-Return-Redirect":"1"},body:new URLSearchParams({csrfToken:i,callbackUrl:a})}),l=await r.json();if(y().postMessage({event:"session",data:{trigger:"signout"}}),s){let e=null!=(t=l.url)?t:a;window.location.href=e,e.includes("#")&&window.location.reload();return}return await E._getSession({event:"storage"}),l}function k(e){if(!m)throw Error("React Context is unavailable in Server Components");let{children:n,basePath:t,refetchInterval:s,refetchWhenOffline:a}=e;t&&(E.basePath=t);let o=void 0!==e.session;E._lastSync=o?g():0;let[i,r]=c.useState(()=>(o&&(E._session=e.session),e.session)),[u,d]=c.useState(!o);c.useEffect(()=>(E._getSession=async function(){let{event:e}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};try{let n="storage"===e;if(n||void 0===E._session){E._lastSync=g(),E._session=await R({broadcast:!n}),r(E._session);return}if(!e||null===E._session||g(){E._lastSync=0,E._session=void 0,E._getSession=()=>{}}),[]),c.useEffect(()=>{let e=()=>E._getSession({event:"storage"});return y().addEventListener("message",e),()=>y().removeEventListener("message",e)},[]),c.useEffect(()=>{let{refetchOnWindowFocus:n=!0}=e,t=()=>{n&&"visible"===document.visibilityState&&E._getSession({event:"visibilitychange"})};return document.addEventListener("visibilitychange",t,!1),()=>document.removeEventListener("visibilitychange",t,!1)},[e.refetchOnWindowFocus]);let v=function(){let[e,n]=c.useState("undefined"!=typeof navigator&&navigator.onLine),t=()=>n(!0),s=()=>n(!1);return c.useEffect(()=>(window.addEventListener("online",t),window.addEventListener("offline",s),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",s)}),[]),e}(),w=!1!==a||v;c.useEffect(()=>{if(s&&w){let e=setInterval(()=>{E._session&&E._getSession({event:"poll"})},1e3*s);return()=>clearInterval(e)}},[s,w]);let _=c.useMemo(()=>({data:i,status:u?"loading":i?"authenticated":"unauthenticated",async update(e){if(u)return;d(!0);let n=await h("session",E,L,void 0===e?void 0:{body:{csrfToken:await T(),data:e}});return d(!1),n&&(r(n),y().postMessage({event:"session",data:{trigger:"getSession"}})),n}}),[i,u]);return(0,l.jsx)(m.Provider,{value:_,children:n})}}}]);