import{r as d,j as e,F as w,L as m,aW as b,aP as f,l as g,D as y}from"./vendor-DyCecx-5.js";import{i as h}from"./invoice.service-ClW3ZJjb.js";import{t as r}from"./index-DJXN7D4i.js";const D=()=>{const[o,p]=d.useState([]),[u,c]=d.useState(!0),[n,i]=d.useState(null);d.useEffect(()=>{(async()=>{c(!0);const a=await h.getCustomerInvoices();a.success?p(a.data||[]):r.error("Failed to load invoices"),c(!1)})()},[]);const N=async(s,a)=>{var x;i(s);const l=await h.downloadInvoice(s);if(l.success&&((x=l.data)!=null&&x.downloadUrl)){const t=document.createElement("a");t.href=l.data.downloadUrl,t.download=`Invoice-${a}.pdf`,document.body.appendChild(t),t.click(),document.body.removeChild(t),r.success("Download started")}else r.error(l.message||"Failed to download invoice");i(null)},j=s=>new Intl.NumberFormat("en-IN",{style:"currency",currency:"INR"}).format(s);return e.jsx("div",{className:"min-h-screen bg-slate-50/50 p-6 md:p-10",children:e.jsxs("div",{className:"max-w-5xl mx-auto",children:[e.jsxs("header",{className:"mb-8 flex items-center gap-3",children:[e.jsx("div",{className:"p-3 bg-slate-900 rounded shadow-lg shadow-slate-200",children:e.jsx(w,{className:"w-6 h-6 text-white"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-black text-slate-900 tracking-tight",children:"My Invoices"}),e.jsx("p",{className:"text-slate-500 font-medium",children:"Access and download your payment history."})]})]}),u?e.jsx("div",{className:"flex justify-center py-20",children:e.jsx(m,{className:"w-10 h-10 text-slate-300 animate-spin"})}):!Array.isArray(o)||o.length===0?e.jsxs("div",{className:"text-center py-20 bg-white rounded border border-slate-100 shadow-sm",children:[e.jsx(b,{className:"w-16 h-16 text-slate-200 mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-bold text-slate-900",children:"No invoices found"}),e.jsx("p",{className:"text-slate-400",children:"You don't have any invoices yet."})]}):e.jsx("div",{className:"bg-white rounded shadow-sm border border-slate-200 overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-left border-collapse",children:[e.jsx("thead",{className:"bg-slate-50/50 border-b border-slate-200",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-6 py-4 text-xs font-bold text-slate-500 uppercase tracking-wider",children:"Invoice ID"}),e.jsx("th",{className:"px-6 py-4 text-xs font-bold text-slate-500 uppercase tracking-wider",children:"Booking ID"}),e.jsx("th",{className:"px-6 py-4 text-xs font-bold text-slate-500 uppercase tracking-wider",children:"Date"}),e.jsx("th",{className:"px-6 py-4 text-xs font-bold text-slate-500 uppercase tracking-wider",children:"Amount"}),e.jsx("th",{className:"px-6 py-4 text-xs font-bold text-slate-500 uppercase tracking-wider text-right",children:"Action"})]})}),e.jsx("tbody",{className:"divide-y divide-slate-100",children:o.map(s=>e.jsxs("tr",{className:"hover:bg-slate-50/50 transition-colors",children:[e.jsx("td",{className:"px-6 py-4",children:e.jsx("div",{className:"font-bold text-slate-900",children:s.invoiceNo})}),e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"flex items-center gap-1.5 text-sm font-medium text-slate-600",children:[e.jsx(f,{className:"w-3.5 h-3.5 text-slate-300"}),s.bookingId]})}),e.jsx("td",{className:"px-6 py-4",children:e.jsxs("div",{className:"flex items-center gap-2 text-sm text-slate-500",children:[e.jsx(g,{className:"w-3.5 h-3.5 text-slate-300"}),new Date(s.createdAt).toLocaleDateString()]})}),e.jsx("td",{className:"px-6 py-4",children:e.jsx("div",{className:"text-sm font-black text-slate-900",children:j(s.amount)})}),e.jsx("td",{className:"px-6 py-4 text-right",children:e.jsxs("button",{onClick:()=>N(s.id,s.invoiceNo),disabled:n===s.id,className:"inline-flex items-center gap-2 px-4 py-2 bg-slate-50 text-slate-600 rounded text-xs font-bold border border-slate-200 hover:bg-slate-900 hover:text-white hover:bg-slate-900 hover:-translate-y-0.5 transition-all shadow-sm disabled-50 disabled-not-allowed",children:[n===s.id?e.jsx(m,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(y,{className:"w-3.5 h-3.5"}),n===s.id?"Downloading...":"Download"]})})]},s.id))})]})})})]})})};export{D as default};
