1import{R as P,d as A,r,s as n,o as F,j as e,L as g,D as v,I as y,B as R,t as f}from"./index-CzAkNt2W.js";import{L as j}from"./label-BwWVuV93.js";function q(){const{invite:a,next:u}=P.useSearch();A();const[s,o]=r.useState(a?"invite-signup":"signin"),[c,p]=r.useState(""),[m,b]=r.useState(""),[x,w]=r.useState(!1),[N,k]=r.useState(!1),h=r.useCallback(async()=>{if(u){window.location.replace(u);return}let i="/dashboard";try{const{data:t}=await n.auth.getUser();if(t.user){const{data:l}=await n.from("user_roles").select("role").eq("user_id",t.user.id),d=(l??[]).map(I=>I.role);i=F(d)}}catch{}window.location.replace(i)},[u]);r.useEffect(()=>{a&&p(a)},[a]),r.useEffect(()=>{n.auth.getSession().then(({data:i})=>{i.session&&h()})},[h]);async function S(i){i.preventDefault(),w(!0);try{if(s==="invite-signup"){if(!a||c.trim().toLowerCase()!==a.trim().toLowerCase())throw new Error("Use the email address on your owner invitation");const{data:t,error:l}=await n.auth.signUp({email:a.trim(),password:m,options:{emailRedirectTo:`${window.location.origin}/onboarding`}});if(l)throw l;if(t.session){window.location.replace("/onboarding");return}k(!0),o("signin")}else if(s==="signin"){const{error:t}=await n.auth.signInWithPassword({email:c,password:m});if(t)throw t;const{data:l,error:d}=await n.auth.getUser();if(d||!l.user)throw d??new Error("Could not verify your session");f.success("Welcome back!"),h()}else{const{error:t}=await n.auth.resetPasswordForEmail(c,{redirectTo:`${window.location.origin}/reset-password`});if(t)throw t;f.success("Check your email for a password reset link."),o("signin")}}catch(t){f.error(t instanceof Error?t.message:"Authentication failed")}finally{w(!1)}}const C=s==="forgot"?"Reset your password":s==="invite-signup"?"Accept your owner invitation":"Welcome back",E=s==="forgot"?"Enter your email and we'll send you a reset link.":s==="invite-signup"?"Create an account with the invited email, then verify it to join your workspace.":"Sign in to your SplashIQ workspace.",L=s==="forgot"?"Send reset link":s==="invite-signup"?"Create invited account":"Sign in";return e.jsxs("div",{className:"min-h-screen grid lg:grid-cols-2",children:[e.jsxs("div",{className:"hidden lg:block relative bg-water",children:[e.jsx("div",{className:"absolute inset-0 caustics opacity-70"}),e.jsxs("div",{className:"relative h-full flex flex-col justify-start p-12 text-primary-foreground",children:[e.jsxs(g,{to:"/",className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-9 w-9 rounded-lg bg-background/20 backdrop-blur grid place-items-center",children:e.jsx(v,{className:"h-5 w-5"})}),e.jsx("span",{className:"font-display text-xl font-bold",children:"SplashIQ"})]}),e.jsxs("div",{className:"pt-24",children:[e.jsx("div",{className:"font-display text-4xl font-bold tracking-tight max-w-md text-balance",children:'"Cut our route-planning time in half â and homeowners actually open our visit summaries now."'}),e.jsx("div",{className:"mt-6 text-sm opacity-80",children:"â Operations lead, California pool service company"})]})]})]}),e.jsx("main",{className:"flex items-center justify-center p-6",children:e.jsxs("div",{className:"w-full max-w-sm",children:[e.jsxs(g,{to:"/",className:"lg:hidden flex items-center gap-2 mb-8",children:[e.jsx("div",{className:"h-8 w-8 rounded-lg bg-water grid place-items-center",children:e.jsx(v,{className:"h-4 w-4 text-primary-foreground"})}),e.jsx("span",{className:"font-display text-lg font-bold",children:"SplashIQ"})]}),e.jsx("h1",{className:"font-display text-3xl font-bold",children:C}),e.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:E}),N?e.jsx("div",{className:"mt-8 rounded-md border p-4 text-sm",children:"Check your email for the verification link. Once verified, SplashIQ will attach your account to the invited workspace. Already verified? Sign in below."}):null,e.jsxs("form",{onSubmit:S,className:"mt-8 space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(j,{htmlFor:"email",children:"Email"}),e.jsx(y,{id:"email",type:"email",value:c,onChange:i=>p(i.target.value),readOnly:s==="invite-signup",required:!0})]}),s!=="forgot"&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(j,{htmlFor:"password",children:"Password"}),s==="signin"&&e.jsx("button",{type:"button",onClick:()=>o("forgot"),className:"text-xs text-muted-foreground hover:text-foreground transition-colors",children:"Forgot password?"})]}),e.jsx(y,{id:"password",type:"password",value:m,onChange:i=>b(i.target.value),required:!0,minLength:8})]}),e.jsx(R,{type:"submit",className:"w-full h-11",disabled:x,children:x?"Please wait...":L})]}),e.jsx("div",{className:"mt-6 text-center text-sm text-muted-foreground space-y-2",children:s==="forgot"?e.jsx("button",{onClick:()=>o("signin"),className:"hover:text-foreground transition-colors",children:"Back to sign in"}):s==="invite-signup"?e.jsx("button",{onClick:()=>o("signin"),className:"hover:text-foreground transition-colors",children:"Already have an account? Sign in"}):a?e.jsx("button",{onClick:()=>o("invite-signup"),className:"hover:text-foreground transition-colors",children:"New owner? Create an account with your invited email"}):e.jsx(g,{to:"/pricing",className:"hover:text-foreground transition-colors block",children:"Need a workspace? Start a 7-day trial"})})]})})]})}export{q 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.