1import{u as I,o as P,E as L,f as k,r as o,j as e,h as A,m as O,B as T,s as c}from"./index-DLd_kDlx.js";import{L as V}from"./Layout-B4HKaXoo.js";import{L as R}from"./label-D4-ENrYn.js";import{I as B,a as F,b as a}from"./input-otp-lmz2zhuN.js";import{M}from"./mail-BVn2o8AP.js";import{L as q}from"./loader-circle-D2miE2xB.js";import{A as z}from"./arrow-left-BXtn7MCa.js";const Q=()=>{const l=I(),[b]=P(),{toast:r}=L(),{verifySignupOtp:v,resendSignupOtp:S}=k(),i=b.get("email")||"",[d,_]=o.useState(""),[x,m]=o.useState(!1),[t,y]=o.useState(60);o.useEffect(()=>{i||l("/enterprise")},[i,l]),o.useEffect(()=>{if(t>0){const n=setTimeout(()=>y(u=>u-1),1e3);return()=>clearTimeout(n)}},[t]);const C=async n=>{var u;if(n.preventDefault(),d.length!==6){r({title:"Please enter the complete 6-digit code",variant:"destructive"});return}m(!0);try{await v(i,d,"enterprise"),await new Promise(g=>setTimeout(g,1e3));const{data:s}=await c.auth.getSession(),p=(u=s==null?void 0:s.session)==null?void 0:u.user;if(!p)throw new Error("Authentication session not established. Please try logging in.");const f=sessionStorage.getItem("enterprise_company_name")||"",j=sessionStorage.getItem("enterprise_full_name")||"";if(!f)throw new Error("Company name not found. Please sign up again.");j&&await c.from("profiles").update({full_name:j}).eq("id",p.id);const{data:w}=await c.from("enterprise_accounts").select("id").ilike("name",f).maybeSingle();let h;if(w)h=w.id;else{const{data:g,error:N}=await c.from("enterprise_accounts").insert({name:f,created_by:p.id}).select("id").single();if(N)throw N;h=g.id}await c.from("enterprise_members").insert({enterprise_id:h,user_id:p.id,role:"member",is_active:!0,joined_at:new Date().toISOString()}),sessionStorage.removeItem("enterprise_company_name"),sessionStorage.removeItem("enterprise_full_name"),r({title:"Enterprise account created!",description:"Redirecting to your dashboardâ¦"}),l("/enterprise/dashboard")}catch(s){console.error("Enterprise verification error:",s),r({title:"Verification failed",description:s.message||"Please check your code and try again.",variant:"destructive"})}finally{m(!1)}},E=async()=>{if(!(t>0)){m(!0);try{await S(i,"enterprise"),y(60),r({title:"New code sent!",description:"Check your email for a new verification code."})}catch(n){r({title:"Failed to resend code",description:n.message,variant:"destructive"})}finally{m(!1)}}};return e.jsx(V,{children:e.jsx("div",{className:"container max-w-md py-16 md:py-24",children:e.jsx(A,{className:"shadow-lg border-0 bg-card/95 backdrop-blur-sm",children:e.jsxs(O,{className:"p-8 space-y-6",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-12 h-12 bg-primary/10 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(M,{className:"h-6 w-6 text-primary"})}),e.jsx("h1",{className:"text-2xl font-bold mb-1",children:"Verify Your Email"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Enter the 6-digit code sent to"," ",e.jsx("span",{className:"font-medium text-foreground",children:i})]})]}),e.jsxs("form",{onSubmit:C,className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(R,{className:"text-sm font-medium",children:"Verification Code"}),e.jsx("div",{className:"flex justify-center",children:e.jsx(B,{value:d,onChange:_,maxLength:6,className:"gap-2",children:e.jsxs(F,{className:"gap-2",children:[e.jsx(a,{index:0,className:"w-12 h-12 text-lg"}),e.jsx(a,{index:1,className:"w-12 h-12 text-lg"}),e.jsx(a,{index:2,className:"w-12 h-12 text-lg"}),e.jsx(a,{index:3,className:"w-12 h-12 text-lg"}),e.jsx(a,{index:4,className:"w-12 h-12 text-lg"}),e.jsx(a,{index:5,className:"w-12 h-12 text-lg"})]})})})]}),e.jsx(T,{type:"submit",size:"lg",className:"w-full",disabled:x||d.length!==6,children:x?e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"mr-2 h-4 w-4 animate-spin"})," Verifyingâ¦"]}):"Verify & Create Account"}),e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx("button",{type:"button",onClick:E,disabled:t>0||x,className:"text-sm text-primary hover:underline disabled:opacity-50 disabled:no-underline",children:t>0?`Resend code in ${t}s`:"Resend code"}),e.jsxs("button",{type:"button",onClick:()=>l("/enterprise"),className:"flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground mx-auto",children:[e.jsx(z,{className:"h-3 w-3"})," Back to signup"]})]})]})]})})})})};export{Q 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.