1import{f as W,u as F,r as n,x as y,J as o,j as e,C as M,h as O,i as A,k as G,a as J,B as u,y as Y,I as z}from"./index-BOYZH3kX.js";import{b as H}from"./cities-BNlHJA_A.js";import{L as R}from"./loader-circle-B2atL_G-.js";import{C as X}from"./circle-check-big-BERj6Md5.js";import{C as T}from"./circle-x-D1mCaCV4.js";import{C as $}from"./circle-alert-RY2IJidO.js";function re(){const[v]=W(),f=F(),[i,d]=n.useState("loading"),[m,_]=n.useState(""),[j,b]=n.useState(!1),[N,q]=n.useState(""),[w,B]=n.useState(""),[k,C]=n.useState(""),[S,x]=n.useState(!1),p=v.get("token"),a=v.get("responseId"),I=n.useRef(a);I.current=a;const h=async s=>{const r=s||I.current;if(!r)return o.error("Invalid response ID"),!1;try{const{error:t}=await y.functions.invoke("resend-response-verification",{body:{responseId:r}});if(t)throw t;return!0}catch(t){return console.error("Resend error:",t),!1}};n.useEffect(()=>{p&&a?P(p,a):d(a?"otp-required":"invalid")},[p,a]);const E=(s,r,t,c)=>{const l=t||new Date(Date.now()+1728e5).toISOString();if(localStorage.setItem("resbo_session_email",s),localStorage.setItem("resbo_session_token",r),localStorage.setItem("resbo_session_expires",l),c){localStorage.setItem("resbo_selected_city",c);const g=H[c];g&&localStorage.setItem("resbo_selected_country",g.country),localStorage.setItem("resbo_city_onboarding_complete","true")}},V=s=>{q(s.bookTitle||""),B(s.requesterName||""),C(s.message||"Verification successful!"),s.responderEmail&&s.sessionToken&&E(s.responderEmail,s.sessionToken,s.expiresAt,s.city),d("success"),o.success("Response verified successfully!"),f("/resbo/app?tab=list&subtab=responses")},P=async(s,r)=>{try{console.log("Verifying with token...");const{data:t,error:c}=await y.functions.invoke("verify-response",{body:{token:s,responseId:r}}),l=(c==null?void 0:c.message)||(t==null?void 0:t.error);if(l)if(console.log("Verification error:",l),l.includes("expired")){await h(r)?(x(!0),o.info("Your link expired. We sent you a fresh verification code!")):o.error("Verification link has expired. Please request a new code."),d("otp-required");return}else{o.error(l),d("error"),C(l);return}V(t)}catch(t){console.error("Verification error:",t),await h(r)?(x(!0),o.info("We sent you a fresh verification code!")):o.error("Verification failed. Please try entering the code."),d("otp-required")}},D=async s=>{if(s.preventDefault(),!/^\d{6}$/.test(m)){o.error("Please enter a valid 6-digit code");return}if(!a){o.error("Invalid verification link");return}b(!0);try{const{data:r,error:t}=await y.functions.invoke("verify-response",{body:{otp:m,responseId:a}});if(t)throw t;r!=null&&r.error?o.error(r.error):V(r)}catch(r){console.error("OTP verification error:",r),o.error(r.message||"Verification failed. Please try again.")}finally{b(!1)}},L=async()=>{await h()?(x(!0),o.success("Verification code sent! Check your email.")):o.error("Failed to resend code")};return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gradient-to-br from-blue-50 to-indigo-100 p-4",children:e.jsxs(M,{className:"w-full max-w-md",children:[e.jsxs(O,{children:[e.jsxs(A,{className:"text-2xl text-center",children:[i==="loading"&&"Verifying...",i==="success"&&"â
Verified!",i==="error"&&"â Verification Failed",i==="otp-required"&&"Enter Verification Code",i==="invalid"&&"â Invalid Link"]}),e.jsxs(G,{className:"text-center",children:[i==="loading"&&"Please wait while we verify your response",i==="success"&&"Your book response is now active",i==="error"&&"There was a problem with verification",i==="otp-required"&&(S?"We sent a fresh 6-digit code to your email":"Enter the 6-digit code from your email"),i==="invalid"&&"This verification link is invalid or incomplete"]})]}),e.jsxs(J,{children:[i==="loading"&&e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx(R,{className:"h-12 w-12 animate-spin text-blue-600"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Verifying your response..."})]}),i==="success"&&e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx(X,{className:"h-16 w-16 text-green-600"}),e.jsx("p",{className:"text-center",children:k}),N&&e.jsxs("p",{className:"text-sm text-center",children:[e.jsx("strong",{children:"Book:"})," ",N]}),w&&e.jsxs("p",{className:"text-sm text-muted-foreground text-center",children:[w," will be notified and can now schedule a meeting with you."]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Redirecting you to ResBo..."})]}),i==="error"&&e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx(T,{className:"h-16 w-16 text-red-600"}),e.jsx("p",{className:"text-center text-red-600",children:k||"Verification failed"}),e.jsx(u,{onClick:()=>f("/resbo/app"),variant:"outline",className:"w-full",children:"Go to ResBo"})]}),i==="otp-required"&&e.jsxs("form",{onSubmit:D,className:"space-y-4",children:[e.jsxs("div",{className:"flex flex-col items-center gap-2 mb-4",children:[e.jsx($,{className:"h-12 w-12 text-blue-600"}),e.jsx("p",{className:"text-sm text-center text-muted-foreground",children:S?"Check your email for the fresh 6-digit code we just sent":"Check your email for the 6-digit verification code"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(Y,{htmlFor:"otp",children:"Verification Code"}),e.jsx(z,{id:"otp",type:"text",inputMode:"numeric",pattern:"\\d{6}",maxLength:6,placeholder:"123456",value:m,onChange:s=>_(s.target.value.replace(/\D/g,"")),className:"text-center text-2xl tracking-widest",required:!0})]}),e.jsx(u,{type:"submit",className:"w-full",disabled:j,children:j?e.jsxs(e.Fragment,{children:[e.jsx(R,{className:"mr-2 h-4 w-4 animate-spin"}),"Verifying..."]}):"Verify Code"}),e.jsx("div",{className:"text-center",children:e.jsx(u,{type:"button",variant:"link",size:"sm",onClick:L,className:"text-sm",children:"Resend verification code"})}),e.jsx(u,{type:"button",variant:"outline",className:"w-full",onClick:()=>f("/resbo/app"),children:"Back to ResBo"})]}),i==="invalid"&&e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx(T,{className:"h-16 w-16 text-red-600"}),e.jsx("p",{className:"text-center text-red-600",children:"This verification link is invali
1d or incomplete."}),e.jsx(u,{onClick:()=>f("/resbo/app"),variant:"outline",className:"w-full",children:"Go to ResBo"})]})]})]})})}export{re 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.