1import{a as e,v as s,r as o,j as r,w as n,x as t,a$ as a,B as i,I as l}from"./index-Cu6nzwse.js";const c=()=>{const c=e(),{refreshQuota:d}=s(),[u,g]=o.useState("pending"),f=o.useRef(!1),m=o.useMemo(()=>{try{return new URLSearchParams(window.location.search).get("return_url")||null}catch{return null}},[]);return o.useEffect(()=>{if(f.current)return;f.current=!0;(async()=>{try{const{data:{session:e}}=await l.auth.getSession(),s=new URLSearchParams(window.location.search).get("session_id");if(e){if(console.log("User already logged in"),s){console.log("User completed payment, refreshing session to pick up new role");const{error:e}=await l.auth.refreshSession();e?(console.error("Failed to refresh session:",e),g("failed")):(console.log("Session refreshed successfully"),g("success"),d())}else console.log("User manually navigated here, no refresh needed"),g("success");return}if(console.log("User not logged in"),!s&&!m)return console.log("No session ID or return URL found, skipping auto-login"),void g("skipped");let o;s?(console.log("Attempting auto-login with session ID from URL:",s),o={sessionId:s}):(console.log("Attempting auto-login with return URL:",m),o={returnUrl:m});const{data:r,error:n}=await l.functions.invoke("stripe-session-login",{body:o});if(n)return console.error("Auto-login failed:",n),void(n.message&&n.message.includes("Session expired")?(console.log("Payment session expired, skipping auto-login"),g("skipped")):g("failed"));if((null==r?void 0:r.success)&&(null==r?void 0:r.verificationToken)){console.log("Attempting to verify OTP with token");const{error:e}=await l.auth.verifyOtp({token_hash:r.verificationToken,type:"email"});e?(console.error("Failed to verify OTP:",e),g("failed")):(console.log("Successfully logged in user:",r.user.email),g("success"),d())}else console.error("No verification token received"),g("failed")}catch(e){console.error("Auto-login error:",e),g("failed")}})()},[]),o.useEffect(()=>{if(m&&"pending"!==u&&("success"===u||"skipped"===u)){const e=setTimeout(()=>{try{window.location.assign(m)}catch{}},4e3);return()=>clearTimeout(e)}},[u,m]),r.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gray-50 dark:bg-gray-900",children:r.jsx(n,{className:"w-full max-w-md",children:r.jsxs(t,{className:"p-8 text-center space-y-6",children:[r.jsx("div",{className:"rounded-full bg-green-100 dark:bg-green-900 p-3 w-16 h-16 mx-auto flex items-center justify-center",children:r.jsx(a,{className:"h-8 w-8 text-green-600 dark:text-green-400"})}),r.jsxs("div",{children:[r.jsx("h1",{className:"text-2xl font-bold text-gray-900 dark:text-gray-100",children:"Your free trial has started!"}),r.jsx("p",{className:"mt-2 text-gray-600 dark:text-gray-300",children:"You have full access for 7 days â no charge until your trial ends. Cancel anytime from the billing portal."}),"skipped"!==u&&r.jsxs("div",{className:"mt-3 text-sm",children:["pending"===u&&r.jsx("p",{className:"text-blue-600 dark:text-blue-400",children:"ð Logging you in automatically..."}),"success"===u&&r.jsx("p",{className:"text-green-600 dark:text-green-400",children:"â
You're now logged in with your upgraded account!"}),"failed"===u&&r.jsx("p",{className:"text-orange-600 dark:text-orange-400",children:"â ï¸ Auto-login failed, but your upgrade is complete"})]})]}),r.jsxs("div",{className:"space-y-3",children:[r.jsx(i,{className:"w-full",onClick:()=>c("/"),children:"Continue"}),r.jsx(i,{variant:"outline",className:"w-full",onClick:()=>c(-1),children:"Go Back"}),m&&r.jsx(i,{variant:"secondary",className:"w-full",onClick:()=>window.location.assign(m),children:"Return to previous site"})]})]})})})};export{c as BillingSuccessPage,c 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.