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-C-gKvEDq.js";import{P as f}from"./page-header--nE6NVdA.js";import{u as _}from"./use-aging-CXOZeZBb.js";import{I as b}from"./input-B9yFYvyi.js";import{L as N}from"./label-B3YRGmn1.js";import{D as y}from"./data-table-1lm2JMeq.js";import{f as n,a as i}from"./format-DcyqLq2i.js";import{L as D}from"./loader-circle-MiR2w4nF.js";import"./command-CyAetjD5.js";import"./separator-Cnu0xg_i.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,t={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:t[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 S(){const{vendorId:a}=l(),s=m(),[t,o]=u.useState(new Date().toISOString().split("T")[0]),{data:r,isLoading:c}=_(a,{as_of_date:t});return c?e.jsx("div",{className:"flex items-center justify-center h-96",children:e.jsx(D,{className:"h-8 w-8 animate-spin"})}):r?e.jsxs("div",{className:"space-y-6",children:[e.jsx(f,{title:`Vendor Aging Detail: ${r.vendor_name}`,description:`Vendor Code: ${r.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(N,{children:"As of Date"}),e.jsx(b,{type:"date",value:t,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:r.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(r.total_outstanding)})]})]})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h2",{className:"text-xl font-semibold",children:["Invoice Details (",r.invoices.length," invoices)"]}),e.jsx(y,{columns:C,data:r.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{S as VendorAgingDetailPage};
