1import{j as e,r as s,z as y,l as j,L as h}from"./index-DeT698OI.js";import{E as N,a as w,P as k}from"./PaymentTestModeBanner-5eDZ3qfa.js";import{g as v,a as g}from"./stripe-DS9DA3Xp.js";import{a as S,b as C}from"./payments.functions-CGooSsRs.js";import{u as E}from"./useSubscription-DalWBFiF.js";function _({priceId:n,quantity:r,customerEmail:a,userId:i,returnUrl:c}){const l=async()=>{const o=await S({data:{priceId:n,quantity:r,customerEmail:a,userId:i,returnUrl:c||window.location.href,environment:g()}});if("error"in o)throw new Error(o.error);if(!o.clientSecret)throw new Error("Stripe did not return a client secret");return o.clientSecret};return e.jsx("div",{id:"checkout",children:e.jsx(N,{stripe:v(),options:{fetchClientSecret:l},children:e.jsx(w,{})})})}const P=[{id:"membership_monthly",label:"Monthly",price:"$6",cadence:"/ month",blurb:"Cancel anytime. Access continues until the end of the paid period."},{id:"membership_yearly",label:"Yearly",price:"$60",cadence:"/ year",blurb:"Two months free. Best for regular readers of the archive."}];function A(){const{userId:n,subscription:r,isMember:a,loading:i}=E(),[c,l]=s.useState(null),[o,d]=s.useState(null),[m,u]=s.useState(!1),[p,x]=s.useState(null),b=y(C);s.useEffect(()=>{j.auth.getUser().then(({data:t})=>l(t.user?.email??null))},[n]);const f=async()=>{x(null),u(!0);try{const t=await b({data:{returnUrl:`${window.location.origin}/membership`,environment:g()}});if("error"in t)throw new Error(t.error);window.open(t.url,"_blank","noopener,noreferrer")}catch(t){x(t?.message??"Could not open billing portal")}finally{u(!1)}};return e.jsxs(e.Fragment,{children:[e.jsx(k,{}),e.jsxs("main",{className:"mx-auto max-w-4xl px-4 py-16 md:px-8",children:[e.jsx("div",{className:"font-mono text-[11px] uppercase tracking-[0.22em] text-gold",children:"Membership"}),e.jsx("h1",{className:"mt-3 font-display text-4xl md:text-5xl",children:"Back the archive. Read everything."}),e.jsx("p",{className:"mt-5 max-w-2xl text-base text-muted-foreground",children:"Free dispatches keep going out to everyone. Membership unlocks the full long-form archive, supports the writing, and gets you every new story the moment it lands."}),i?e.jsx("div",{className:"mt-12 font-mono text-sm text-muted-foreground",children:"Loadingâ¦"}):a&&r?e.jsxs("section",{className:"mt-12 border border-border bg-card p-8",children:[e.jsx("div",{className:"font-mono text-[11px] uppercase tracking-[0.22em] text-gold",children:"Active member"}),e.jsx("h2",{className:"mt-2 font-display text-2xl",children:"You're in. Thank you."}),e.jsx("p",{className:"mt-3 text-sm text-muted-foreground",children:r.cancel_at_period_end?`Access continues until ${r.current_period_end?new Date(r.current_period_end).toLocaleDateString():"the end of the period"}.`:`Next renewal: ${r.current_period_end?new Date(r.current_period_end).toLocaleDateString():"â"}.`}),e.jsx("button",{type:"button",onClick:f,disabled:m,className:"mt-6 border border-gold bg-gold px-5 py-3 font-mono text-[11px] uppercase tracking-[0.22em] text-primary-foreground disabled:opacity-50",children:m?"Openingâ¦":"Manage billing"}),p?e.jsx("div",{className:"mt-3 font-mono text-[11px] uppercase tracking-[0.18em] text-destructive",children:p}):null]}):n?o?e.jsxs("section",{className:"mt-12",children:[e.jsx("button",{type:"button",onClick:()=>d(null),className:"mb-4 font-mono text-[11px] uppercase tracking-[0.22em] text-muted-foreground hover:text-foreground",children:"â Choose a different plan"}),e.jsx(_,{priceId:o,userId:n,customerEmail:c??void 0,returnUrl:`${window.location.origin}/checkout/return?session_id={CHECKOUT_SESSION_ID}`})]}):e.jsx("section",{className:"mt-12 grid gap-6 md:grid-cols-2",children:P.map(t=>e.jsxs("button",{type:"button",onClick:()=>d(t.id),className:"border border-border bg-card p-8 text-left transition hover:border-gold",children:[e.jsx("div",{className:"font-mono text-[11px] uppercase tracking-[0.22em] text-gold",children:t.label}),e.jsxs("div",{className:"mt-3 font-display text-4xl",children:[t.price,e.jsx("span",{className:"ml-1 text-base text-muted-foreground",children:t.cadence})]}),e.jsx("p",{className:"mt-4 text-sm text-muted-foreground",children:t.blurb}),e.jsxs("div",{className:"mt-6 font-mono text-[11px] uppercase tracking-[0.22em] text-foreground",children:["Choose ",t.label.toLowerCase()," â"]})]},t.id))}):e.jsxs("section",{className:"mt-12 border border-border bg-card p-8",children:[e.jsx("h2",{className:"font-display text-2xl",children:"Sign in to become a member"}),e.jsx("p",{className:"mt-3 text-sm text-muted-foreground",children:"Members get account-linked access. Create a free account or sign in to continue."}),e.jsxs("div",{className:"mt-6 flex gap-3",children:[e.jsx(h,{to:"/signup",className:"border border-gold bg-gold px-5 py-3 font-mono text-[11px] uppercase tracking-[0.22em] text-primary-foreground",children:"Create account"}),e.jsx(h,{to:"/login",search:{redirect:"/membership"},className:"border border-foreground px-5 py-3 font-mono text-[11px] uppercase tracking-[0.22em] text-foreground",children:"Sign in"})]})]}),e.jsx("p",{className:"mt-12 max-w-2xl text-xs text-muted-foreground",children:"Payments are processed by Stripe. You can cancel any time from your billing portal; access continues until the end of the paid period."})]})]})}export{A as component};
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.