1import{r as h,u as P,a as V,j as e,B as o,I as g,d as j,L as B,z as l}from"./index-BvSdsJgV.js";import{u as b,F as y,a as v,b as w,c as N,d as S,e as C,t as E}from"./form-xwyJkt3W.js";import{B as M}from"./brand-logos-dpNPGVlr.js";import{K as J}from"./key-round-u3bA0W41.js";import"./label-C0V1X8lK.js";const W=l.object({email:l.string().email("Please enter a valid email")}),z=l.object({email:l.string().email("Please enter a valid email"),code:l.string().length(6,"Code must be 6 digits")});function U(){const[a,r]=h.useState(!1),[F,u]=h.useState(!1),[c,k]=h.useState(""),{toast:n}=P(),[,f]=V(),x=b({resolver:E(W),defaultValues:{email:""}}),d=b({resolver:E(z),defaultValues:{email:"",code:""}}),T=async s=>{r(!0);try{const t=await fetch("/api/auth/send-verification-code",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:s.email})});if(!t.ok){const i=await t.json();throw new Error(i.message||"Failed to send verification code")}n({title:"Verification code sent!",description:`Check your email at ${s.email} for a 6-digit code.`}),k(s.email),d.setValue("email",s.email),u(!0)}catch(t){console.error("Login error:",t);const i=t instanceof Error?t.message:"Failed to send verification code";n({title:"Error",description:i,variant:"destructive"})}finally{r(!1)}},L=async s=>{r(!0);try{const t=await fetch("/api/auth/verify-code",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:s.email,code:s.code})});if(!t.ok){const m=await t.json();throw new Error(m.message||"Invalid verification code")}const i=await t.json();i.isNewUser?(localStorage.setItem("userEmail",s.email),f("/register")):(localStorage.setItem("authToken",i.token),localStorage.setItem("userData",JSON.stringify(i.user)),window.dispatchEvent(new Event("auth-update")),n({title:"Welcome back!",description:"You have successfully signed in."}),f("/projects"))}catch(t){console.error("Code verification error:",t);const i=t instanceof Error?t.message:"Invalid verification code";n({title:"Error",description:i,variant:"destructive"})}finally{r(!1)}},I=async()=>{if(c){r(!0);try{if(!(await fetch("/api/auth/send-verification-code",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({email:c})})).ok)throw new Error("Failed to resend code");n({title:"Code resent!",description:`A new code has been sent to ${c}`})}catch{n({title:"Error",description:"Failed to resend code. Please try again.",variant:"destructive"})}finally{r(!1)}}},O=async()=>{r(!0);try{const t=new URLSearchParams(window.location.search).get("returnTo"),i={};t&&t.startsWith("/")&&(i.returnTo=t);const m=await fetch("/api/auth/google-signin/url",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(i)});if(!m.ok)throw new Error("Failed to initiate Google sign-in");const p=await m.json();p.url&&(window.location.href=p.url)}catch(s){console.error("Google sign-in error:",s),n({title:"Error",description:"Failed to initiate Google sign-in",variant:"destructive"}),r(!1)}};return e.jsxs("div",{className:"min-h-screen flex",children:[e.jsx("div",{className:"hidden lg:flex lg:w-1/2 bg-gradient-to-br from-[#2f9ebc] to-[#10b981] items-center justify-center p-12",children:e.jsx("div",{className:"text-center max-w-md",children:e.jsx("h1",{className:"text-white text-left text-[56px] font-ubuntu font-normal leading-[1.1]",children:"Welcome back"})})}),e.jsx("div",{className:"w-full lg:w-1/2 flex items-center justify-center p-8 bg-white",children:e.jsxs("div",{className:"w-full max-w-md
1space-y-8",children:[e.jsx("div",{className:"flex justify-center mb-6",children:e.jsx(M,{className:"h-12 w-auto"})}),e.jsx("div",{className:"text-center lg:hidden",children:e.jsx("h2",{className:"text-3xl font-semibold text-gray-900 mb-2",children:"Welcome back"})}),e.jsx("div",{className:"w-full",children:F?e.jsx(y,{...d,children:e.jsxs("form",{onSubmit:d.handleSubmit(L),className:"space-y-4",children:[e.jsx("div",{className:"text-center mb-4",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:["We sent a 6-digit code to ",e.jsx("strong",{children:c})]})}),e.jsx(v,{control:d.control,name:"code",render:({field:s})=>e.jsxs(w,{children:[e.jsx(N,{children:"Verification Code"}),e.jsx(S,{children:e.jsx(g,{type:"text",placeholder:"Enter 6-digit code",maxLength:6,disabled:a,className:"text-center text-2xl tracking-widest",...s})}),e.jsx(C,{})]})}),e.jsx(o,{type:"submit",className:"w-full",disabled:a,children:a?e.jsxs(e.Fragment,{children:[e.jsx(j,{className:"mr-2 h-4 w-4 animate-spin"}),"Verifying..."]}):"Verify code"}),e.jsxs("div",{className:"flex justify-between items-center text-sm",children:[e.jsx(o,{type:"button",variant:"link",onClick:()=>u(!1),disabled:a,className:"p-0",children:"Use different email"}),e.jsx(o,{type:"button",variant:"link",onClick:I,disabled:a,className:"p-0",children:"Resend code"})]})]})}):e.jsx(y,{...x,children:e.jsxs("form",{onSubmit:x.handleSubmit(T),className:"space-y-4",children:[e.jsxs(o,{type:"button",variant:"outline",className:"w-full pt-[24px] pb-[24px] text-[16px] font-medium border-gray-300 hover:bg-gray-50 mt-[14px] mb-[14px]",onClick:O,disabled:a,"data-testid":"button-google-signin",children:[e.jsxs("svg",{className:"mr-2 h-5 w-5",viewBox:"0 0 24 24",children:[e.jsx("path",{fill:"#4285F4",d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"}),e.jsx("path",{fill:"#34A853",d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"}),e.jsx("path",{fill:"#FBBC05",d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"}),e.jsx("path",{fill:"#EA4335",d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"})]}),"Continue with Google"]}),e.jsxs("div",{className:"relative my-6",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-white px-2 text-muted-foreground",children:"Or continue with email"})})]}),e.jsx(v,{control:x.control,name:"email",render:({field:s})=>e.jsxs(w,{children:[e.jsx(N,{children:"Email"}),e.jsx(S,{children:e.jsx(g,{type:"email",placeholder:"Enter your email",disabled:a,className:"mt-[4px] mb-[4px] pt-[22px] pb-[22px]",...s})}),e.jsx(C,{})]})}),e.jsx(o,{type:"submit",className:"w-full pt-[24px] pb-[24px] mt-[8px] mb-[8px] text-[16px] font-medium",disabled:a,children:a?e.jsxs(e.Fragment,{children:[e.jsx(j,{className:"mr-2 h-4 w-4 animate-spin"}),"Sending code..."]}):e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"mr-2 h-4 w-4"}),"Send verification code"]})})]})})}),e.jsx("div",{className:"text-center",children:e.jsxs("p",{className:"text-sm text-gray-600",children:["Don't have an account?"," ",e.jsx(B,{href:"/register-account",className:"text-[#098bb9] hover:underline font-medium",children:"Create one"})]})})]})})]})}export{U as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.