1import{i as B,b7 as F,a as M,r as i,j as e,k as I,A as q,b8 as $,b9 as K,m as h,n as p,ba as O,bb as Z,B as U,s as j,g as x}from"./index-C3wyiG4j.js";import{A as G,b as H,a as J}from"./alert-ehS6FFfY.js";const W=()=>{const w=B(),{t}=F(),[C]=M(),r=C.get("token"),[a,y]=i.useState({full_name:"",email:"",phone:"",company:"",password:""}),[f,z]=i.useState(!1),[N,v]=i.useState(!1),[d,_]=i.useState(null),[k,L]=i.useState(""),[E,T]=i.useState(""),[u,S]=i.useState(null),[R,A]=i.useState(!1);i.useEffect(()=>{if(!r)return;(async()=>{A(!0),S(null);const{data:l,error:o}=await j.rpc("get_invitation_by_token",{_token:r}),s=Array.isArray(l)?l[0]:l,g=c=>{S(c),_(null),x.error(c.title,{description:c.description})};if(o)g({title:"Einladung konnte nicht geprüft werden",description:"Die Einladung konnte technisch nicht abgerufen werden. Bitte prüfe deine Internetverbindung und lade die Seite neu.",detail:o.message});else if(!s)g({title:"Einladung nicht gefunden",description:"Zu diesem Link existiert keine Einladung. Möglicherweise wurde der Link beim Kopieren gekürzt oder die Einladung wurde gelöscht. Bitte fordere eine neue Einladung an.",detail:`Token: ${r.slice(0,8)}â¦`});else if(s.status==="accepted")g({title:"Einladung bereits verwendet",description:"Diese Einladung wurde bereits angenommen. Melde dich einfach mit deinem bestehenden Konto an oder setze dein Passwort zurück.",detail:`Status: ${s.status}`});else if(s.status&&s.status!=="pending")g({title:"Einladung nicht mehr gültig",description:"Diese Einladung wurde zurückgezogen oder storniert. Bitte lass dir von deinem Administrator eine neue Einladung schicken.",detail:`Status: ${s.status}`});else if(s.expires_at&&new Date(s.expires_at)<=new Date)g({title:"Einladung abgelaufen",description:"Der Gültigkeitszeitraum dieser Einladung ist überschritten. Bitte fordere bei deinem Administrator eine neue Einladung an.",detail:`Abgelaufen am ${new Date(s.expires_at).toLocaleString("de-DE")}`});else{const c=s.full_name||"",D=s.company||"";L(c),T(D),y(b=>({...b,email:s.email||"",full_name:c||b.full_name,company:D||b.company})),_(s.role)}A(!1)})()},[r]);const m=(n,l)=>y(o=>({...o,[n]:l})),P=async n=>{if(n.preventDefault(),a.password.length<8){x.error(t("passwordMinError"));return}v(!0);const{data:l,error:o}=await j.auth.signUp({email:a.email,password:a.password,options:{data:{full_name:a.full_name,phone:a.phone,company:a.company},emailRedirectTo:"https://liefersoft.de/dashboard"}});if(o){x.error(o.message),v(!1);return}r&&l.user&&await j.rpc("accept_invitation",{_token:r,_user_id:l.user.id}),v(!1),r?(x.success(t("registerSuccess")),w("/dashboard/login")):(x.success("Registrierung eingegangen â ein Administrator prüft deinen Zugang. Du erhältst eine E-Mail, sobald dein Konto freigeschaltet ist.",{duration:8e3}),w("/dashboard/login"))};return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-muted/30",children:e.jsx("div",{className:"w-full max-w-md mx-4",children:e.jsxs("div",{className:"bg-card rounded-xl shadow-lg border p-8",children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[e.jsxs(I,{to:"/",className:"inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors",children:[e.jsx(q,{className:"h-4 w-4"}),t("backToMain")]}),e.jsx("div",{className:"w-32",children:e.jsx($,{})})]}),e.jsxs("div",{className:"text-center mb-8",children:[e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:t(r?"acceptInvitation":"registerTitle")}),e.jsx("p",{className:"text-muted-foreground mt-2",children:d?t("invitedAs",{role:d.replace("_"," ")}):t("createAccount")})]}),R&&e.jsx("p",{className:"text-sm text-muted-foreground text-center mb-4",children:"Einladung wird geprüftâ¦"}),u&&e.jsxs(G,{variant:"destructive",className:"mb-6",children:[e.jsx(K,{className:"h-4 w-4"}),e.jsx(H,{children:u.title}),e.jsxs(J,{className:"space-y-2",children:[e.jsx("p",{children:u.description}),u.detail&&e.jsxs("p",{className:"text-xs opacity-80",children:["Technischer Hinweis: ",u.detail]}),e.jsx("p",{className:"text-xs",children:"Du kannst dich hier trotzdem ohne Einladung registrieren â ein Administrator prüft dann deinen Zugang."})]})]}),e.jsxs("form",{onSubmit:P,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs(h,{htmlFor:"full_name",children:[t("fullName")," *"]}),e.jsx(p,{id:"full_name",value:a.full_name,onChange:n=>m("full_name",n.target.value),required:!0,readOnly:!!k,className:k?"bg-muted cursor-not-allowed":""})]}),e.jsxs("div",{children:[e.jsxs(h,{htmlFor:"email",children:[t("email")," *"]}),e.jsx(p,{id:"email",type:"email",value:a.email,onChange:n=>m("email",n.target.value),required:!0})]}),e.jsxs("div",{children:[e.jsx(h,{htmlFor:"phone",children:t("phone")}
1),e.jsx(p,{id:"phone",type:"tel",value:a.phone,onChange:n=>m("phone",n.target.value)})]}),e.jsxs("div",{children:[e.jsxs(h,{htmlFor:"company",children:[t("company")," ",!d||!["vertriebsmitarbeiter","head_of_sales","admin","senior_manager","manager"].includes(d)?"*":""]}),e.jsx(p,{id:"company",value:a.company,onChange:n=>m("company",n.target.value),required:!d||!["vertriebsmitarbeiter","head_of_sales","admin","senior_manager","manager"].includes(d),readOnly:!!E,className:E?"bg-muted cursor-not-allowed":""})]}),e.jsxs("div",{children:[e.jsx(h,{htmlFor:"password",children:t("passwordMin")}),e.jsxs("div",{className:"relative",children:[e.jsx(p,{id:"password",type:f?"text":"password",value:a.password,onChange:n=>m("password",n.target.value),required:!0,minLength:8,className:"pr-10"}),e.jsx("button",{type:"button",className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",onClick:()=>z(!f),tabIndex:-1,children:f?e.jsx(O,{size:16}):e.jsx(Z,{size:16})})]})]}),e.jsx(U,{type:"submit",className:"w-full",disabled:N,children:t(N?"registering":"register")})]}),e.jsxs("p",{className:"text-center text-sm text-muted-foreground mt-6",children:[t("alreadyRegistered")," ",e.jsx(I,{to:"/dashboard/login",className:"text-primary hover:underline",children:t("signIn")})]})]})})})};export{W 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.