1import{R as C,u as k,r as c,s as l,j as e,L as j,t as o}from"./index-hs4a0mYW.js";import{B as w}from"./button-Cc6vISkn.js";import{I as m}from"./input-XaHB6AeD.js";import{L as p}from"./label-COJky-GG.js";import{S as E}from"./SiteHeader-BqOOKgqK.js";import{S as L}from"./SiteFooter-CpQk1rby.js";import"./useServerFn-DgMZqDJQ.js";import"./newsletter.functions-BPJ19l6O.js";function U(){const{mode:a,redirect:n}=C.useSearch(),t=k();return c.useEffect(()=>{const{data:d}=l.auth.onAuthStateChange((i,u)=>{u&&t({to:n,replace:!0})});return l.auth.getUser().then(({data:i})=>{i.user&&t({to:n,replace:!0})}),()=>d.subscription.unsubscribe()},[t,n]),e.jsxs("div",{className:"min-h-screen flex flex-col bg-background text-foreground",children:[e.jsx(E,{}),e.jsx("main",{id:"main",className:"flex-1 grid place-items-center px-4 py-12",children:e.jsxs("div",{className:"w-full max-w-md",children:[e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("h1",{className:"font-serif text-primary",style:{fontSize:"2rem"},children:a==="signup"?"Create your account":"Welcome back"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:a==="signup"?"Sign up to access your library and future purchases.":"Sign in to see your orders and downloads."})]}),e.jsxs("div",{className:"rounded-xl border border-border bg-card p-6 shadow-sm",children:[e.jsx(F,{mode:a,redirect:n}),e.jsx("p",{className:"mt-6 text-center text-sm text-muted-foreground",children:a==="signup"?e.jsxs(e.Fragment,{children:["Already have an account?"," ",e.jsx(j,{to:"/auth",search:{mode:"signin",redirect:n},className:"font-medium text-primary underline-offset-4 hover:underline",children:"Sign in"})]}):e.jsxs(e.Fragment,{children:["New here?"," ",e.jsx(j,{to:"/auth",search:{mode:"signup",redirect:n},className:"font-medium text-primary underline-offset-4 hover:underline",children:"Create an account"})]})})]})]})}),e.jsx(L,{})]})}function F({mode:a,redirect:n}){const[t,d]=c.useState(""),[i,u]=c.useState(""),[h,N]=c.useState(""),[g,x]=c.useState(!1),[f,y]=c.useState(!1),b=async s=>{s.preventDefault(),x(!0);try{if(a==="signup"){const{error:r}=await l.auth.signUp({email:t,password:i,options:{data:{display_name:h||t.split("@")[0]},emailRedirectTo:`${window.location.origin}${n}`}});if(r)throw r;o.success("Account created. Signing you in.")}else{const{error:r}=await l.auth.signInWithPassword({email:t,password:i});if(r)throw r;o.success("Signed in.")}}catch(r){const S=r instanceof Error?r.message:"Something went wrong";o.error(S)}finally{x(!1)}},v=async()=>{if(!t){o.error("Enter your email first.");return}y(!0);try{const{error:s}=await l.auth.signInWithOtp({email:t,options:{emailRedirectTo:`${window.location.origin}${n}`,shouldCreateUser:!0}});if(s)throw s;o.success("Check your inbox. We just sent you a sign-in link.")}catch(s){const r=s instanceof Error?s.message:"Could not send magic link";o.error(r)}finally{y(!1)}};return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("form",{onSubmit:b,className:"space-y-4",noValidate:!0,children:[a==="signup"&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(p,{htmlFor:"display_name",children:"Display name"}),e.jsx(m,{id:"display_name",type:"text",autoComplete:"name",value:h,onChange:s=>N(s.target.value),placeholder:"Your name"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(p,{htmlFor:"email",children:"Email"}),e.jsx(m,{id:"email",type:"email",autoComplete:"email",required:!0,value:t,onChange:s=>d(s.target.value),placeholder:"[email protected]"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(p,{htmlFor:"password",children:"Password"}),e.jsx(m,{id:"password",type:"password",autoComplete:a==="signup"?"new-password":"current-password",required:!0,minLength:8,value:i,onChange:s=>u(s.target.value),placeholder:a==="signup"?"At least 8 characters":"Your password"})]}),e.jsx(w,{type:"submit",className:"w-full",disabled:g,children:g?"Working...":a==="signup"?"Create account":"Sign in"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs uppercase tracking-widest text-muted-foreground",children:[e.jsx("span",{className:"h-px flex-1 bg-border"}),"or",e.jsx("span",{className:"h-px flex-1 bg-border"})]}),e.jsx(w,{type:"button",variant:"outline",className:"w-full",disabled:f,onClick:v,children:f?"
1Sending...":"Email me a magic sign-in link"}),e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:"No password needed. Great for checking your orders after a purchase."})]})}export{U as component};
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.