1import{r as s,j as e,B as j,A as se,M as ae,b as Y,u as re,d as ie,e as le,L as W,am as z,an as ne}from"./index-CrpPsQa6.js";import{C as X,c as Z}from"./card-Bqqtbe5t.js";import{c as oe,g as ce,a as de,i as me,b as H}from"./referralCode-BxErTuoD.js";import{f as J}from"./functions-DKk9Cl_A.js";import{I as E}from"./input-DUKoQAZK.js";import{L as B}from"./label-D2SdOD12.js";import{L as K}from"./loader-circle-VCJ5TxJ1.js";import{C as ue}from"./circle-check-big-DRAwsdlF.js";import{C as A}from"./circle-alert-Bve7bFt7.js";import{R as xe}from"./refresh-cw-Y4DkxcSD.js";import{G as Q}from"./gift-BQ2CTfcN.js";import{S as he}from"./sparkles-DOS2WGb6.js";function fe({onAuthed:a,onBack:d}){const[f,L]=s.useState("form"),[g,M]=s.useState(""),[m,n]=s.useState(""),[S,T]=s.useState(""),[_,b]=s.useState(""),[v,k]=s.useState(!1),[w,r]=s.useState(""),x=/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(g.trim())&&m.length>=6&&m===S,p=async i=>{var N,y;if(i.preventDefault(),r(""),m!==S){r("Passwords do not match.");return}if(m.length<6){r("Password must be at least 6 characters.");return}k(!0);try{await Y.auth.register({email:g.trim(),password:m}),L("otp")}catch(t){r(((y=(N=t==null?void 0:t.response)==null?void 0:N.data)==null?void 0:y.error)||(t==null?void 0:t.message)||"Could not start sign-up. That email may already be registered.")}finally{k(!1)}},P=async i=>{var N,y;i.preventDefault(),r(""),k(!0);try{await Y.auth.verifyOtp({email:g.trim(),otpCode:_.trim()}),await Y.auth.loginViaEmailPassword(g.trim(),m),a()}catch(t){r(((y=(N=t==null?void 0:t.response)==null?void 0:N.data)==null?void 0:y.error)||(t==null?void 0:t.message)||"Could not verify the code. Check the code and try again.")}finally{k(!1)}};return e.jsxs("div",{className:"mt-6 text-left",children:[f==="form"&&e.jsxs("form",{onSubmit:p,className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(B,{htmlFor:"su-email",className:"text-xs font-medium text-gray-600",children:"Email address"}),e.jsx(E,{id:"su-email",type:"email",value:g,onChange:i=>M(i.target.value),placeholder:"Use the email that received this invitation",className:"mt-1 h-11",required:!0})]}),e.jsxs("div",{children:[e.jsx(B,{htmlFor:"su-pw",className:"text-xs font-medium text-gray-600",children:"Create a password"}),e.jsx(E,{id:"su-pw",type:"password",value:m,onChange:i=>n(i.target.value),placeholder:"At least 6 characters",className:"mt-1 h-11",required:!0})]}),e.jsxs("div",{children:[e.jsx(B,{htmlFor:"su-cp",className:"text-xs font-medium text-gray-600",children:"Confirm password"}),e.jsx(E,{id:"su-cp",type:"password",value:S,onChange:i=>T(i.target.value),placeholder:"Re-enter your password",className:"mt-1 h-11",required:!0})]}),w&&e.jsx("p",{className:"text-sm text-red-600 bg-red-50 px-3 py-2 rounded-lg",children:w}),e.jsxs(j,{type:"submit",disabled:v||!x,className:"w-full bg-red-500 hover:bg-red-600 text-white h-11",children:[v?e.jsx(K,{className:"w-4 h-4 animate-spin mr-2"}):null,"Create account ",e.jsx(se,{className:"w-4 h-4 ml-1"})]}),e.jsx("p",{className:"text-xs text-gray-400 text-center",children:"We'll send a verification code to your email."})]}),f==="otp"&&e.jsxs("form",{onSubmit:P,className:"space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-2 bg-blue-50 rounded-lg p-3",children:[e.jsx(ae,{className:"w-4 h-4 text-blue-600 mt-0.5 flex-shrink-0"}),e.jsxs("p",{className:"text-xs text-blue-700",children:["We sent a verification code to ",e.jsx("strong",{children:g.trim()}),". Enter it below to confirm your account."]})]}),e.jsxs("div",{children:[e.jsx(B,{htmlFor:"su-otp",className:"text-xs font-medium text-gray-600",children:"Verification code"}),e.jsx(E,{id:"su-otp",value:_,onChange:i=>b(i.target.value),placeholder:"Enter the code from your email",className:"mt-1 h-11 tracking-widest text-center",required:!0})]}),w&&e.jsx("p",{className:"text-sm text-red-600 bg-red-50 px-3 py-2 rounded-lg",children:w}),e.jsxs(j,{type:"submit",disabled:v||!_.trim(),className:"w-full bg-red-500 hover:bg-red-600 text-white h-11",children:[v?e.jsx(K,{className:"w-4 h-4 animate-spin mr-2"}):null,"Verify and sign in"]}),e.jsx("button",{type:"button",onClick:d,className:"w-full text-xs text-gray-400 hover:text-gray-600",children:"Back"})]})]})}const ge="https://qtrypzzcjebvfcihiynt.supabase.co/storage/v1/object/public/base44-prod/public/2ced6e720_Artboard2.png",O=new Map,pe=(a,d)=>`${a}|${d||"anon"}`;function Be(){const{user:a,isAuthenticated:d,isLoadingAuth:f,navigateToLogin:L,logout:g,checkUserAuth:M}=re(),m=ie(),[n,S]=s.useState(null),[T,_]=s.useState(null),[b,v]=s.useState(null),[k,w]=s.useState(!1),[r,u]=s.useState("idle"),[x,p]=s.useState({code:null,message:""}),[P,i]=s.useState(0),[N,y]=s.useState(!1),t=s.useRef(!1);s.useEffect(()=>{oe();const l=ce();if(l)S(l);else{const o=de();o&&!me(o)&&_(o)}},[]),s.useEffect(()=>{if(!n||d||f)return;let l=!1;return w(!0),J.peekReferral({referral_code:n}).then(o=>{l||v((o==null?void 0:o.data)||{valid:!1,status:"invalid",referrer_first_name:null})}).catch(()=>{l||v({valid:!1,status:"invalid",referrer_first_name:null})}).finally(()=>{l||w(!1)}),()=>{l=!0}},[n,d,f]),s.useEffect(()=>{t.current=!1},[n,a==null?void 0:a.email]),s.useEffect(()=>{if(!n||!d||f||t.current)return;const l=pe(n,a==null?void 0:a.email);let o=O.get(l);o||(o=J.claimReferral({referral_code:n}),O.set(l,o),u("claiming")),o.then(c=>{if(t.current)return;t.current=!0;const h=(c==null?void 0:c.data)||{};h.success?(u(h.already_claimed?"already":"success"),H()):(u("error"),p({code:"unknown",message:h.error||"We could not complete your referral claim."}))}).catch(c=>{var D,G;if(t.current)return;t.current=!0;const h=(D=c==null?void 0:c.response)==null?void 0:D.status,R=((G=c==null?void 0:c.response)==null?void 0:G.data)||{}
1,U=R.code;U==="self_referral"||h===400&&/own referral|another email/i.test(R.error||"")?(u("error"),p({code:"self_referral",message:"This referral invitation is for another email address. Sign out to continue as the invited friend."})):U==="email_mismatch"||h===403?(u("error"),p({code:"email_mismatch",message:"Please sign up using the email address that received this invitation."})):U==="invalid_code"||h===404||h===400?(u("error"),p({code:"invalid_code",message:"This referral link is invalid."}),H()):h===409?(u("error"),p({code:"claim_in_progress",message:R.error||"We are preparing your referral claim. Please try again in a moment."})):(u("error"),p({code:"server_error",message:R.error||"We could not complete your referral claim right now. Please try again."}))}).finally(()=>{O.delete(l)})},[n,d,f,P]);const ee=()=>{t.current=!1,i(l=>l+1)},q=()=>L(window.location.origin+"/referral"),te=()=>m("/BookLesson"),I=()=>{g(!0)},V=r==="claiming";if(f)return e.jsx("div",{className:"min-h-[60vh] flex items-center justify-center",children:e.jsx("div",{className:"w-8 h-8 border-4 border-red-100 border-t-red-500 rounded-full animate-spin"})});if(!n&&T)return e.jsx(F,{message:"This referral link is invalid."});if(!n)return e.jsx(F,{message:"This referral link is invalid."});if(d)return r==="claiming"||r==="idle"?e.jsxs(C,{children:[e.jsx("div",{className:"w-8 h-8 border-4 border-red-100 border-t-red-500 rounded-full animate-spin mx-auto mb-4"}),e.jsx("h2",{className:"text-xl font-bold text-gray-900",children:"Claiming your referral rewardâ¦"}),e.jsx("p",{className:"text-gray-500 text-sm mt-1",children:"Just a moment while we add your lesson credit."})]}):r==="success"||r==="already"?e.jsxs(C,{children:[e.jsx("div",{className:"w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(ue,{className:"w-9 h-9 text-green-600"})}),e.jsx("h2",{className:"text-2xl font-bold text-gray-900",children:"Your referral reward has been added: 1 lesson credit. ð"}),e.jsx("p",{className:"text-gray-600 text-sm mt-2 max-w-md mx-auto",children:r==="already"?"You've already claimed this referral â 1 lesson credit is on your account. Book a lesson with any available teacher. Most teachers cost 1 credit per lesson. Ula costs 2 credits.":"1 lesson credit has been added to your account. Book a lesson with any available teacher. Most teachers cost 1 credit per lesson. Ula costs 2 credits."}),e.jsxs(j,{onClick:te,className:"mt-6 bg-red-500 hover:bg-red-600 text-white",children:[e.jsx(le,{className:"w-4 h-4 mr-1.5"})," Book a lesson"]}),e.jsx(W,{to:"/StudentDashboard",className:"block text-sm text-gray-500 hover:text-gray-700 mt-3",children:"Go to my dashboard"})]}):x.code==="self_referral"?e.jsxs(C,{children:[e.jsx("div",{className:"w-16 h-16 bg-amber-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(A,{className:"w-9 h-9 text-amber-600"})}),e.jsx("h2",{className:"text-xl font-bold text-gray-900",children:x.message}),e.jsx("p",{className:"text-gray-500 text-sm mt-2",children:"You're currently signed in as the person who sent this invitation. Sign out, then sign back in with the invited email address to claim your free lesson."}),e.jsxs(j,{onClick:I,variant:"outline",className:"mt-6",children:[e.jsx(z,{className:"w-4 h-4 mr-1.5"})," Sign out"]})]}):x.code==="email_mismatch"?e.jsxs(C,{children:[e.jsx("div",{className:"w-16 h-16 bg-amber-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(A,{className:"w-9 h-9 text-amber-600"})}),e.jsx("h2",{className:"text-xl font-bold text-gray-900",children:x.message}),e.jsxs("p",{className:"text-gray-500 text-sm mt-2 max-w-md mx-auto",children:["You're signed in as ",e.jsx("strong",{children:a==null?void 0:a.email}),", but this invitation was sent to a different email address. Sign out and create your account with the invited email to claim your free lesson."]}),e.jsxs(j,{onClick:I,variant:"outline",className:"mt-6",children:[e.jsx(z,{className:"w-4 h-4 mr-1.5"})," Sign out"]})]}):x.code==="invalid_code"?e.jsx(F,{message:x.message}):e.jsxs(C,{children:[e.jsx("div",{className:"w-16 h-16 bg-red-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(A,{className:"w-9 h-9 text-red-600"})}),e.jsx("h2",{className:"text-xl font-bold text-gray-900",children:"We couldn't complete your claim right now."}),e.jsx("p",{className:"text-gray-500 text-sm mt-2",children:x.message}),e.jsxs(j,{onClick:ee,disabled:V,className:"mt-6 bg-red-500 hover:bg-red-600 text-white",children:[e.jsx(xe,{className:`w-4 h-4 mr-1.5 ${V?"animate-spin":""}`})," Try again"]})]});if(k)return e.jsx("div",{className:"min-h-[60vh] flex items-center justify-center",children:e.jsx("div",{className:"w-8 h-8 border-4 border-red-100 border-t-red-500 rounded-full animate-spin"})});if(!b||!b.valid)return e.jsx(F,{message:"This referral link is invali
1d."});if(b.status==="signed_up"||b.status==="rewarded")return e.jsxs(C,{children:[e.jsx("div",{className:"w-16 h-16 bg-gray-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(Q,{className:"w-9 h-9 text-gray-500"})}),e.jsx("h2",{className:"text-xl font-bold text-gray-900",children:"This referral invitation has already been claimed."}),e.jsx("p",{className:"text-gray-500 text-sm mt-2",children:"The referral reward from this link has already been claimed."}),e.jsx(j,{onClick:q,variant:"outline",className:"mt-6",children:"Sign in"}),e.jsx(W,{to:"/",className:"block text-sm text-gray-500 hover:text-gray-700 mt-3",children:"Back to home"})]});const $=b.referrer_first_name;return e.jsx("div",{className:"max-w-2xl mx-auto px-4 py-12 sm:py-16",children:e.jsx(X,{className:"bg-gradient-to-br from-red-50 to-orange-50 border-red-100 shadow-lg",children:e.jsxs(Z,{className:"p-8 sm:p-10 text-center",children:[e.jsx("img",{src:ge,alt:"Mandarin Monkey",className:"h-16 w-16 object-contain mx-auto mb-4"}),e.jsxs("div",{className:"inline-flex items-center gap-1.5 bg-red-100 text-red-700 text-xs font-semibold px-3 py-1 rounded-full mb-4",children:[e.jsx(he,{className:"w-3.5 h-3.5"})," You've been invited"]}),e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold text-gray-900",children:"You've been invited to learn Mandarin with Mandarin Monkey ð"}),e.jsx("p",{className:"text-gray-600 text-base mt-3 leading-relaxed",children:$?e.jsxs(e.Fragment,{children:["Your friend ",e.jsx("strong",{children:$})," thinks you would love learning Mandarin â and they have invited you to join our online academy."]}):"A friend thinks you would love learning Mandarin â and they have invited you to join our online academy."}),e.jsx("div",{className:"bg-white/70 border border-red-100 rounded-2xl p-5 mt-6 text-left",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-10 h-10 bg-red-100 rounded-xl flex items-center justify-center flex-shrink-0",children:e.jsx(Q,{className:"w-5 h-5 text-red-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-gray-900 text-sm",children:"Create your account and receive one free lesson credit"}),e.jsx("p",{className:"text-gray-500 text-xs mt-1",children:"No existing account needed â just sign up with the email that received this invitation, and your lesson credit will be added automatically."})]})]})}),N?e.jsx(fe,{onAuthed:()=>M(),onBack:()=>y(!1)}):e.jsx(j,{onClick:()=>y(!0),className:"mt-7 bg-red-500 hover:bg-red-600 text-white text-base px-8 h-12",children:"Create your account and claim your free credit"}),e.jsxs("div",{className:"mt-4 text-sm text-gray-500",children:["Already have an account?"," ",e.jsx("button",{onClick:q,className:"text-red-600 hover:text-red-700 font-medium",children:"Sign in"})]})]})})})}function C({children:a}){return e.jsx("div",{className:"max-w-md mx-auto px-4 py-16 sm:py-24 text-center",children:e.jsx(X,{className:"shadow-sm",children:e.jsx(Z,{className:"p-8",children:a})})})}function F({message:a}){return e.jsxs(C,{children:[e.jsx("div",{className:"w-16 h-16 bg-gray-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(A,{className:"w-9 h-9 text-gray-400"})}),e.jsx("h2",{className:"text-xl font-bold text-gray-900",children:a}),e.jsx("p",{className:"text-gray-500 text-sm mt-2",children:"This referral link may have expired or been entered incorrectly."}),e.jsxs(W,{to:"/",className:"inline-flex items-center gap-1.5 text-sm text-red-600 hover:text-red-700 font-medium mt-6",children:[e.jsx(ne,{className:"w-4 h-4"})," Back to home"]})]})}export{Be 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.