1import{ak as y,d as k,a as b,a6 as R,t as w,b as g,Y as h,j as e,a0 as E,a1 as P,S as x,B as S}from"./index-COb3BWG8.js";import{C as A}from"./payment-integration-CVfa0zAo.js";import{G as N}from"./card-decline-messages-B_nbAiVJ.js";import{C as B}from"./circle-check-big-BANmrhMR.js";import{C as M}from"./circle-alert-CCGVUS_b.js";import{R as F}from"./refresh-cw-CoRVSjNV.js";import{u as I}from"./useMutation-BQY-xsoU.js";import"./useIsomorphicLayoutEffect-D8rpVvO2.js";const _=(t,n=N)=>{var c;return((c=t==null?void 0:t.paymentCharge)==null?void 0:c.customerFailureMessage)||n},q=()=>{const[t]=y(),n=k(),{locale:c}=b(),s=R.useCallback(m=>w(m,c),[c]),d=t.get("pid")??void 0,u=t.get("resourcePath")??void 0,[f]=I(A),j=g.useRef(!1),[l,i]=g.useState({kind:"loading"});g.useEffect(()=>{if(!d){i({kind:"error",message:s("Missing payment intent reference. Please try adding your payment method again.")});return}if(!u){i({kind:"error",message:s("Missing AFS resource path. The tokenisation did not complete.")});return}j.current||(j.current=!0,(async()=>{var m,p;try{const{data:r}=await f({variables:{input:{paymentIntentId:d,resourcePath:u}}}),a=r==null?void 0:r.confirmPayment,o=(m=a==null?void 0:a.paymentCharge)==null?void 0:m.status;if(a!=null&&a.success&&o==="SUCCEEDED"){i({kind:"success"}),h.success(s("Payment method added")),setTimeout(()=>n("/dashboard/billing"),1200);return}console.error("[AfsBillingReturnPage] save-card confirmation failed:",{paymentIntentStatus:(p=a==null?void 0:a.paymentIntent)==null?void 0:p.status,paymentChargeStatus:o});const C=_(a,s(N));i({kind:"error",message:C}),h.error(C)}catch(r){console.error("[AfsBillingReturnPage] confirmPayment failed:",r);const o=(r instanceof Error?r.message:void 0)||s("An unexpected error occurred while saving your card.");i({kind:"error",message:o}),h.error(o)}})())},[d,u,f,n,s]);const v=()=>{n("/dashboard/billing")};return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background px-4",children:e.jsx(E,{className:"w-full max-w-md",children:e.jsxs(P,{className:"p-10 text-center space-y-6",children:[l.kind==="loading"&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"sr-only",children:s("Loading...")}),e.jsx("div",{className:"flex justify-center",children:e.jsx(x,{className:"h-16 w-16 rounded-full"})}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x,{className:"h-5 w-48 mx-auto"}),e.jsx(x,{className:"h-4 w-64 mx-auto"})]})]}),l.kind==="success"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"rounded-full bg-green-100 p-5",children:e.jsx(B,{className:"h-12 w-12 text-green-600"})})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-xl font-semibold",children:s("Payment method added")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("Redirecting you back to Billing...")})]})]}),l.kind==="error"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"rounded-full bg-red-100 p-5",children:e.jsx(M,{className:"h-12 w-12 text-red-600"})})}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("h2",{className:"text-xl font-semibold",children:s("Could not save card")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:l.message})]}),e.jsxs(S,{onClick:v,className:"w-full",children:[e.jsx(F,{className:"h-4 w-4 mr-2"}),s("Back to Billing")]})]})]})})})};export{q as AfsBillingReturnPage,q as default,_ as resolveAfsSaveCardFailureMessage};
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.