1import{j as e}from"./data-DN-eP4ae.js";import{k as C,r,L as _}from"./react-BUOzgyp0.js";import{bA as P,F as R,B as c,a4 as D,cK as d,n as B}from"./index-6GUxm5Tl.js";import{C as N,a as w}from"./card-Bpoa90g8.js";import{u as S}from"./head-BBAUgEcO.js";import{f as z,r as y}from"./publicDocumentService-DieygP36.js";import{D as E}from"./download-D8rVLK2a.js";import"./documents-Bju1cS7G.js";import"./charts-BjVT6r80.js";function M(){var u,x,p,h,f,j,g,b;const{token:t}=C(),[s,v]=r.useState(null),[n,l]=r.useState("loading"),o=r.useCallback(async()=>{if(!t)return;l("loading");const i=await z(t);if(i.success===!1){l(i.error);return}v(i.data),l("ready")},[t]);r.useEffect(()=>{o()},[o]),S(s?{kind:"receipt",label:(u=s.receipt)!=null&&u.receipt_number?`Receipt ${s.receipt.receipt_number}`:"Payment Receipt",status:"Paid",orgName:((x=s.branding)==null?void 0:x.name)??null,imageUrl:((p=s.branding)==null?void 0:p.logo_url)??null,url:window.location.href.split("?")[0]}:null);const k=()=>{t&&(y(t,"receipt","receipt_downloaded"),window.print())};if(n==="loading")return e.jsx("main",{className:"flex min-h-screen items-center justify-center bg-muted/30",children:e.jsx(P,{className:"h-5 w-5 animate-spin text-muted-foreground"})});if(n!=="ready"||!s){const i=n==="expired"?"This receipt link has expired. Please ask the business for a new one.":n==="network"?"We could not load your receipt. Please check your connection and try again.":"We could not find this receipt.";return e.jsx("main",{className:"flex min-h-screen items-center justify-center bg-muted/30 p-6",children:e.jsx(N,{className:"max-w-md",children:e.jsxs(w,{className:"space-y-4 p-6 text-center",children:[e.jsx(R,{className:"mx-auto h-8 w-8 text-muted-foreground"}),e.jsx("h1",{className:"text-lg font-semibold",children:"Receipt unavailable"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:i}),e.jsx(c,{variant:"outline",size:"sm",onClick:o,children:"Try again"})]})})})}const a=s.receipt,m=Number(a.balance_after??0);return e.jsx("main",{className:"min-h-screen bg-muted/30 px-4 py-10",children:e.jsxs("div",{className:"mx-auto max-w-lg space-y-4",children:[e.jsxs("header",{className:"flex items-center gap-3",children:[(h=s.branding)!=null&&h.logo_url?e.jsx("img",{src:s.branding.logo_url,alt:`${((f=s.branding)==null?void 0:f.name)??"Business"} logo`,className:"h-10 w-10 rounded-md object-cover"}):e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-md bg-primary/10 text-sm font-semibold text-primary",children:(((j=s.branding)==null?void 0:j.name)??"B").slice(0,1).toUpperCase()}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",children:((g=s.branding)==null?void 0:g.name)??"Receipt"}),((b=s.branding)==null?void 0:b.address)&&e.jsx("p",{className:"text-xs text-muted-foreground",children:s.branding.address})]})]}),e.jsx(N,{children:e.jsxs(w,{className:"space-y-5 p-6",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(D,{className:"mt-0.5 h-5 w-5 text-primary"}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-semibold",children:"Payment received"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Receipt ",a.receipt_number,s.invoice.invoice_number?` for invoice ${s.invoice.invoice_number}`:""]})]})]}),e.jsxs("dl",{className:"space-y-2 text-sm",children:[e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Amount paid"}),e.jsx("dd",{className:"font-semibold",children:d(Number(a.amount??0))})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Paid on"}),e.jsx("dd",{children:new Date(a.paid_at).toLocaleDateString()})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Invoice total"}),e.jsx("dd",{children:d(Number(a.invoice_total??0))})]}),e.jsxs("div",{className:"flex justify-between",children:[e.jsx("dt",{className:"text-muted-foreground",children:"Balance remaining"}),e.jsx("dd",{className:m>0?"font-semibold":"",children:d(m)})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.allow_download&&e.jsxs(c,{size:"sm",onClick:k,children:[e.jsx(E,{className:"mr-2 h-4 w-4"}),"Download receipt"]}),s.invoice.public_token&&e.jsx(c,{asChild:!0,size:"sm",variant:"outline",children:e.jsx(_,{to:`/i/${s.invoice.public_token}`,onClick:()=>t&&y(t,"receipt","link_clicked",{to:"invoice"}),children:"View invoice"})}),e.jsx(c,{size:"sm",variant:"ghost",onClick:()=>B.info("Contact the business",{description:"Reply to the message that sent you this receipt and we will help."}),children:"Contact support"})]})]})}),e.jsx("p",{className:"text-center text-xs text-muted-foreground",children:"Keep this link - it is your proof of payment."})]})})}export{M 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.