1import{r as a,u as D,j as e}from"./vendor-query-CnAhr2B8.js";import{a0 as A,u as k,h,p as j,q as p,r as v,aT as y,aU as w,B as d,ax as g,aV as E,s as b,aa as C,ay as P,aP as B,aE as T,o as L,aW as q,aF as F,a as J}from"./index-CLUtDhnY.js";import{E as R,l as Y,u as _,a as M,P as O}from"./react-stripe.esm-CcBtmaMG.js";import{a as U}from"./api-c_Wfq480.js";import"./vendor-ui-CYA7SV0W.js";import"./vendor-charts-CPMWc2oJ.js";import"./vendor-forms-UY-il7MQ.js";const V=Y("pk_live_51R9ziJGsu75nju9Zcqg6IaljY0IBVihcgJUOeeQ6tPnnN5LUbs8zchiPUAV5Yr0wJT1scdJEkE2ehXg46RTBvAZJ00F0MIPDxc");function z({invoice:f,onSuccess:n}){const r=_(),c=M(),[m,u]=a.useState(!1),[x,l]=a.useState(null),{toast:o}=J(),s=async N=>{if(N.preventDefault(),!(!r||!c)){u(!0),l(null);try{const{error:i}=await r.confirmPayment({elements:c,confirmParams:{return_url:window.location.origin+"/invoices"},redirect:"if_required"});i?(l(i.message||"An error occurred"),o({title:"Payment error",description:i.message||"Failed to process payment",variant:"destructive"})):(o({title:"Payment successful",description:"Your payment has been processed",variant:"default"}),n())}catch(i){l(i.message||"An error occurred"),o({title:"Payment error",description:i.message||"An unexpected error occurred",variant:"destructive"})}finally{u(!1)}}};return e.jsx("form",{onSubmit:s,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(O,{}),x&&e.jsx("div",{className:"p-3 bg-red-50 text-red-700 rounded-md text-sm",children:x}),e.jsx(d,{type:"submit",disabled:!r||m,className:"w-full",children:m?"Processing...":`Pay ${C(f.total)}`})]})})}function X(){var S,I;const f=A(),{invoiceId:n}=f,[,r]=k(),[c,m]=a.useState(null),[u,x]=a.useState("idle"),[l,o]=a.useState(!1),{data:s,isLoading:N}=D({queryKey:[`/api/invoices/${n}`],enabled:!!n});a.useEffect(()=>{s&&n&&U("POST","/api/create-payment-intent",{amount:s.total,invoiceId:parseInt(n)}).then(t=>{if((t==null?void 0:t.code)==="PAYMENT_BLOCKED"){o(!0);return}t!=null&&t.clientSecret&&m(t.clientSecret)}).catch(t=>{console.error("Error creating payment intent:",t)})},[s,n]);const i=()=>{x("success")};return N?e.jsx(h,{title:"Invoice Payment",children:e.jsx("div",{className:"flex justify-center items-center h-64",children:e.jsx("div",{className:"animate-spin w-10 h-10 border-4 border-primary rounded-full border-t-transparent"})})}):s?u==="success"?e.jsx(h,{title:"Payment Complete",children:e.jsxs(j,{children:[e.jsxs(p,{children:[e.jsxs(v,{className:"flex items-center text-green-600",children:[e.jsx(E,{className:"mr-2 h-5 w-5"}),"Payment Successful"]}),e.jsxs(y,{children:["Your payment for invoice #",s.invoiceNumber," has been processed."]})]}),e.jsx(b,{children:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("p",{children:[e.jsx("strong",{children:"Amount:"})," ",C(s.total)]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Invoice Number:"})," ",s.invoiceNumber]}),e.jsxs("p",{children:[e.jsx("strong",{children:"Payment Date:"})," ",P(new Date)]})]})}),e.jsx(w,{children:e.jsxs(d,{onClick:()=>r("/invoices"),children:[e.jsx(g,{className:"mr-2 h-4 w-4"}),"Back to Invoices"]})})]})}):e.jsxs(h,{title:"Payment Details",children:[e.jsxs(d,{variant:"ghost",className:"mb-4",onClick:()=>r("/invoices"),children:[e.jsx(g,{className:"mr-2 h-4 w-4"}),"Back to Invoices"]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs(j,{children:[e.jsxs(p,{children:[e.jsx(v,{children:"Invoice Summary"}),e.jsx(y,{children:"Review your invoice details"})]}),e.jsx(b,{children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-500",children:"Invoice Number"}),e.jsx("div",{className:"font-medium",children:s.invoiceNumber})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-500",children:"Customer"}),e.jsxs("div",{className:"font-medium",children:[(S=s.customer)==null?void 0:S.firstName," ",(I=s.customer)==null?void 0:I.lastName]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-500",children:"Issue Date"}),e.jsx("div",{className:"font-medium",children:P(s.createdAt)})]}),s.dueDate&&e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-500",children:"Due Date"}),e.jsx("div",{className:"font-medium",children:P(s.dueDate)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm text-gray-500",children:"Amount Due"}),e.jsx("div",{className:"text-xl font-bold text-primary",children:C(s.total)})]})]})})]}),e.jsxs(j,{children:[e.jsxs(p,{children:[e.jsxs(v,{className:"flex items-center",children:[e.jsx(B,{className:"mr-2 h-5 w-5"}),"Payment Details"]}
1),e.jsx(y,{children:"Complete your payment securely"})]}),e.jsx(b,{children:l?e.jsxs(T,{className:"border-amber-200 bg-amber-50",children:[e.jsx(L,{className:"h-4 w-4 text-amber-600"}),e.jsx(q,{className:"text-amber-800",children:"Online Payments Not Available"}),e.jsxs(F,{className:"text-amber-700",children:["To accept online payments, connect your Stripe account in"," ",e.jsx(d,{variant:"link",className:"h-auto p-0 text-amber-800 underline",onClick:()=>r("/settings?tab=integrations"),children:"Settings â Integrations â Payments"}),"."]})]}):c?e.jsx(R,{stripe:V,options:{clientSecret:c},children:e.jsx(z,{invoice:s,onSuccess:i})}):e.jsx("div",{className:"flex justify-center py-4",children:e.jsx("div",{className:"animate-spin w-8 h-8 border-4 border-primary rounded-full border-t-transparent"})})})]})]})]}):e.jsx(h,{title:"Invoice Payment",children:e.jsxs(j,{children:[e.jsxs(p,{children:[e.jsx(v,{children:"Invoice Not Found"}),e.jsx(y,{children:"The requested invoice could not be found."})]}),e.jsx(w,{children:e.jsxs(d,{onClick:()=>r("/invoices"),children:[e.jsx(g,{className:"mr-2 h-4 w-4"}),"Back to Invoices"]})})]})})}export{X 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.