import{u as w,r as o,j as e,N,L as S,S as C,s as x}from"./index-CrYQtPeZ.js";import{S as L}from"./SectionTitle-DgmmrH_c.js";const U=()=>{const{user:h,loading:g}=w(),[t,f]=o.useState(!0),[a,b]=o.useState(""),[n,y]=o.useState(""),[i,j]=o.useState(""),[c,u]=o.useState(""),[d,l]=o.useState(""),[m,p]=o.useState(!1);if(g)return null;if(h)return e.jsx(N,{to:"/forum",replace:!0});const v=async r=>{r.preventDefault(),u(""),l(""),p(!0);try{if(t){const{error:s}=await x.auth.signInWithPassword({email:a,password:n});if(s)throw s}else{if(i.trim().length<3)throw new Error("Le nom d'utilisateur doit contenir au moins 3 caractères.");const{error:s}=await x.auth.signUp({email:a,password:n,options:{data:{username:i.trim()},emailRedirectTo:window.location.origin}});if(s)throw s;l("Un email de confirmation vous a été envoyé. Vérifiez votre boîte de réception.")}}catch(s){u(s.message||"Une erreur est survenue.")}finally{p(!1)}};return e.jsxs(S,{children:[e.jsx(C,{title:"Connexion – Hellwatt Festival Forum",description:"Connectez-vous ou créez un compte pour participer au forum du Hellwatt Festival.",path:"/auth"}),e.jsxs("section",{className:"container py-16 max-w-md mx-auto",children:[e.jsx(L,{as:"h1",className:"text-3xl mb-8 text-center",children:t?"Connexion":"Créer un compte"}),e.jsxs("form",{onSubmit:v,className:"space-y-4",children:[!t&&e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-muted-foreground mb-1 block",children:"Nom d'utilisateur"}),e.jsx("input",{type:"text",value:i,onChange:r=>j(r.target.value),required:!t,minLength:3,maxLength:30,className:"w-full px-4 py-2.5 bg-secondary border border-border rounded-lg text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:border-primary",placeholder:"Votre pseudo"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-muted-foreground mb-1 block",children:"Email"}),e.jsx("input",{type:"email",value:a,onChange:r=>b(r.target.value),required:!0,className:"w-full px-4 py-2.5 bg-secondary border border-border rounded-lg text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:border-primary",placeholder:"votre@email.com"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-muted-foreground mb-1 block",children:"Mot de passe"}),e.jsx("input",{type:"password",value:n,onChange:r=>y(r.target.value),required:!0,minLength:6,className:"w-full px-4 py-2.5 bg-secondary border border-border rounded-lg text-sm text-foreground placeholder:text-muted-foreground focus:outline-none focus:border-primary",placeholder:"••••••••"})]}),c&&e.jsx("p",{className:"text-sm text-destructive",children:c}),d&&e.jsx("p",{className:"text-sm text-primary",children:d}),e.jsx("button",{type:"submit",disabled:m,className:"w-full bg-primary text-primary-foreground px-5 py-2.5 rounded-lg font-medium text-sm hover:opacity-90 transition-opacity disabled:opacity-50",children:m?"Chargement...":t?"Se connecter":"Créer un compte"})]}),e.jsxs("p",{className:"text-sm text-muted-foreground text-center mt-6",children:[t?"Pas encore de compte ?":"Déjà un compte ?"," ",e.jsx("button",{onClick:()=>{f(!t),u(""),l("")},className:"text-primary hover:underline",children:t?"Créer un compte":"Se connecter"})]})]})]})};export{U as default};