1import{u as I,w as T,a as q,r as o,j as e,N as $,L as j,v as N,b as u,k as F}from"./index-B0sM48fE.js";import{A as S,a as _}from"./AuthInput-9rhwaw4R.js";import"./eye-off-CNUKsdly.js";function M(){const L=I(),{isAuthenticated:k,isLoadingAuth:C}=T(),{t}=q(),[f,E]=o.useState("form"),[n,P]=o.useState(""),[c,A]=o.useState(""),[g,R]=o.useState(""),[i,p]=o.useState(!1),[d,r]=o.useState(""),x=o.useRef(null);if(o.useEffect(()=>{if(f==="otp"){const a=setTimeout(()=>{var s;return(s=x.current)==null?void 0:s.focus()},100);return()=>clearTimeout(a)}},[f]),!C&&k)return e.jsx($,{to:"/app",replace:!0});const U=async a=>{if(a.preventDefault(),r(""),c.length<8){r(t("auth_signup_password_short"));return}p(!0);try{await u.auth.register({email:n.trim().toLowerCase(),password:c}),E("otp")}catch(s){r((s==null?void 0:s.message)||t("auth_signup_error"))}finally{p(!1)}},y=async a=>{var w;let s=g;if(a&&typeof a=="object"&&typeof a.preventDefault=="function"?a.preventDefault():typeof a=="string"&&(s=a),s=(s||"").trim(),!i){if(s.length!==6){r("Entre les 6 chiffres du code.");return}r(""),p(!0);try{await u.auth.verifyOtp({email:n.trim().toLowerCase(),otpCode:s});try{await u.auth.loginViaEmailPassword(n.trim().toLowerCase(),c)}catch(h){console.warn("Login after verify skipped (session may already be active):",h)}F("SIGN_UP",{user_email:n.trim().toLowerCase()});const l=new URLSearchParams(window.location.search),b=l.get("checkout"),v=l.get("period");if(b&&v){const h=l.get("ref")||localStorage.getItem("affiliate_ref")||void 0;try{const m=await u.functions.invoke("createStripeCheckout",{serviceKey:b,billingPeriod:v,...h?{affiliateCode:h}:{}}
1);if((w=m.data)!=null&&w.sessionUrl){window.location.href=m.data.sessionUrl;return}}catch(m){console.error("Post-signup checkout failed:",m)}}L("/app",{replace:!0}),window.location.reload()}catch(l){r((l==null?void 0:l.message)||t("auth_signup_otp_invalid")),p(!1)}}},D=async()=>{r("");try{await u.auth.resendOtp(n.trim().toLowerCase())}catch(a){r((a==null?void 0:a.message)||t("auth_signup_otp_resend_failed"))}};return f==="otp"?e.jsx(S,{title:t("auth_signup_otp_title"),subtitle:`${t("auth_signup_otp_subtitle_prefix")} ${n}`,footer:e.jsx("button",{onClick:D,className:"text-primary hover:text-primary/80 font-medium",children:t("auth_signup_otp_resend")}),children:e.jsxs("form",{onSubmit:y,className:"space-y-4",children:[e.jsx(_,{ref:x,label:t("auth_signup_otp_label"),type:"text",inputMode:"numeric",pattern:"[0-9]*",maxLength:6,autoComplete:"one-time-code",value:g,onChange:a=>{const s=a.target.value.replace(/\D/g,"").slice(0,6);R(s),s.length===6&&!i&&setTimeout(()=>y(s),50)},placeholder:"123456",required:!0,disabled:i}),d&&e.jsx("p",{className:"text-sm text-red-400",children:d}),e.jsx("button",{type:"submit",disabled:i||g.length!==6,className:"w-full py-3 bg-primary hover:bg-primary/90 text-primary-foreground font-bold rounded-xl transition disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2",children:i?e.jsxs(e.Fragment,{children:[e.jsx(j,{className:"w-4 h-4 animate-spin"}),t("auth_signup_otp_verifying")]}):t("auth_signup_otp_button")})]})}):e.jsx(S,{title:t("auth_signup_title"),subtitle:t("auth_signup_subtitle"),footer:e.jsxs(e.Fragment,{children:[t("auth_signup_has_account")," ",e.jsx(N,{to:`/signin${typeof window<"u"?window.location.search:""}`,className:"text-primary hover:text-primary/80 font-medium",children:t("auth_signup_signin_link")})]}),children:e.jsxs("form",{onSubmit:U,className:"space-y-4",children:[e.jsx(_,{label:t("auth_email_label"),type:"email",value:n,onChange:a=>P(a.target.value),placeholder:t("auth_email_placeholder"),autoComplete:"email",required:!0,disabled:i}),e.jsx(_,{label:t("auth_password_label"),type:"password",value:c,onChange:a=>A(a.target.value),placeholder:t("auth_password_placeholder_new"),autoComplete:"new-password",required:!0,disabled:i}),d&&e.jsx("p",{className:"text-sm text-red-400",children:d}),e.jsxs("button",{type:"submit",disabled:i,className:"w-full py-3 bg-primary hover:bg-primary/90 text-primary-foreground font-bold rounded-xl transition disabled:opacity-50 flex items-center justify-center gap-2",children:[i&&e.jsx(j,{className:"w-4 h-4 animate-spin"}),t("auth_signup_button")]}),e.jsxs("p",{className:"text-xs text-white/50 text-center pt-2",children:[t("auth_signup_cgu_prefix")," ",e.jsx(N,{to:"/cgu",className:"underline hover:text-white/70",children:t("auth_signup_cgu_link")}),"."]})]})})}export{M 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.