"use strict";(globalThis.webpackChunk_affine_web=globalThis.webpackChunk_affine_web||[]).push([[1800],{81800:(e,i,t)=>{t.r(i),t.d(i,{Component:()=>m});var n=t(36870),r=t(63234),a=t(53216),s=t(10980),o=t(91218),c=t(72254),u=t(30397),l=t(86326),p=t(4194),h=t(84190),g=t(82834),b=t(56607),d=t(29007),w=t(69628),f=t(94002),k=t(59481);let m=()=>{let{authService:e,subscriptionService:i}=(0,s.A$)({AuthService:k.uR,SubscriptionService:k.nC}),[t]=(0,p.ok)(),[m,v]=(0,l.useState)(""),[y,C]=(0,l.useState)(""),[R,$]=(0,l.useState)(0),{jumpToSignIn:S,jumpToIndex:j}=(0,w.P)(),x=(0,l.useMemo)(()=>(0,u.Ak)(),[]),A=t.get("plan"),E=t.get("recurring");return(0,l.useEffect)(()=>{let t=A?.toLowerCase()??"",n=E?.toLowerCase()??"",r=[];if(["ai","pro"].includes(t)||r.push("plan"),["monthly","yearly","lifetime"].includes(n)||r.push("recurring"),r.length){C(`Invalid ${r.join(", ")}`);return}let s=(0,o.Q)((0,h.n)(()=>(0,c.Sx)(async r=>{if(v("Checking account status..."),C(""),await e.session.waitForRevalidation(r),"authenticated"!==e.session.status$.value){v("Redirecting to sign in..."),S(location.pathname+location.search,w.Q.REPLACE);return}if(v("Checking subscription status..."),await i.subscription.waitForRevalidation(r),"ai"===t?i.subscription.ai$.value:"lifetime"===n?i.subscription.isBeliever$.value:i.subscription.pro$.value)v("Your account is already subscribed. Redirecting..."),await new Promise(e=>{setTimeout(e,5e3)}),j(w.Q.REPLACE);else{v("Creating checkout...");try{let r=e.session.account$.value;if(!r)throw Error("No account");let s="ai"===t?a.R$.AI:a.R$.Pro,o="monthly"===n?a.zS.Monthly:"yearly"===n?a.zS.Yearly:a.zS.Lifetime;f.u4.subscriptionLanding.$.$.checkout({control:"pricing",plan:s,recurring:o});let c=await i.createCheckoutSession({idempotencyKey:x,plan:s,coupon:null,recurring:o,successCallbackLink:(0,d.e6)(r,s,o)});v("Redirecting..."),location.href=c,A&&f.jp.people.set({[a.R$.AI===A?"ai plan":A]:A,recurring:E})}catch(e){console.error(e),C("Something went wrong. Please try again.")}}}).pipe((0,g.Z)(()=>b.w))));return s(),()=>{s.unsubscribe()}},[e,i,S,x,A,j,E,R]),(0,l.useEffect)(()=>{e.session.revalidate()},[e]),(0,n.jsx)("div",{className:"rdkpbn0",children:y?(0,n.jsxs)(n.Fragment,{children:[y,(0,n.jsx)("br",{}),(0,n.jsx)(r.$n,{variant:"primary",onClick:()=>$(e=>e+1),children:"Retry"})]}):(0,n.jsxs)(n.Fragment,{children:[m,(0,n.jsx)("br",{}),(0,n.jsx)(r.Rh,{size:20})]})})}}}]); //# sourceMappingURL=chunk.1800.6d8b4317.js.map