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