import{c as E,u as T,a as F,r,j as e,b as i}from"./index-CdLZCFax.js";import{B as u}from"./button-D6hPD216.js";import{I as n}from"./input-BkGx6ON6.js";import{L as o}from"./label-CzSAyO9T.js";import{T as I,a as P,b as y,c as N}from"./tabs-B6pywf85.js";import{m as v,B,U as M}from"./index-Dr4C0uWC.js";import{L as w}from"./lock-yUPCALAU.js";import{A as b}from"./arrow-right-7ipfs5MG.js";/**
 * @license lucide-react v0.462.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const A=E("Mail",[["rect",{width:"20",height:"16",x:"2",y:"4",rx:"2",key:"18n3k1"}],["path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7",key:"1ocrg3"}]]);function W(){const{login:h,register:C,isAuthenticated:x,loading:g}=T(),c=F(),[s,p]=r.useState(""),[m,L]=r.useState(""),[l,f]=r.useState(""),[t,d]=r.useState(!1);r.useEffect(()=>{!g&&x&&c("/courses")},[x,g,c]);const j=async a=>{if(!s||!l||!a&&!m){i.error("Please fill in all fields");return}d(!0);try{a?(await h(s,l),i.success("Logged in successfully")):(await C(m,s,l),i.success("Account created successfully")),setTimeout(()=>{c("/courses")},100)}catch(S){i.error(S.message||"Authentication failed")}finally{d(!1)}},k=async()=>{d(!0);try{await h(s,l),c("/admin")}catch(a){i.error(a.message||"Admin login failed")}finally{d(!1)}};return e.jsxs("div",{className:"min-h-screen flex items-center justify-center bg-background animated-mesh p-4",children:[e.jsx("div",{className:"gradient-orb gradient-orb-1"}),e.jsx("div",{className:"gradient-orb gradient-orb-2"}),e.jsxs(v.div,{initial:{opacity:0,y:20,scale:.95},animate:{opacity:1,y:0,scale:1},transition:{duration:.6,ease:"easeInOut"},className:"w-full max-w-md relative z-10",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx(v.div,{initial:{scale:.8,opacity:0},animate:{scale:1,opacity:1},transition:{delay:.2,type:"spring",stiffness:200},className:"w-16 h-16 rounded-2xl gradient-primary flex items-center justify-center mx-auto mb-4 shadow-glow",children:e.jsx(B,{className:"w-8 h-8 text-primary-foreground"})}),e.jsx("h1",{className:"font-heading text-3xl font-bold mb-2",children:"Welcome to E-Maths"}),e.jsx("p",{className:"text-muted-foreground",children:"Your gateway to mathematical mastery"})]}),e.jsx("div",{className:"glass-card rounded-2xl p-6",children:e.jsxs(I,{defaultValue:"login",children:[e.jsxs(P,{className:"grid w-full grid-cols-2 mb-6",children:[e.jsx(y,{value:"login",children:"Sign In"}),e.jsx(y,{value:"register",children:"Register"})]}),e.jsxs(N,{value:"login",className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"email",children:"Email"}),e.jsxs("div",{className:"relative",children:[e.jsx(A,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(n,{id:"email",type:"email",placeholder:"you@example.com",className:"pl-10",value:s,onChange:a=>p(a.target.value)})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"password",children:"Password"}),e.jsxs("div",{className:"relative",children:[e.jsx(w,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(n,{id:"password",type:"password",placeholder:"••••••••",className:"pl-10",value:l,onChange:a=>f(a.target.value)})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 pt-2",children:[e.jsxs(u,{onClick:()=>j(!0),disabled:t,className:"w-full gradient-primary text-primary-foreground border-0 rounded-xl shadow-glow",children:[t?"Signing in...":"Sign in",e.jsx(b,{className:"w-4 h-4 ml-2"})]}),e.jsx(u,{variant:"outline",onClick:k,disabled:t,className:"w-full rounded-xl glass",children:"Sign in as Admin"})]})]}),e.jsxs(N,{value:"register",className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"reg-name",children:"Full Name"}),e.jsxs("div",{className:"relative",children:[e.jsx(M,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(n,{id:"reg-name",placeholder:"John Doe",className:"pl-10",value:m,onChange:a=>L(a.target.value)})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"reg-email",children:"Email"}),e.jsxs("div",{className:"relative",children:[e.jsx(A,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(n,{id:"reg-email",type:"email",placeholder:"you@example.com",className:"pl-10",value:s,onChange:a=>p(a.target.value)})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"reg-password",children:"Password"}),e.jsxs("div",{className:"relative",children:[e.jsx(w,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(n,{id:"reg-password",type:"password",placeholder:"••••••••",className:"pl-10",value:l,onChange:a=>f(a.target.value)})]})]}),e.jsxs(u,{onClick:()=>j(!1),disabled:t,className:"w-full gradient-primary text-primary-foreground border-0 rounded-xl shadow-glow",children:[t?"Creating Account...":"Create Account",e.jsx(b,{className:"w-4 h-4 ml-2"})]})]})]})})]})]})}export{W as default};
