import{z as T,F as a,j as e,r as c,g as Pe,c as U,a3 as F,aB as pe,u as we,K as ve,b as _e}from"./vendor-CT-JknSv.chunk.js";import{j as S,l as f,E as ue,i as x,b4 as J,aD as W,a7 as N,aF as he,b as H,c6 as X,n as R,bH as Ce,aE as Ie,G as ee,bR as Y,r as me,bF as K,cm as Te,k as Z,cF as Fe,cG as Be,a0 as ke,aW as Ee,cx as ae,cw as ze,cA as Ae,cH as Le,u as $e,P as Re}from"./index-DDZqnj79.js";import{g as We,e as He,f as Me,d as Ve}from"./SubscriptionSummary-DPjiGDu4.chunk.js";import{C as ce}from"./Checkbox-CgLYsCrp.chunk.js";import{F as le,a as je}from"./FormInputField-CoRdK2rH.chunk.js";import{F as Ne}from"./FormPasswordField-FDPkcmWm.chunk.js";import"./ExternalRedirect-BqsmRQpQ.chunk.js";const Qe="/static/clouds-CUKePHZK.png";function ge({price:t,description:i,callToAction:r,...o}){const n="LIFETIME MEMBERSHIP";return a("div",{css:$.wrapper,...o,children:[e("p",{css:$.p,children:n}),a("div",{css:$.price,children:["$",t]}),e("div",{css:$.description,children:i}),e("div",{css:$.cta,children:r({ariaLabelPrefix:`${n} $${t} `})})]})}const $={wrapper:T({background:`url(${Qe})`,position:"relative",borderRadius:"32px",display:"flex",flexDirection:"column",justifyContent:"flex-start",alignItems:"center",marginBottom:"24px",border:`1px solid ${S.blue400_10}`,color:S.neutral0,padding:"32px 20px",backgroundSize:"cover",backgroundOrigin:"border-box",backgroundPosition:"top center"}),h2:T({fontSize:"13px",lineHeight:"14px",color:S.blue400,fontWeight:f.weight.medium}),p:T({fontSize:"13px"}),price:T({fontSize:"32px",lineHeight:"45px",fontWeight:f.weight.semibold}),description:T({fontSize:"12px",fontWeight:f.weight.book,textAlign:"center"}),cta:T({marginTop:"13px",width:"calc(100% - 34px)",maxWidth:"240px",display:"flex",flexDirection:"column",alignItems:"stretch"})};function fe({product:t,selectedProductId:i,setSelectedProductId:r,...o}){const n=i===t.product_id,p=c.useId(),l=c.useId(),g=c.useId(),m=c.useId(),{promotion:P}=ue();return c.useEffect(()=>{t.period!=="monthly"&&t.period!=="yearly"&&Pe(new Error(`Unexpected product period: ${t.period}`))},[t.period]),a("div",{css:{width:"100%",height:"166px",borderRadius:"16px",border:n?`2px solid ${S.blue400}`:`1px solid ${x.label100}`,display:"flex",alignItems:"center",justifyContent:"flex-start",flexDirection:"column",padding:n?"16px 0px":"17px 1px"},...o,children:[e("div",{css:{fontSize:"12px",marginBottom:"0px",textTransform:"uppercase",color:n?S.blue400:"inherit"},id:p,children:t.period}),a("div",{css:{height:"45px",fontSize:"18px",fontWeight:f.weight.semibold,color:n?S.blue400:"inherit"},id:l,children:[e("span",{css:{fontSize:"32px"},children:e(qe,{product:t,promotion:P})}),t.period==="yearly"&&!P?"/year":"/month"]}),e("div",{id:m,css:{fontSize:"12px",marginBottom:"14px"},children:Oe(t,P)}),e(W,{theme:n?"primary":"secondary",css:{width:"calc( 100% - 34px )",height:"32px"},type:"button","aria-labelledby":`${p} ${l} ${m} ${g} `,id:g,"aria-selected":n,onClick:()=>{r(t.product_id)},children:n?a("div",{css:{display:"flex",justifyContent:"center",alignItems:"center"},children:[e(J,{css:{width:"16px",height:"16px",marginRight:"4px"}}),"Plan Selected"]}):"Select Plan"})]})}function Q({...t}){return a("div",{css:{height:"166px",borderRadius:"16px",border:`1px solid ${x.label100}`,display:"flex",alignItems:"center",justifyContent:"center",flexDirection:"column",padding:"20px"},...t,children:[e(N,{css:{height:"16px",marginBottom:"4px",width:"65px",borderRadius:"16px"}}),e(N,{css:{height:"38px",width:"109px",fontWeight:f.weight.semibold,borderRadius:"16px",marginBottom:"4px"}}),e(N,{css:{width:"91px",height:"16px",marginBottom:"16px",borderRadius:"16px"}}),e(N,{css:{width:"100%",height:"32px",borderRadius:"16px"}})]})}const Ue=t=>{const[i,r]=t.split(".");return{dollars:i,cents:r?r.padEnd(2,"0"):""}},Ke=t=>t.period==="monthly"?t.price:t.period==="yearly"?(Math.floor(parseFloat(t.price)/12*100)/100).toString():t.price,Oe=(t,i)=>t.period==="yearly"&&i?`Billed ${We(t.price,t.currency)} annually`:t.period==="yearly"?"Best value":"Cancel anytime",qe=({product:t,promotion:i,...r})=>{const{dollars:o,cents:n}=Ue(t.period==="yearly"&&!i?t.price:Ke(t));return a("span",{...r,children:[t.currency==="usd"?"$":"",o,n?a("span",{css:{fontSize:"18px"},children:[".",n]}):null,t.currency!=="usd"?t.currency:""]})};function Ge(){var V,w;const{notify:t,dismiss:i}=he(),[r]=H("product_id"),o=U(),n=(V=o.location.state)==null?void 0:V.returnTo,[p,l]=c.useState(!1),{availablePlans:g,lifetimeProduct:m,subscriptionPlans:P,error:B,isInitialLoading:k}=X({includeRenewsOn:!0}),[_,O]=H("verified",{defaultValue:"false",allowedValues:["false","true"]}),E=c.useCallback(h=>{let v=o.location.search;v=R(v,"product_id",h),o.push({search:v,state:o.location.state}),l(!1)},[o]),{availablePlans:q,error:y,isInitialLoading:z}=Ce(),A=Ie("email-validation-warnings"),d=c.useMemo(()=>de(g,h=>h.product_id===r),[g,r]),C=r&&!k&&!d;if(c.useEffect(()=>{C&&(l(!0),i(),t("The product you selected is no longer available for purchase.",{type:"error"}))},[C,i,t]),k||z)return null;if(A&&_!=="true")return e(De,{setVerified:()=>o.push({...O("true"),state:{returnTo:n}})});if(B||y)return a(c.Fragment,{children:[e(F,{defer:!1,children:e("title",{children:"Error"})}),e(ee,{error:B||y})]});const L=g.find(h=>h.products.find(v=>v.product_id===r)),G=pe(P.map(h=>h.products)),M=de(q,h=>h.period===(d==null?void 0:d.period)),b=m?m.product_id===r:!1;return a(K,{css:{paddingTop:"36px"},children:[e(F,{defer:!1,children:e("title",{children:"Set Up Your Payment"})}),L&&d&&M&&!p?e(He,{setShowChange:l,plan:L,product:d,showYourSubscriptionTitle:!0}):null,p||!d?a(c.Fragment,{children:[e(Y,{css:{marginBottom:"16px"},children:"Step 1 of 3"}),e("h1",{css:{fontSize:"22px",lineHeight:"28px",fontWeight:f.weight.semibold,color:x.label,marginBottom:"32px"},children:"Select your plan"}),m?e(ge,{price:m.price,description:(w=m.description)!=null?w:"",callToAction:({ariaLabelPrefix:h})=>e(W,{theme:b?"primary":"secondary",css:{height:"32px"},type:"button","aria-selected":b,onClick:()=>E(m.product_id),"aria-label":`${h} ${b?"Plan Selected":"Select Plan"}`,children:b?a("div",{css:{display:"flex",justifyContent:"center",alignItems:"center"},children:[e(J,{css:{width:"16px",height:"16px",marginRight:"4px"}}),"Plan Selected"]}):"Select Plan"})}):null,e("div",{css:{display:"grid",gridTemplateColumns:"1fr 1fr",width:"100%",gap:"24px",marginBottom:"64px",[me]:{gap:"15px"}},children:k||z?a(c.Fragment,{children:[e(Q,{}),e(Q,{})]}):G.map(h=>e(fe,{product:h,selectedProductId:d==null?void 0:d.product_id,setSelectedProductId:E},h.product_id))})]}):null,d?e(Me,{productId:d.product_id}):null]})}function De({setVerified:t}){return a(K,{css:{paddingTop:"36px"},children:[e(F,{defer:!1,children:e("title",{children:"Verify Email"})}),e("h1",{css:{fontSize:"22px",lineHeight:"28px",fontWeight:f.weight.semibold,color:x.label,marginBottom:"32px"},children:"Verify Email"}),a("p",{css:{fontSize:"13px",lineHeight:"18px",marginBottom:"20px"},children:["We have sent a confirmation request to the email address you provided. Please check your inbox and verify your email address before proceeding.",e("br",{}),e("br",{}),"For security reasons, you will be unable to begin a Nebula subscription until your email address has been verified."]}),a(Te,{children:[e("div",{}),e(W,{onClick:t,children:"Continue"})]})]})}function de(t,i){for(const r of t)for(const o of r.products)if(i(o))return o}function Ye(){const{availablePlans:t,error:i,isInitialLoading:r}=X();return i?a(c.Fragment,{children:[e(F,{defer:!1,children:e("title",{children:"Error"})}),e(ee,{error:i})]}):a(K,{css:{paddingTop:"36px"},children:[e(F,{defer:!1,children:e("title",{children:"Create Account"})}),e(Xe,{availablePlans:t,arePlansLoading:r}),a("div",{css:{fontSize:"15px",lineHeight:"20px",textAlign:"center",marginTop:"52px"},children:[e("span",{css:{color:x.label400,fontWeight:f.weight.book},children:"Already have an account?"})," ",e(Z,{to:"/login",theme:"nebulaBlue",css:{fontWeight:f.weight.medium,"&:hover":{textDecoration:"underline"}},children:"Sign in to Nebula"})]})]})}function Ze(t){var o,n,p;if(!t)return null;const i=(o=t.response)==null?void 0:o.data;return{email:(n=i==null?void 0:i.email)==null?void 0:n[0],password:(p=i==null?void 0:i.password)==null?void 0:p[0]}}function Je({promotion:t,currency:i}){return!t||!t.alternate_discounted_plan||!t.discounted_plan?[]:[{product_id:t.alternate_discounted_plan.stripe_id,period:t.alternate_discounted_plan.interval,price:(t.alternate_discounted_plan.amount_in_cents/100).toString(),currency:i!=null?i:"usd",legacy:!1},{product_id:t.discounted_plan.stripe_id,period:t.discounted_plan.interval,price:(t.discounted_plan.amount_in_cents/100).toString(),currency:i!=null?i:"usd",legacy:!1}]}function Xe({availablePlans:t,arePlansLoading:i}){var ie,ne,se;const{notify:r,dismiss:o}=he(),[n,p]=c.useState(""),[l,g]=c.useState(""),[m,P]=c.useState(!1),[B,k]=c.useState(!1),_=U(),{search:O}=we(),{promotion:E,isInitialLoading:q}=ue(),[y]=H("product_id"),z=new URLSearchParams(O).get("plan")==="lifetime",A=t.find(s=>s.is_lifetime),d=A==null?void 0:A.products[0],C=pe(t.filter(s=>!s.is_lifetime).map(s=>s.products)),[L,G]=c.useState(!z),M=z?d==null?void 0:d.product_id:(ie=C.find(s=>s.period==="yearly"))==null?void 0:ie.product_id,b=c.useCallback(s=>{let u=_.location.search;u=R(u,"product_id",s),_.replace({search:u,state:_.location.state})},[_]);c.useEffect(()=>{y||b(M)},[M,y,b]);const{mutate:V,isLoading:w,error:h}=Fe({onError:s=>{var re,oe;const u=(re=s.response)==null?void 0:re.data;if(!(u!=null&&u.email)&&!(u!=null&&u.password)){o();let D=s.message;(oe=u==null?void 0:u.non_field_errors)!=null&&oe[0]&&(D=u.non_field_errors[0]),u!=null&&u.detail&&(D=u.detail),r(D,{type:"error"})}}}),v=c.useCallback(s=>{p(s.target.value||"")},[]),xe=c.useCallback(s=>{g(s.target.value||"")},[]),be=s=>{s.preventDefault(),s.stopPropagation(),!w&&(!n||!l||!m||V({email:n,password:l,agreed_to_terms:m,opt_in_to_communications:B}))},I=Ze(h),te=Je({promotion:E,currency:(ne=C[0])==null?void 0:ne.currency}),ye=te.length>0?te:C,Se=d&&!L,j=d?d.product_id===y:!1;return a("form",{onSubmit:be,children:[a(ve,{children:[e(Y,{css:{marginBottom:"10px"},children:"Step 1 of 3"}),e("h1",{css:{fontSize:"22px",lineHeight:"28px",fontWeight:f.weight.semibold,color:x.label,marginBottom:"24px"},children:"Select your plan"}),e(Be,{promotion:E,message:"Thank you for supporting",css:{padding:16}}),d?e(ge,{price:d.price,description:(se=d.description)!=null?se:"",callToAction:({ariaLabelPrefix:s})=>e(W,{theme:j?"primary":"secondary",css:{height:"32px"},type:"button","aria-selected":j,onClick:()=>b(d.product_id),"aria-label":`${s} ${j?"Plan Selected":"Select Plan"}`,children:j?a("div",{css:{display:"flex",justifyContent:"center",alignItems:"center"},children:[e(J,{css:{width:"16px",height:"16px",marginRight:"4px"}}),"Plan Selected"]}):"Select Plan"})}):null,Se?e("button",{type:"button",onClick:()=>{G(!0)},css:{color:S.blue400,cursor:"pointer",[ke]:{"&:hover":{color:S.blue600}},verticalAlign:"bottom",textDecoration:"dotted",fontWeight:f.weight.medium,fontSize:"14px",marginBottom:"64px",lineHeight:"20px",textAlign:"center"},children:"See other plans"}):null,L?e("div",{css:{display:"grid",gridTemplateColumns:"1fr 1fr",width:"100%",gap:"24px",marginBottom:"64px",[me]:{gap:"15px"}},children:i||q?a(c.Fragment,{children:[e(Q,{}),e(Q,{})]}):ye.map(s=>e(fe,{product:s,selectedProductId:y,setSelectedProductId:b},s.product_id))}):null,e(Y,{css:{marginBottom:"16px"},children:"Step 2 of 3"})]}),e("h1",{css:{fontSize:"22px",lineHeight:"28px",fontWeight:f.weight.semibold,color:x.label,marginBottom:"52px"},children:"Create Account"}),e("div",{}),e(le,{htmlFor:"input-email",css:{marginBottom:8},children:"Email Address"}),e(je,{autoComplete:"username",readOnly:w,name:"email",id:"input-email",onChange:v,placeholder:"your@email.com",type:"email",value:n,errorMessage:I==null?void 0:I.email}),e(le,{css:{marginTop:24,marginBottom:8},htmlFor:"input-password",children:"Password"}),e(Ne,{autoComplete:"new-password",readOnly:w,id:"input-password",name:"password",onChange:xe,value:l,errorMessage:I==null?void 0:I.password}),e(ce,{name:"agreedToTerms",checked:m,onChange:()=>{P(s=>!s)},css:{color:x.label,fontSize:"15px",lineHeight:"20px",marginBottom:24,marginTop:24},children:a("span",{css:{color:x.label},children:["I agree to the Nebula"," ",e(Z,{to:"/terms",target:"_blank",theme:"nebulaBlue",children:"Terms of Service"})," ","and"," ",e(Z,{to:"/privacy",target:"_blank",theme:"nebulaBlue",children:"Privacy Policy"}),"."]})}),e(ce,{name:"optInToCommunications",onChange:()=>{k(s=>!s)},checked:B,css:{marginBottom:24},children:e("span",{css:{color:x.label,fontSize:"15px",lineHeight:"20px"},children:"Opt-in to Nebula communications. No spam, ever."})}),e(W,{disabled:!(n.length&&l.length&&m&&y)||w,type:"submit",size:"jumbo",css:{height:"56px",width:"100%",marginTop:"24px"},children:"Create account"})]})}function et(){const t=U(),i=_e(),[r]=Ee(),o=[...ae.plans(),{apiToken:r}],n=ze();return Ve(o,{condition:p=>!!(p!=null&&p.current_subscriptions.length),onFinish:async()=>{await i.invalidateQueries(Ae.user()),await i.invalidateQueries(ae.lifetimePlans()),await i.invalidateQueries(Le.authorization()),n?t.push(n):t.push("/")}}),a(K,{css:{paddingTop:190},children:[e("h2",{css:{marginBottom:32,textAlign:"center"},children:"Payment Successful"}),e("p",{css:{textAlign:"center"},children:"Thank you for supporting creators!"})]})}function ct(){const t=$e(),{currentSubscriptions:i,error:r,isInitialLoading:o}=X(),[n]=H("step",{defaultValue:"account",allowedValues:["account","subscription","payment","success"]}),[p]=H("product_id"),l=U(),g=(i==null?void 0:i.length)>0,m=t&&n!=="account"&&o||g&&n!=="success";return c.useEffect(()=>{if(!t)n!=="account"&&l.push({search:R(l.location.search,"step",void 0),state:l.location.state});else if(g&&n==="account"&&(p!=null&&p.includes("lifetime")))l.push("/settings/subscription");else if(g&&n!=="success")l.push("/");else{if(o)return;n==="subscription"?l.push({search:R(l.location.search,"step","payment")}):n!=="payment"&&n!=="success"&&l.push({search:R(l.location.search,"step","payment"),state:l.location.state})}},[l,t,g,o,p,n]),r&&n!=="account"?a(c.Fragment,{children:[e(F,{defer:!1,children:e("title",{children:"Error"})}),e(ee,{error:r})]}):e(Re,{children:m?null:n==="account"?e(Ye,{}):n==="payment"?e(Ge,{}):n==="success"?e(et,{}):null})}export{ct as default};