1import{j as e}from"./vendor-query-CniT1WJL.js";import{u as g,r as o}from"./vendor-react-69GsFwrV.js";import{u as w,F as C,G as y,V as b,eB as N,eC as E,w as x,eD as S,eE as k,eF as P,m as v}from"./index-KjAD5lCC.js";import{A}from"./AccountNav-CGK2802V.js";import{g as F,a4 as D,ax as L}from"./vendor-ui-Ad3ANzF6.js";import"./vendor-forms-q6h4WU-p.js";function T({onSaved:f}){const s=S(),a=k(),{toast:d}=v(),[i,c]=o.useState(!1),l=async p=>{if(p.preventDefault(),!s||!a)return;c(!0);const{error:h,setupIntent:n}=await s.confirmSetup({elements:a,confirmParams:{return_url:window.location.href},redirect:"if_required"});if(h){c(!1),d({title:h.message??"Payment setup failed",variant:"destructive"});return}if(n?.status==="succeeded"&&n.payment_method){const m=typeof n.payment_method=="string"?n.payment_method:n.payment_method.id;try{if(!(await x("/api/hub/save-payment-method",{method:"POST",headers:{"content-type":"application/json"},credentials:"include",body:JSON.stringify({paymentMethodId:m})})).ok)throw new Error("Save failed");d({title:"Payment saved"}),f()}catch(u){d({title:u instanceof Error?u.message:"Could not save payment",variant:"destructive"})}}c(!1)};return e.jsxs("form",{onSubmit:l,className:"space-y-4",children:[e.jsx(P,{options:{layout:{type:"tabs",defaultCollapsed:!1}}}),e.jsx(b,{type:"submit",block:!0,disabled:!s||i,children:i?"Saving...":"Save secure payment"}),e.jsx("p",{className:"text-center text-xs leading-relaxed text-ink-3",children:"Card and Link can be saved. Apple Pay, Google Pay, Klarna, Afterpay, and Affirm are approved per payment when you top up."})]})}function O(){const{user:f,isAuthenticated:s}=w(),{toast:a}=v(),[,d]=g(),[i,c]=o.useState(null),[l,p]=o.useState(null),[h,n]=o.useState(!0),m=async()=>{try{const t=await x("/api/hub/saved-cards",{credentials:"include"});if(!t.ok)throw new Error("Failed to load cards");const r=await t.json();c(r.cards)}catch(t){a({title:t instanceof Error?t.message:"Could not load cards",variant:"destructive"})}},u=async()=>{try{const t=await x("/api/hub/setup-intent",{method:"POST",credentials:"include"});if(!t.ok)throw new Error("Failed to start card setup");const r=await t.json();p(r)}catch(t){a({title:t instanceof Error?t.message:"Could not start card setup",variant:"destructive"})}},j=async t=>{try{if(!(await x(`/api/hub/saved-cards/${t}`,{method:"DELETE",credentials:"include"})).ok)throw new Error("Delete failed");a({title:"Card removed"}),await m()}catch(r){a({title:r instanceof Error?r.message:"Could not remove card",variant:"destructive"})}};return o.useEffect(()=>{if(!s){d("/login");return}m().finally(()=>n(!1))},[s]),o.useEffect(()=>{const t=document.createElement("meta");return t.name="robots",t.content="noindex, nofollow",document.head.appendChild(t),()=>{document.head.removeChild(t)}},[]),!s||!f?null:e.jsxs(e.Fragment,{children:[e.jsx(A,{}),e.jsxs(C,{width:"narrow",className:"mx-auto max-w-md space-y-5 py-6 sm:py-10",children:[e.jsxs("header",{className:"text-center",children:[e.jsx("h1",{className:"font-display text-t1 text-ink",children:"Payment methods"}),e.jsx("p",{className:"mt-1 text-sm text-ink-2 sm:text-base",children:"Saved payments live on the secure VidaTools hub and power faster checkout, subscriptions, and automatic VidaCredit top-ups across the Vida ecosystem."})]}),e.jsxs(y,{children:[e.jsx("h2",{className:"mb-3 text-sm font-semibold text-ink",children:"Saved payments"}),h?e.jsx("div",{className:"flex justify-center py-6",children:e.jsx(F,{className:"size-6 animate-spin text-primary"})}):i&&i.length>0?e.jsx("ul",{className:"space-y-2",children:i.map(t=>e.jsxs("li",{className:"flex items-center justify-between rounded-card border border-card-border bg-card px-3 py-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(D,{className:"size-5 text-ink-3","aria-hidden":"true"}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-medium text-ink",children:[t.brand?t.brand[0].toUpperCase()+t.brand.slice(1):"Card"," ","â¢â¢â¢â¢ ",t.last4??"****"]}),e.jsxs("p",{className:"text-xs text-ink-3",children:["Expires ",t.expMonth??"--","/",t.expYear??"----",t.isDefault?" ⢠Default":""]})]})]}),e.jsx("button",{type:"button",onClick:()=>j(t.id),className:"rounded p-2 text-ink-3 hover:bg-danger/10 hover:text-danger","aria-label":"Remove saved payment",children:e.jsx(L,{className:"size-4"})})]},t.id))}):e.jsx("p",{className:"py-4 text-center text-sm text-ink-3",children:"No saved payments yet."})]}),l?e.jsxs(y,{children:[e.jsx("h2",{className:"mb-3 text-sm font-semibold text-ink",children:"Add a secure payment"}),e.jsx(N,{stripe:E(l.publishableKey),options:{clientSecret:l.clientSecret},children:e.jsx(T,{onSaved:()=>{p(null),m()}})})]}):e.jsx(b,{block:!0,onClick:u,children:"Add a secure payment"})]})]})}export{O 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.