(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5957],{13877:(e,t,n)=>{"use strict";n.r(t),n.d(t,{default:()=>l});var i=n(73365),a=n(66542),s=n(1521),r=n(73773);function o(e){let{user:t}=e,[n,a]=(0,s.useState)({email:"",name:"",password:"",privileges:[]}),{mutate:o,isLoading:l}=(0,r.n)({mutationFn:e=>fetch("/api/admin/register",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(e=>e.json())});return(0,i.jsxs)("div",{className:"bg-white p-6 rounded-lg shadow",children:[(0,i.jsx)("h2",{className:"text-xl font-semibold mb-4",children:"Create New Admin"}),(0,i.jsx)("form",{onSubmit:e=>{e.preventDefault(),o(n,{onSuccess:()=>{alert("Admin created successfully"),a({email:"",name:"",password:"",privileges:[]})}})},className:"space-y-4"})]})}function l(){let{data:e}=(0,a.iZ)();return(0,i.jsxs)("div",{className:"container mx-auto p-4",children:[(0,i.jsx)("h1",{className:"text-2xl font-bold mb-6",children:"Admin Dashboard"}),(0,i.jsx)(o,{user:e})]})}},17199:(e,t,n)=>{Promise.resolve().then(n.bind(n,13877))},28492:(e,t,n)=>{"use strict";n.d(t,{t:()=>i});let i=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=await fetch("".concat(e),{...t,headers:{"Content-Type":"application/json",...t.headers},credentials:"include"});if(401===n.status)throw window.location.href="/login",Error("Please login again");if(!n.ok)throw Error((await n.json()).message||"Authentication failed");return await n.json()}},42354:(e,t,n)=>{"use strict";n.d(t,{n:()=>s});var i=n(73401),a=n(64350);let s=(0,i.v)((0,a.Zr)(e=>({user:null,token:null,isAuthenticated:!1,login:(t,n)=>e({user:{id:t.id,email:t.email,name:t.name,role:t.role,profile:t.profile},token:n,isAuthenticated:!0}),logout:()=>e({user:null,token:null,isAuthenticated:!1}),setUser:t=>e({user:{...t},isAuthenticated:!!t})}),{name:"auth-storage",storage:(0,a.KU)(()=>localStorage),partialize:e=>({user:e.user,token:e.token,isAuthenticated:e.isAuthenticated})}))},66542:(e,t,n)=>{"use strict";n.d(t,{FB:()=>d,M7:()=>c,So:()=>u,Wn:()=>h,iZ:()=>m,vz:()=>l});var i=n(14111),a=n(73773),s=n(32412),r=n(42354),o=n(28492);let l=()=>{let e=(0,i.jE)(),t=r.n.getState().login;return(0,a.n)({mutationFn:e=>(0,o.t)("/api/auth/login",{method:"POST",body:JSON.stringify(e),credentials:"include",headers:{"Content-Type":"application/json"}}),onSuccess:n=>{let{user:i,token:a}=n;e.invalidateQueries(["user"]),t(i,a)}})},u=()=>(0,a.n)({mutationFn:e=>(0,o.t)("/api/auth/signup",{method:"POST",body:JSON.stringify(e)})}),d=()=>{let e=(0,i.jE)();return(0,a.n)({mutationFn:async e=>{let{email:t,code:n}=e;return(0,o.t)("/api/auth/verify-email",{method:"POST",body:JSON.stringify({email:t,verificationCode:n})})},onSuccess:()=>{e.invalidateQueries(["user"])}})},c=()=>{let e=(0,i.jE)();return(0,a.n)({mutationFn:async e=>{let{email:t}=e;return(0,o.t)("/api/auth/resend-verification",{method:"POST",body:JSON.stringify({email:t})})},onSuccess:()=>{e.invalidateQueries(["user"])}})},h=()=>{let e=(0,i.jE)(),t=r.n.getState().logout;return(0,a.n)({mutationFn:()=>(0,o.t)("/api/auth/logout",{method:"POST"}),onSuccess:()=>{t(),e.clear(),router.push("/login")}})},m=()=>{let{user:e,token:t,isAuthenticated:n}=(0,r.n)();return(0,s.I)({queryKey:["user"],queryFn:async()=>n?(0,o.t)("/api/profiles/me",{headers:{Authorization:"Bearer ".concat(t)}}):null,initialData:e,enabled:n&&!!t,staleTime:3e5})}}},e=>{var t=t=>e(e.s=t);e.O(0,[1303,2412,3192,2347,4870,7358],()=>t(17199)),_N_E=e.O()}]);