import{u as l,a as m,r as u,j as e,B as x,A as g,C as h,b as v,c as p,d as j}from"./index-Cc987VYg.js";import{P as _}from"./page-header-CrLb0v5J.js";import{u as f}from"./use-aging-U7aee-6E.js";import{I as b}from"./input-DPNG9e3H.js";import{L as N,a as y}from"./label-npsA0UlW.js";import{D}from"./data-table-DE8WuOG4.js";import{f as n,a as i}from"./format-xRPgypNS.js";import"./command-G4m7hi6O.js";import"./separator-D14BnWPe.js";const C=[{accessorKey:"invoice_number",header:"Invoice Number"},{accessorKey:"invoice_date",header:"Invoice Date",cell:({row:a})=>i(a.original.invoice_date)},{accessorKey:"due_date",header:"Due Date",cell:({row:a})=>i(a.original.due_date)},{accessorKey:"days_outstanding",header:"Days Outstanding",cell:({row:a})=>{const s=a.original.days_outstanding;return e.jsx("span",{className:s>90?"text-red-600 font-semibold":"",children:s})}},{accessorKey:"aging_bucket",header:"Aging Bucket",cell:({row:a})=>{const s=a.original.aging_bucket,r={current:"text-green-600","1-30":"text-blue-600","31-60":"text-yellow-600","61-90":"text-orange-600",over_90:"text-red-600"};return e.jsx("span",{className:r[s]||"",children:s})}},{accessorKey:"original_amount",header:"Original Amount",cell:({row:a})=>n(a.original.original_amount)},{accessorKey:"paid_amount",header:"Paid Amount",cell:({row:a})=>n(a.original.paid_amount)},{accessorKey:"balance_due",header:"Balance Due",cell:({row:a})=>e.jsx("span",{className:"font-semibold",children:n(a.original.balance_due)})},{accessorKey:"vendor_invoice_number",header:"Vendor Invoice #"},{accessorKey:"po_number",header:"PO Number"}];function L(){const{vendorId:a}=l(),s=m(),[r,o]=u.useState(new Date().toISOString().split("T")[0]),{data:t,isLoading:c}=f(a,{as_of_date:r});return c?e.jsx("div",{className:"flex items-center justify-center h-96",children:e.jsx(N,{className:"h-8 w-8 animate-spin"})}):t?e.jsxs("div",{className:"space-y-6",children:[e.jsx(_,{title:`Vendor Aging Detail: ${t.vendor_name}`,description:`Vendor Code: ${t.vendor_code}`}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(x,{variant:"outline",size:"sm",onClick:()=>s(-1),children:[e.jsx(g,{className:"h-4 w-4 mr-2"}),"Back to Report"]}),e.jsxs("div",{className:"w-64",children:[e.jsx(y,{children:"As of Date"}),e.jsx(b,{type:"date",value:r,onChange:d=>o(d.target.value)})]})]}),e.jsxs(h,{children:[e.jsx(v,{children:e.jsx(p,{children:"Summary"})}),e.jsx(j,{children:e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Vendor Name"}),e.jsx("p",{className:"text-lg font-semibold",children:t.vendor_name})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Total Outstanding"}),e.jsx("p",{className:"text-lg font-semibold",children:n(t.total_outstanding)})]})]})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h2",{className:"text-xl font-semibold",children:["Invoice Details (",t.invoices.length," invoices)"]}),e.jsx(D,{columns:C,data:t.invoices,searchableColumns:[{id:"invoice_number",title:"Invoice Number"},{id:"vendor_invoice_number",title:"Vendor Invoice #"},{id:"po_number",title:"PO Number"}]})]})]}):e.jsx("div",{children:"No data available"})}export{L as VendorAgingDetailPage};
