(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[177],{63:(e,t,r)=>{"use strict";var o=r(7260);r.o(o,"useRouter")&&r.d(t,{useRouter:function(){return o.useRouter}})},1290:()=>{},2327:(e,t,r)=>{"use strict";r.d(t,{u:()=>s});let o="http://localhost:8000/api";class a{getToken(){return localStorage.getItem("auth_token")}async request(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=this.getToken(),a={"Content-Type":"application/json",...t.headers};r&&(a.Authorization="Bearer ".concat(r));try{let r=await fetch("".concat(o).concat(e),{...t,headers:a}),s=await r.json();if(!r.ok)throw 401===r.status&&(localStorage.removeItem("auth_token"),window.location.href="/login"),Error(s.message||"API request failed");return s}catch(e){throw console.error("API Error:",e),e}}async get(e){return this.request(e,{method:"GET"})}async post(e,t){return this.request(e,{method:"POST",body:t?JSON.stringify(t):void 0})}async put(e,t){return this.request(e,{method:"PUT",body:t?JSON.stringify(t):void 0})}async delete(e){return this.request(e,{method:"DELETE"})}async upload(e,t){let r=this.getToken(),a={};r&&(a.Authorization="Bearer ".concat(r));try{let r=await fetch("".concat(o).concat(e),{method:"POST",headers:a,body:t}),s=await r.json();if(!r.ok)throw 401===r.status&&(localStorage.removeItem("auth_token"),window.location.href="/login"),Error(s.message||"Upload failed");return s}catch(e){throw console.error("Upload Error:",e),e}}}let s=new a},4845:(e,t,r)=>{"use strict";r.d(t,{AuthProvider:()=>u,c:()=>l});var o=r(5155),a=r(2115),s=r(63),n=r(2327);let l=(0,a.createContext)(void 0);function u(e){let{children:t}=e,[r,u]=(0,a.useState)(null),[c,i]=(0,a.useState)(null),[h,d]=(0,a.useState)(!0),g=(0,s.useRouter)();(0,a.useEffect)(()=>{let e=localStorage.getItem("auth_token");e?(i(e),m(e)):d(!1)},[]);let m=async e=>{try{let e=await n.u.get("/auth/user");e.success&&e.data&&u(e.data)}catch(e){console.error("Failed to fetch user:",e),localStorage.removeItem("auth_token"),i(null)}finally{d(!1)}},f=async e=>{try{let t=await n.u.post("/auth/login",e);if(t.success&&t.data){let{token:e,user:r}=t.data;localStorage.setItem("auth_token",e),i(e),u(r),g.push("/dashboard")}else throw Error(t.message||"Login failed")}catch(e){throw console.error("Login error:",e),e}},y=async e=>{try{let t=await n.u.post("/auth/register",e);if(t.success&&t.data){let{token:e,user:r}=t.data;localStorage.setItem("auth_token",e),i(e),u(r),g.push("/dashboard")}else throw Error(t.message||"Registration failed")}catch(e){throw console.error("Registration error:",e),e}};return(0,o.jsx)(l.Provider,{value:{user:r,token:c,isAuthenticated:!!c,isLoading:h,login:f,register:y,logout:()=>{localStorage.removeItem("auth_token"),i(null),u(null),g.push("/login")}},children:t})}},7074:e=>{e.exports={style:{fontFamily:"'Inter', 'Inter Fallback'",fontStyle:"normal"},className:"__className_f367f3"}},9828:(e,t,r)=>{Promise.resolve().then(r.bind(r,4845)),Promise.resolve().then(r.t.bind(r,7074,23)),Promise.resolve().then(r.t.bind(r,1290,23))}},e=>{e.O(0,[904,441,255,358],()=>e(e.s=9828)),_N_E=e.O()}]);