1import{r as i,j as e,aa as $,c6 as D,cL as H,bc as K,bd as q,b3 as F,d2 as Q,an as W}from"./vendor-DH3sIdl2.js";import{b1 as G,s as C,g as J,aQ as X,S as v,B as p,b2 as z,t as r}from"./index-BwHllA22.js";import{I as k}from"./Input-BVWsGTsI.js";import{m as f}from"./motion-CAIqhnBW.js";import"./utils-CDPbcFE-.js";const te=({token:c,onActivated:b,onRequestLogin:d,onGoHome:S})=>{const[t,V]=i.useState(null),[E,P]=i.useState(!0),[n,I]=i.useState(""),[m,L]=i.useState(""),[u,B]=i.useState(!1),[l,o]=i.useState(!1),[x,M]=i.useState(null);i.useEffect(()=>{let s=!1;return(async()=>{const[a,h]=await Promise.all([G(c),C.auth.getSession().then(({data:U})=>{var N,w;return((w=(N=U.session)==null?void 0:N.user)==null?void 0:w.email)??null}).catch(()=>null)]);s||(V(a),M(h),P(!1))})(),()=>{s=!0}},[c]);const O=async()=>{if(!(!t||l)){o(!0);try{const s=await z(c);if(!s.success){r({title:"Liaison impossible",description:s.message||"Réessayez ou appelez le 04 12 13 62 41.",variant:"destructive"}),o(!1);return}const a=s.email||t.email;if(x&&x.toLowerCase()===a.toLowerCase()){r({title:"Chantier relié â",description:"Votre chantier a été ajouté à votre compte."}),b();return}r({title:"Chantier relié â",description:"Connectez-vous avec votre mot de passe habituel pour y accéder."}),d(a)}catch(s){console.error("[ChantierInvitePage] liaison compte existant KO :",s),r({title:"Erreur",description:"Une erreur est survenue. Réessayez ou appelez-nous au 04 12 13 62 41.",variant:"destructive"}),o(!1)}}},T=J(n),A=X(n),j=m.length>0&&n===m,g=A&&j&&!l,R=async s=>{if(s.preventDefault(),!(!g||!t)){o(!0);try{const a=await z(c,n);if(!a.success){r({title:"Activation impossible",description:a.message||"Réessayez ou contactez-nous au 04 12 13 62 41.",variant:"destructive"}),o(!1);return}if(a.mode==="login"){r({title:"Vous avez déjà un compte",description:"Votre chantier a été relié à votre compte existant. Connectez-vous avec votre mot de passe habituel."}),d(a.email||t.email);return}const{error:h}=await C.auth.signInWithPassword({email:a.email||t.email,password:n});if(h){r({title:"Compte créé !",description:"Connectez-vous avec votre email et le mot de passe que vous venez de choisir."}),d(a.email||t.email);return}r({title:"Bienvenue ! ð",description:"Votre Espace Travaux est prêt."}),b()}catch(a){console.error("[ChantierInvitePage] activation KO :",a),r({title:"Erreur",description:"Une erreur est survenue. Réessayez ou appelez-nous au 04 12 13 62 41.",variant:"destructive"}),o(!1)}}};if(E)return e.jsxs("div",{className:"min-h-screen bg-background flex flex-col items-center justify-center gap-4",children:[e.jsx(v,{size:"lg",className:"text-foreground/40"}),e.jsx("p",{className:"text-sm text-foreground/50",children:"Vérification de votre invitationâ¦"})]});if(!t||t.etat!=="valide"){const s=(t==null?void 0:t.etat)==="utilisee";return e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-4",children:e.jsxs(f.div,{initial:{opacity:0,y:16},animate:{opacity:1,y:0},className:"w-full max-w-md bg-card border border-border rounded-2xl p-8 text-center space-y-4",children:[e.jsx("div",{className:"mx-auto w-14 h-14 rounded-full bg-amber-500/10 flex items-center justify-center",children:e.jsx($,{className:"w-7 h-7 text-amber-500"})}),e.jsx("h1",{className:"text-xl font-serif font-bold text-foreground",children:s?"Invitation déjà utilisée":"Lien d'invitation non valide"}),e.jsx("p",{className:"text-sm text-foreground/60 leading-relaxed",children:s?"Votre espace a déjà été activé. Connectez-vous avec votre email et votre mot de passe.":"Ce lien a expiré ou n'est plus valide. Contactez Monsieur Ben bouazza au 04 12 13 62 41 pour en recevoir un nouveau."}),e.jsxs("div",{className:"flex flex-col gap-3 pt-2",children:[s&&t&&e.jsx(p,{onClick:()=>d(t.email),children:"Me connecter"}),e.jsx(p,{variant:"outline",onClick:S,children:"Retour à l'accueil"})]})]})})}if(t.compteExistant){const s=!!x&&x.toLowerCase()===t.email.toLowerCase();return e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-4",children:e.jsxs(f.div,{initial:{opacity:0,y:16}
1,animate:{opacity:1,y:0},className:"w-full max-w-md bg-card border border-border rounded-2xl overflow-hidden shadow-2xl",children:[e.jsxs("div",{className:"bg-black dark:bg-[#050505] p-6 text-center",children:[e.jsx("div",{className:"mx-auto w-14 h-14 rounded-2xl bg-primary/15 flex items-center justify-center mb-3",children:e.jsx(D,{className:"w-7 h-7 text-primary"})}),e.jsx("p",{className:"text-primary font-bold tracking-widest text-[11px] uppercase mb-1",children:"Les Maisons Vertes Provençales"}),e.jsx("h1",{className:"text-2xl font-serif font-bold text-white",children:"Bonne nouvelle : vous avez déjà un compte"})]}),e.jsxs("div",{className:"p-6 space-y-4 text-center",children:[e.jsxs("p",{className:"text-sm text-foreground/60 leading-relaxed",children:["Le suivi de votre chantier ",e.jsxs("strong",{className:"text-foreground",children:["« ",t.chantierTitre," »"]}),t.chantierVille?` à ${t.chantierVille}`:""," va être ajouté à votre compte",e.jsxs("strong",{className:"text-foreground",children:[" ",t.email]})," â photos, avancement, équipe, paiements et documents."]}),!s&&e.jsx("p",{className:"text-xs text-foreground/40",children:"Vous vous connecterez avec votre mot de passe habituel (« Mot de passe oublié » est là si besoin â pas de nouveau compte à créer)."}),e.jsx(p,{className:"w-full",size:"lg",onClick:O,disabled:l,children:l?e.jsx(v,{size:"sm"}):s?"Ajouter le chantier et ouvrir mon espace":"Relier le chantier et me connecter"})]})]})})}const y=[t.prenom,t.nom].filter(Boolean).join(" ");return e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-4 py-10",children:e.jsx(f.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.4},className:"w-full max-w-md",children:e.jsxs("div",{className:"bg-card border border-border rounded-2xl overflow-hidden shadow-2xl",children:[e.jsxs("div",{className:"bg-black dark:bg-[#050505] p-6 text-center",children:[e.jsx("div",{className:"mx-auto w-14 h-14 rounded-2xl bg-primary/15 flex items-center justify-center mb-3",children:e.jsx(H,{className:"w-7 h-7 text-primary"})}),e.jsx("p",{className:"text-primary font-bold tracking-widest text-[11px] uppercase mb-1",children:"Les Maisons Vertes Provençales"}),e.jsx("h1",{className:"text-2xl font-serif font-bold text-white",children:"Votre Espace Travaux"}),e.jsxs("p",{className:"text-white/50 text-sm mt-2",children:["Suivez votre chantier « ",t.chantierTitre," »",t.chantierVille?` à ${t.chantierVille}`:""," : photos, avancement et paiements."]})]}),e.jsxs("form",{onSubmit:R,className:"p-6 space-y-5",children:[e.jsxs("div",{className:"bg-foreground
1/5 border border-border rounded-xl p-4 space-y-1",children:[y&&e.jsx("p",{className:"font-semibold text-foreground",children:y}),e.jsx("p",{className:"text-sm text-foreground/60",children:t.email}),e.jsx("p",{className:"text-[11px] text-foreground/40 pt-1",children:"Ces informations ont été préparées pour vous. Il ne vous reste qu'à choisir votre mot de passe."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wider text-foreground/50",children:"Choisissez votre mot de passe"}),e.jsxs("div",{className:"relative",children:[e.jsx(k,{type:u?"text":"password",value:n,onChange:s=>I(s.target.value),placeholder:"Votre mot de passe",autoComplete:"new-password",autoFocus:!0}),e.jsx("button",{type:"button",onClick:()=>B(s=>!s),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground transition-colors","aria-label":u?"Masquer le mot de passe":"Afficher le mot de passe",children:u?e.jsx(K,{size:18}):e.jsx(q,{size:18})})]}),e.jsx("ul",{className:"space-y-1 pt-1",children:T.map(s=>e.jsxs("li",{className:`flex items-center gap-2 text-xs ${s.ok?"text-primary":"text-foreground/40"}`,children:[s.ok?e.jsx(F,{size:14}):e.jsx(Q,{size:14}),s.label]},s.label))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-xs font-semibold uppercase tracking-wider text-foreground/50",children:"Confirmez votre mot de passe"}),e.jsx(k,{type:u?"text":"password",value:m,onChange:s=>L(s.target.value),placeholder:"Confirmation",autoComplete:"new-password"}),m.length>0&&!j&&e.jsx("p",{className:"text-xs text-red-500",children:"Les deux mots de passe ne correspondent pas."})]}),e.jsx(p,{type:"submit",disabled:!g,className:"w-full",size:"lg",children:l?e.jsx(v,{size:"sm"}):"Valider et accéder à mon espace"}),e.jsxs("p",{className:"flex items-start gap-2 text-[11px] text-foreground/40 leading-relaxed",children:[e.jsx(W,{size:14,className:"shrink-0 mt-0.5 text-primary"}),"Accès sécurisé et personnel. En activant votre espace vous acceptez nos conditions d'utilisation. Données hébergées en Europe, jamais revendues."]})]})]})})})};export{te 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.