import{c as U,r as n,a as z,j as e,B as j,L as R}from"./index-DHiKqTn6.js";import{u as b}from"./en-US-BHI7lbCO.js";import{N as H,F as O}from"./Footer-DIHGzGNa.js";import{M as Y}from"./MobileBottomNav-BRRCjtR3.js";import{P as V}from"./PageHeader-CgT1RQpc.js";import{T as q,a as W,b as v,c as N}from"./tabs-BFxiwNXW.js";import{S as i}from"./skeleton-CikzIUyw.js";import{B as c}from"./badge-BmhJSggK.js";import{D as Z}from"./DemoModeBanner-BIMQJrAO.js";import{P as w}from"./pagination-controls-DubxzMMs.js";import{A as G}from"./arrow-left-Cl5wWEfz.js";import{F as u}from"./file-text-BGscRDPn.js";import{D as Q}from"./download-NFAFFg-C.js";import{C}from"./credit-card-CBlRgKpv.js";import{W as X}from"./wallet-B4dDbtdN.js";import{C as J}from"./circle-alert-CqGX50wv.js";import{C as K}from"./circle-x-CwZ0UNLv.js";import{C as ee}from"./clock-nMhDUsgy.js";import{C as te}from"./circle-check-big-Cng-7zZp.js";import{f as l}from"./format-BIQUK3y2.js";import"./check-DCv_Nj_2.js";import"./house-D_3Onipo.js";import"./sparkles-DVJTaxfx.js";import"./chevron-left-B2icCOsE.js";import"./differenceInCalendarDays-VRrrNlro.js";const M=U("Receipt",[["path",{d:"M4 2v20l2-1 2 1 2-1 2 1 2-1 2 1 2-1 2 1V2l-2 1-2-1-2 1-2-1-2 1-2-1-2 1Z",key:"q3az6g"}],["path",{d:"M16 8h-6a2 2 0 1 0 0 4h4a2 2 0 1 1 0 4H8",key:"1h4pet"}],["path",{d:"M12 17.5v-11",key:"1jc1ny"}]]),r=10,$e=()=>{const[d,I]=n.useState([]),[m,$]=n.useState([]),[k,P]=n.useState(!0),[T,_]=n.useState(!0),[p,D]=n.useState(1),[x,F]=n.useState(1),{toast:g}=z();n.useEffect(()=>{S(),A()},[]);const S=async()=>{try{const{data:t,error:s}=await b.getTransactions();if(s)throw s;I(t||[])}catch(t){console.error("Error fetching transactions:",t)}finally{P(!1)}},A=async()=>{try{const{data:t,error:s}=await b.getInvoices();if(s)throw s;$(t||[])}catch(t){console.error("Error fetching invoices:",t)}finally{_(!1)}},B=async t=>{try{const s=E(t),h=new Blob([s],{type:"text/html"}),a=URL.createObjectURL(h),o=document.createElement("a");o.href=a,o.download=`invoice-${t.invoice_number}.html`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(a),g({title:"Invoice Downloaded",description:`Invoice ${t.invoice_number} has been downloaded.`})}catch(s){console.error("Error downloading invoice:",s),g({title:"Download Failed",description:"Failed to download the invoice.",variant:"destructive"})}},E=t=>{const h=(t.items||[]).map(a=>`
      <tr>
        <td style="padding: 12px; border-bottom: 1px solid #e5e7eb;">${a.description}</td>
        <td style="padding: 12px; border-bottom: 1px solid #e5e7eb; text-align: center;">${a.quantity}</td>
        <td style="padding: 12px; border-bottom: 1px solid #e5e7eb; text-align: right;">$${a.unit_price.toFixed(2)}</td>
        <td style="padding: 12px; border-bottom: 1px solid #e5e7eb; text-align: right;">$${(a.quantity*a.unit_price).toFixed(2)}</td>
      </tr>
    `).join("");return`
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Invoice ${t.invoice_number}</title>
  <style>
    body { font-family: system-ui, -apple-system, sans-serif; margin: 40px; color: #1f2937; }
    h1 { color: #111827; }
    .header { display: flex; justify-content: space-between; margin-bottom: 40px; }
    .invoice-details { text-align: right; }
    table { width: 100%; border-collapse: collapse; margin: 20px 0; }
    th { background: #f3f4f6; padding: 12px; text-align: left; }
    .total { font-size: 24px; font-weight: bold; text-align: right; margin-top: 20px; }
    .status { display: inline-block; padding: 4px 12px; border-radius: 9999px; font-size: 14px; }
    .status-paid { background: #dcfce7; color: #166534; }
    .status-pending { background: #fef9c3; color: #854d0e; }
    .notes { margin-top: 40px; padding: 20px; background: #f9fafb; border-radius: 8px; }
  </style>
</head>
<body>
  <div class="header">
    <div>
      <h1>INVOICE</h1>
      <p><strong>AppForge</strong></p>
    </div>
    <div class="invoice-details">
      <p><strong>Invoice #:</strong> ${t.invoice_number}</p>
      <p><strong>Date:</strong> ${l(new Date(t.created_at),"MMMM d, yyyy")}</p>
      ${t.due_date?`<p><strong>Due Date:</strong> ${l(new Date(t.due_date),"MMMM d, yyyy")}</p>`:""}
      <p><span class="status ${t.status==="paid"?"status-paid":"status-pending"}">${t.status.toUpperCase()}</span></p>
    </div>
  </div>

  <table>
    <thead>
      <tr>
        <th>Description</th>
        <th style="text-align: center;">Qty</th>
        <th style="text-align: right;">Unit Price</th>
        <th style="text-align: right;">Amount</th>
      </tr>
    </thead>
    <tbody>
      ${h}
    </tbody>
  </table>

  <div class="total">
    Total: ${t.currency.toUpperCase()} $${t.amount.toFixed(2)}
  </div>

  ${t.notes?`<div class="notes"><strong>Notes:</strong><br>${t.notes}</div>`:""}

  <div style="margin-top: 60px; text-align: center; color: #6b7280; font-size: 14px;">
    <p>Thank you for your business!</p>
    <p>AppForge - Build Mobile Apps from Any Website</p>
  </div>
</body>
</html>
    `},f=t=>{switch(t){case"completed":case"paid":return e.jsxs(c,{variant:"default",className:"bg-accent/10 text-accent border-accent/20",children:[e.jsx(te,{className:"w-3 h-3 mr-1"}),t==="paid"?"Paid":"Completed"]});case"pending":case"sent":return e.jsxs(c,{variant:"secondary",children:[e.jsx(ee,{className:"w-3 h-3 mr-1"}),t==="sent"?"Sent":"Pending"]});case"failed":case"cancelled":return e.jsxs(c,{variant:"destructive",children:[e.jsx(K,{className:"w-3 h-3 mr-1"}),t==="cancelled"?"Cancelled":"Failed"]});case"overdue":return e.jsxs(c,{variant:"destructive",children:[e.jsx(J,{className:"w-3 h-3 mr-1"}),"Overdue"]});default:return e.jsx(c,{variant:"outline",children:t})}},L=t=>{switch(t){case"stripe":return e.jsx(C,{className:"w-4 h-4"});case"bank_transfer":return e.jsx(X,{className:"w-4 h-4"});default:return e.jsx(C,{className:"w-4 h-4"})}},y=()=>e.jsx("div",{className:"space-y-4",children:Array.from({length:5}).map((t,s)=>e.jsxs("div",{className:"glass-card rounded-xl p-4 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(i,{className:"w-10 h-10 rounded-lg"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(i,{className:"h-4 w-32"}),e.jsx(i,{className:"h-3 w-24"})]})]}),e.jsxs("div",{className:"text-right space-y-2",children:[e.jsx(i,{className:"h-5 w-20 ml-auto"}),e.jsx(i,{className:"h-4 w-16 ml-auto"})]})]},s))});return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(H,{}),e.jsx("main",{className:"pt-24 sm:pt-28 pb-24 md:pb-16",children:e.jsxs("div",{className:"container mx-auto px-4 sm:px-6",children:[e.jsx(Z,{}),e.jsx(V,{title:"Payment History",description:"View your transactions and download invoices",children:e.jsx(j,{variant:"outline",asChild:!0,children:e.jsxs(R,{to:"/subscription",children:[e.jsx(G,{className:"w-4 h-4 mr-2"}),"Back to Subscription"]})})}),e.jsxs(q,{defaultValue:"transactions",className:"mt-6",children:[e.jsxs(W,{className:"grid w-full max-w-md grid-cols-2",children:[e.jsxs(v,{value:"transactions",className:"gap-2",children:[e.jsx(M,{className:"w-4 h-4"}),"Transactions"]}),e.jsxs(v,{value:"invoices",className:"gap-2",children:[e.jsx(u,{className:"w-4 h-4"}),"Invoices"]})]}),e.jsxs(N,{value:"transactions",className:"mt-6",children:[k?e.jsx(y,{}):d.length===0?e.jsxs("div",{className:"glass-card rounded-2xl p-8 text-center",children:[e.jsx("div",{className:"w-16 h-16 rounded-xl bg-muted flex items-center justify-center mx-auto mb-4",children:e.jsx(M,{className:"w-8 h-8 text-muted-foreground"})}),e.jsx("h3",{className:"font-display text-lg font-semibold text-foreground mb-2",children:"No Transactions Yet"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Your payment history will appear here after your first purchase."})]}):e.jsx("div",{className:"space-y-3",children:d.slice((p-1)*r,p*r).map(t=>e.jsxs("div",{className:"glass-card rounded-xl p-4 flex items-center justify-between hover:border-primary/30 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-primary/10 flex items-center justify-center text-primary",children:L(t.payment_method)}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-foreground capitalize",children:t.transaction_type.replace(/_/g," ")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:l(new Date(t.created_at),"MMM d, yyyy 'at' h:mm a")})]})]}),e.jsxs("div",{className:"text-right",children:[e.jsxs("p",{className:"font-semibold text-foreground",children:[t.currency.toUpperCase()," $",t.amount.toFixed(2)]}),f(t.status)]})]},t.id))}),e.jsx(w,{currentPage:p,totalPages:Math.max(1,Math.ceil(d.length/r)),totalItems:d.length,pageSize:r,onPageChange:D})]}),e.jsxs(N,{value:"invoices",className:"mt-6",children:[T?e.jsx(y,{}):m.length===0?e.jsxs("div",{className:"glass-card rounded-2xl p-8 text-center",children:[e.jsx("div",{className:"w-16 h-16 rounded-xl bg-muted flex items-center justify-center mx-auto mb-4",children:e.jsx(u,{className:"w-8 h-8 text-muted-foreground"})}),e.jsx("h3",{className:"font-display text-lg font-semibold text-foreground mb-2",children:"No Invoices Yet"}),e.jsx("p",{className:"text-muted-foreground text-sm",children:"Your invoices will appear here after your first purchase."})]}):e.jsx("div",{className:"space-y-3",children:m.slice((x-1)*r,x*r).map(t=>e.jsxs("div",{className:"glass-card rounded-xl p-4 flex items-center justify-between hover:border-primary/30 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-accent/10 flex items-center justify-center text-accent",children:e.jsx(u,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsxs("p",{className:"font-medium text-foreground",children:["Invoice #",t.invoice_number]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[l(new Date(t.created_at),"MMM d, yyyy"),t.due_date&&e.jsxs("span",{children:[" · Due ",l(new Date(t.due_date),"MMM d, yyyy")]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"text-right",children:[e.jsxs("p",{className:"font-semibold text-foreground",children:[t.currency.toUpperCase()," $",t.amount.toFixed(2)]}),f(t.status)]}),e.jsx(j,{variant:"ghost",size:"icon",className:"shrink-0",onClick:()=>B(t),title:"Download Invoice",children:e.jsx(Q,{className:"w-4 h-4"})})]})]},t.id))}),e.jsx(w,{currentPage:x,totalPages:Math.max(1,Math.ceil(m.length/r)),totalItems:m.length,pageSize:r,onPageChange:F})]})]})]})}),e.jsx(O,{}),e.jsx(Y,{})]})};export{$e as default};
