1import{f as D,e as F,r as i,j as e}from"./vendor-react-Dgkv3zLY.js";import{s as f}from"./index-BpeVYbuh.js";import{t as v,a5 as h,a0 as k}from"./vendor-icons-_OaOT06M.js";import"./vendor-radix-CAUjHo7r.js";import"./vendor-supabase-BeMDVzzN.js";import"./vendor-utils-B2rm_Apj.js";import"./vendor-motion-DuWIbOtB.js";function Z(){const[w]=D(),b=F(),m=w.get("token"),x=w.get("optout"),[r,a]=i.useState("loading"),[_,y]=i.useState("de"),[P,E]=i.useState(""),[j,S]=i.useState(""),[l,C]=i.useState(""),[N,A]=i.useState(""),[p,c]=i.useState("");i.useEffect(()=>{if(!m&&!x){a("invalid");return}(async()=>{try{if(x){const{data:n,error:g}=await f.functions.invoke("tradar-process-opt-out",{body:{token:x}});if(g)throw g;((n==null?void 0:n.language)==="de"||(n==null?void 0:n.language)==="en")&&y(n.language),a(n!=null&&n.already_opted_out?"already_opted_out":"opt_out_success");return}const{data:t,error:u}=await f.functions.invoke("tradar-validate-opt-in",{body:{token:m}});if(u)throw u;const o=t==null?void 0:t.error;if(o==="opted_out"){a("already_opted_out");return}if(o==="invalid_token"||!(t!=null&&t.success)){a("invalid");return}((t==null?void 0:t.language)==="de"||(t==null?void 0:t.language)==="en")&&y(t.language),E(t.email),S(t.masked_email||t.email),t.already_activated?a("already_activated"):a("form")}catch(t){console.error("[migrate] validate failed:",t),a("error"),c((t==null?void 0:t.message)||"Something went wrong")}})()},[m,x]);const s=_==="de",L=async d=>{if(d.preventDefault(),c(""),l.length<8){c(s?"Passwort muss mindestens 8 Zeichen haben.":"Password must be at least 8 characters.");return}if(l!==N){c(s?"Passwörter stimmen nicht überein.":"Passwords don't match.");return}a("submitting");try{const{data:t,error:u}=await f.functions.invoke("tradar-activate-account",{body:{token:m,password:l}});if(u)throw u;const o=t==null?void 0:t.error;if(o==="expired_token"){a("expired");return}if(o==="invalid_token"){a("invalid");return}if(o==="opted_out"){a("already_opted_out");return}if(o==="weak_password"){c(s?"Passwort muss mindestens 8 Zeichen haben.":"Password must be at least 8 characters."),a("form");return}if(o)throw new Error(o);const n=(t==null?void 0:t.email)||P;if(n){const{error:g}=await f.auth.signInWithPassword({email:n,password:l});if(g){a("done"),setTimeout(()=>b("/auth",{replace:!0}),1500);return}}a("done"),setTimeout(()=>b("/",{replace:!0}),1200)}catch(t){console.error("[migrate] activate failed:",t),c(s?"Etwas ist schiefgelaufen. Bitte versuche es erneut.":"Something went wrong. Please try again."),a("form")}};return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background p-4",children:e.jsxs("div",{className:"max-w-md w-full bg-card rounded-xl border border-border p-8 space-y-6",children:[r==="loading"&&e.jsxs("div",{className:"text-center space-y-3",children:[e.jsx(v,{className:"h-10 w-10 animate-spin text-primary mx-auto"}),e.jsx("p",{className:"text-muted-foreground",children:s?"Einen Moment...":"One moment..."})]}),(r==="form"||r==="submitting")&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:s?"Willkommen bei FanPool! ð":"Welcome to FanPool! ð"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s?`Lege jetzt Dein Passwort fest, um Dein Konto für ${j} zu aktivieren und 50 FanCredits zu erhalten.`:`Set a password to activate your account for ${j} and unlock 50 FanCredits.`})]}),e.jsxs("form",{onSubmit:L,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium text-foreground",children:s?"Passwort":"Password"}),e.jsx("input",{type:"password",autoComplete:"new-password",value:l,onChange:d=>C(d.target.value),className:"w-full px-3 py-2 rounded-md bg-background border border-border text-foreground focus:outline-none focus:ring-2 focus:ring-primary",required:!0,minLength:8,disabled:r==="submitting"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium text-foreground",children:s?"Passwort wiederholen":"Confirm password"}),e.jsx("input",{type:"password",autoComplete:"new-password",value:N,onChange:d=>A(d.target.value),className:"w-full px-3 py-2 rounded-md bg-background border border-border text-foreground focus:outline-none focus:ring-2 focus:ring-primary",required:!0,minLength:8,disabled:r==="submitting"})]}),p&&e.jsxs("div",{className:"flex items-start gap-2 text-sm text-destructive",children:[e.jsx(h,{className:"h-4 w-4 mt-0.5 shrink-0"}),e.jsx("span",{children:p})]}),e.jsx("button",{type:"submit",disabled:r==="submitting",className:"w-full py-2.5 rounded-md bg-primary text-primary-foreground font-medium hover:opacity-90 disabled:opacity-50 disabled:cursor-not-allowed transition",children:r==="submitting"?e.jsxs("span",{className:"flex items-center justify-center gap-2",children:[e.jsx(v,{className:"h-4 w-4 animate-spin"}),s?"Aktiviere...":"Activating..."]}):s?"Konto aktivieren & 50 FC erhalten":"Activate account & claim 50 FC"})]}),e.jsx("p",{className:"text-xs text-muted-foreground text-center",children:s?"Probleme? Schreibe uns an [email protected].":"Issues? Email [email protected]."})]}),r==="done"&&e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx(k,{className:"h-16 w-16 text-primary mx-auto"}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:s?"Konto aktiviert! ð":"Account activated! ð"}),e.jsx("p",{className:"text-muted-foreground",children:s?"Du wirst eingeloggt...":"Signing you in..."}),e.jsx(v,{className:"h-6 w-6 animate-spin text-primary mx-auto"})]}
1),r==="already_activated"&&e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx(k,{className:"h-16 w-16 text-muted-foreground mx-auto"}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:s?"Konto bereits aktiv":"Account already active"}),e.jsx("p",{className:"text-muted-foreground",children:s?"Dein FanPool-Konto ist bereits aktiviert. Bitte melde Dich an.":"Your FanPool account is already activated. Please sign in."}),e.jsx("button",{onClick:()=>b("/auth",{replace:!0}),className:"w-full py-2.5 rounded-md bg-primary text-primary-foreground font-medium hover:opacity-90 transition",children:s?"Zur Anmeldung":"Go to sign-in"})]}),r==="opt_out_success"&&e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx(h,{className:"h-16 w-16 text-muted-foreground mx-auto"}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:s?"Abmeldung bestätigt":"Opt-out confirmed"}),e.jsx("p",{className:"text-muted-foreground",children:s?"Sie wurden aus unserer Kontaktliste entfernt. Wir respektieren Ihre Entscheidung.":"You've been removed from our contact list. We respect your decision."})]}),r==="already_opted_out"&&e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx(h,{className:"h-16 w-16 text-muted-foreground mx-auto"}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:s?"Bereits abgemeldet":"Already opted out"}),e.jsx("p",{className:"text-muted-foreground",children:s?"Diese E-Mail-Adresse wurde abgemeldet.":"This email address has opted out."})]}),(r==="expired"||r==="invalid"||r==="error")&&e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx(h,{className:"h-16 w-16 text-destructive mx-auto"}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:r==="expired"?s?"Link abgelaufen":"Link expired":s?"Ungültiger Link":"Invalid link"}),e.jsx("p",{className:"text-muted-foreground",children:r==="expired"?s?"Dieser Aktivierungslink ist abgelaufen. Bitte kontaktiere uns für einen neuen Link.":"This activation link has expired. Please contact us for a fresh link.":s?"Wir können diesen Link nicht zuordnen. Bitte prüfe die Adresse in Deiner E-Mail.":"We can't match this link. Please check the URL from your email."}),p&&e.jsx("p",{className:"text-xs text-muted-foreground",children:p}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s?"Hilfe: [email protected]":"Need help? [email protected]"})]})]})})}export{Z 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.