1import{eC as L,aR as E,m as g,bq as O,eD as I,eE as T,eF as F,d as u,bs as i,j as e,p as N,L as M,T as A,ai as m,bS as B,dm as R}from"./index-70yz1Rcc.js";import{A as G}from"./arrow-left-D1Uc4TKp.js";const U="rt_paypal_upgrade_plan";function p(a){return`$${(a/100).toFixed(2)}`}function w(a){if(!a)return null;const d=new Date(a);return Number.isNaN(d.getTime())?null:d.toLocaleDateString("en-GB",{day:"numeric",month:"long",year:"numeric"})}function K(){const{plan:a}=L.useSearch(),d=E(),k=g(O),P=g(I),S=g(T),C=g(F),[r,h]=u.useState(null),[Y,$]=u.useState(!0),[o,f]=u.useState(null),[b,y]=u.useState(!1),[c,_]=u.useState(!1);u.useEffect(()=>{let n=!1;return i("upgrade_confirmation_opened",{plan_id:a??null,surface:"page",at:new Date().toISOString()}),k({data:void 0}).then(s=>{if(n)return;h(s);const l=s?.options.find(x=>x.id===a);l&&s.provider==="stripe"&&(y(!0),P({data:{plan_id:l.id}}).then(x=>{n||f(x?.amount_cents??null)}).catch(()=>{n||f(null)}).finally(()=>{n||y(!1)}))}).catch(()=>h(null)).finally(()=>{n||$(!1)}),()=>{n=!0}},[]);const t=r?.options.find(n=>n.id===a)??null;
1function j(n){i("upgrade_confirmation_cancelled",{plan_id:a??null,surface:"page",via:n,at:new Date().toISOString()}),d({to:"/billing"})}async function D(){if(!(!r||!t||c)){_(!0),i("upgrade_payment_confirmed",{plan_id:t.id,provider:r.provider,amount_today_cents:o,surface:"page",at:new Date().toISOString()});try{if(r.provider==="stripe"){const l=await S({data:{plan_id:t.id}});l.ok?(i("upgrade_payment_successful",{plan_id:t.id,provider:"stripe"}),m.success("Your membership has been changed",{description:l.current_period_end?`Your previous plan has stopped. Your next renewal is ${w(l.current_period_end)}.`:"Your previous plan has stopped.",duration:9e3}),d({to:"/billing"})):(i("upgrade_payment_failed",{plan_id:t.id,provider:"stripe"}),m.error("Plan change not completed",{description:l.message,duration:9e3}));return}const n=B(),s=await C({data:{plan_id:t.id,return_url:`${n}/billing?upgrade=paypal`,cancel_url:`${n}/billing?upgrade=cancelled`}});if(!s.ok){i("upgrade_payment_failed",{plan_id:t.id,provider:"paypal"}),m.error("Plan change not completed",{description:s.message,duration:9e3});return}if(s.approve_url){window.sessionStorage.setItem(U,t.id),window.location.href=s.approve_url;return}i("upgrade_payment_successful",{plan_id:t.id,provider:"paypal"}),m.success("Your membership has been changed",{description:"Your previous plan has stopped.",duration:9e3}),d({to:"/billing"})}catch(n){i("upgrade_payment_failed",{plan_id:t?.id??null,error:!0}),m.error("Plan change not completed",{description:R(n)})}finally{_(!1)}}}if(Y)return e.jsx("div",{className:"mx-auto flex min-h-[60vh] max-w-2xl items-center justify-center px-4",children:e.jsx(N,{className:"h-6 w-6 animate-spin text-muted-foreground"})});if(!r||!t)return e.jsx("div",{className:"mx-auto max-w-2xl px-4 py-16",children:e.jsxs("div",{className:"rounded-3xl border border-border bg-card p-8 text-center",children:[e.jsx("h1",{className:"font-serif text-2xl text-foreground",children:"We couldn't find that plan change"}),e.jsx("p",{className:"mt-3 text-sm text-muted-foreground",children:"Nothing has been changed and nothing has been charged. You can go back to your membership and choose again."}),e.jsx(M,{to:"/billing",className:"btn-gold mt-6 inline-flex items-center gap-2 text-sm",children:"Back to your membership"})]})});const v=w(r.next_renewal);return e.jsxs("div",{className:"mx-auto max-w-2xl px-4 py-10 md:py-16",children:[e.jsxs("button",{type:"button",onClick:()=>j("back_link"),className:"mb-5 inline-flex min-h-[44px] items-center gap-2 text-sm text-muted-foreground underline",children:[e.jsx(G,{className:"h-4 w-4"})," Back to your membership"]}),e.jsxs("div",{className:"rounded-3xl border border-gold/40 bg-card p-6 shadow-sm md:p-8",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(A,{className:"mt-0.5 h-6 w-6 text-[var(--gold-deep)]",strokeWidth:1.5}),e.jsxs("div",{children:[e.jsx("h1",{className:"font-serif text-2xl text-foreground md:text-3xl",children:"Confirm your plan change"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Nothing has been changed or charged yet. Please read this page, then confirm only if it's what you want."})]})]}),e.jsxs("div",{className:"mt-6 space-y-3 rounded-2xl border border-border bg-muted/20 p-4 text-sm",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground",children:"You are changing from"}),e.jsxs("p",{className:"text-foreground",children:[e.jsx("strong",{children:r.current_plan_label}),r.current_plan_price_cents!=null?` â ${p(r.current_plan_price_cents)}${r.current_plan_billing_note?` (${r.current_plan_billing_note})`:""}`:""]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-muted-foreground",children:"To"}),e.jsxs("p",{className:"text-foreground",children:[e.jsx("strong",{children:t.name})," â ",p(t.price_cents),t.billing_note?` (${t.billing_note})`:""]})]}),v?e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Your current renewal date is ",v,"."]}):null]}),e.jsx("div",{className:"mt-4 rounded-2xl border border-gold/40 bg-muted/10 p-4 text-sm",children:r.provider==="stripe"?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-foreground",children:[e.jsx("strong",{children:"Amount charged today: "}),b?e.jsx("span",{className:"text-muted-foreground",children:"working it outâ¦"}):o!=null?p(o):e.jsxs("span",{className:"text-muted-foreground",children:[p(t.price_cents),", less any unused time left on your current plan"]})]}),o!=null&&o<t.price_cents?e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"This is lower than the full price because the unused time on your current plan has been credited."}):null,e.jsx("p",{className:"mt-2 text-muted-foreground",children:"Your saved card is only charged when you press Confirm below."})]}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-foreground",children:[e.jsx("strong",{children:"Amount PayPal will take: "}),p(t.price_cents)," ",t.billing_note?`(${t.billing_note})`:""]}),e.jsx("p",{className:"mt-2 text-muted-foreground",children:"You'll be taken to PayPal to approve this change. Nothing is taken from your PayPal account until you approve it there."})]})}),e.jsxs("p",{className:"mt-4 text-sm text-muted-foreground",children:["Your ",r.current_plan_label," plan stops billing once this goes through. Your journal, reflections and everything else in your account stay exactly as they are. If you go back, nothing changes."]}),e.jsxs("div",{className:"mt-6 flex flex-col gap-3 sm:flex-row-reverse sm:items-center",children:[e.jsxs("button",{type:"button",onClick:()=>{D()},disabled:c||b,className:"btn-gold inline-flex min-h-[52px] w-full items-center justify-center gap-2 text-sm disabled:opacity-60 sm:w-auto",children:[c?e.jsx(N,{className:"h-4 w-4 animate-spin"}):null,r.provider==="stripe"?c?"Processingâ¦":`Confirm & Pay${o!=null?` ${p(o)}`:""}`:c?"Opening PayPalâ¦":"Continue to PayPal"]}),e.jsx("button",{type:"button",onClick:()=>
1j("go_back"),disabled:c,className:"inline-flex min-h-[52px] w-full items-center justify-center rounded-xl border border-border bg-background px-5 text-sm font-medium text-foreground transition hover:bg-muted/40 disabled:opacity-60 sm:w-auto",children:"Go back, don't change anything"})]})]})]})}export{K as component}; 2//# sourceMappingURL=plan-change-CWP9W8oc.js.map
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.