import{a as y,j as e,c as N,R as h,D,f as A,B as b,g as C,h as E,r as o,e as P}from"./index-Cc987VYg.js";import{P as S}from"./page-header-CrLb0v5J.js";import{S as d}from"./stats-card-9bgUZjvH.js";import{D as R}from"./data-table-DE8WuOG4.js";import{D as r}from"./data-table-column-header-Bq3ISNV9.js";import{f as t,a as w}from"./format-xRPgypNS.js";import{E as T}from"./ellipsis-DRyH0mgV.js";import{E as I}from"./eye-CXkzLhIn.js";import{a as O,b as z}from"./use-aging-U7aee-6E.js";import{I as K}from"./input-DPNG9e3H.js";import{L,a as V}from"./label-npsA0UlW.js";function M({report:a,onExport:g,onPaginationChange:c}){const i=y(),m=[{accessorKey:"vendor_code",header:({column:s})=>e.jsx(r,{column:s,title:"Code"})},{accessorKey:"vendor_name",header:({column:s})=>e.jsx(r,{column:s,title:"Vendor"}),cell:({row:s})=>e.jsx("button",{onClick:()=>i(h.VENDOR_AGING_DETAIL.replace(":vendorId",s.original.vendor_id)),className:"text-blue-600 hover:text-blue-800 hover:underline text-left",children:s.original.vendor_name})},{accessorKey:"current",header:({column:s})=>e.jsx(r,{column:s,title:"Current",className:"justify-end"}),cell:({row:s})=>e.jsx("div",{className:"text-right",children:t(s.original.current)})},{accessorKey:"days_1_30",header:({column:s})=>e.jsx(r,{column:s,title:"1-30 Days",className:"justify-end"}),cell:({row:s})=>e.jsx("div",{className:"text-right",children:t(s.original.days_1_30)})},{accessorKey:"days_31_60",header:({column:s})=>e.jsx(r,{column:s,title:"31-60 Days",className:"justify-end"}),cell:({row:s})=>e.jsx("div",{className:"text-right",children:t(s.original.days_31_60)})},{accessorKey:"days_61_90",header:({column:s})=>e.jsx(r,{column:s,title:"61-90 Days",className:"justify-end"}),cell:({row:s})=>e.jsx("div",{className:"text-right",children:t(s.original.days_61_90)})},{accessorKey:"over_90",header:({column:s})=>e.jsx(r,{column:s,title:"Over 90 Days",className:"justify-end"}),cell:({row:s})=>e.jsx("div",{className:"text-right",children:t(s.original.over_90)})},{accessorKey:"total_outstanding",header:({column:s})=>e.jsx(r,{column:s,title:"Total",className:"justify-end"}),cell:({row:s})=>e.jsx("div",{className:"text-right font-bold",children:t(s.original.total_outstanding)})},{id:"actions",header:()=>e.jsx("div",{className:"text-right",children:"Actions"}),cell:({row:s})=>e.jsx("div",{className:"flex items-center justify-end",children:e.jsxs(D,{children:[e.jsx(A,{asChild:!0,children:e.jsx(b,{variant:"ghost",size:"sm",children:e.jsx(T,{className:"h-4 w-4"})})}),e.jsx(C,{align:"end",children:e.jsxs(E,{onClick:l=>{l.stopPropagation(),i(h.VENDOR_AGING_DETAIL.replace(":vendorId",s.original.vendor_id))},children:[e.jsx(I,{className:"h-4 w-4 mr-2"}),"View Details"]})})]})})}];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsx(d,{title:"Total Outstanding",value:t(a.summary.total_outstanding)}),e.jsx(d,{title:"Current",value:t(a.summary.total_current),description:`${a.summary.percentage_current.toFixed(1)}%`}),e.jsx(d,{title:"Overdue",value:t(a.summary.total_overdue),valueClassName:"text-red-600",description:`${a.summary.percentage_overdue.toFixed(1)}%`}),e.jsx(d,{title:"Total Vendors",value:a.summary.total_vendors})]}),e.jsx("div",{className:"flex justify-between items-center",children:e.jsxs("div",{children:[e.jsx(N,{children:"Accounts Payable Aging Report"}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["As of ",w(a.as_of_date)]})]})}),e.jsx(R,{columns:m,data:a.lines,searchableColumns:[{id:"vendor_name",title:"Vendor"},{id:"vendor_code",title:"Code"}],onPaginationChange:c})]})}function G(){const[a,g]=o.useState(new Date().toISOString().split("T")[0]),{preferences:c,getDefaultPageSize:i}=P(),[m,s]=o.useState(1),[l,u]=o.useState(i());o.useEffect(()=>{u(i()),s(1)},[c?.items_per_page,i]);const{data:x,isLoading:p}=O({as_of_date:a,page:m,page_size:l}),f=z();if(p)return e.jsx("div",{className:"flex items-center justify-center h-96",children:e.jsx(L,{className:"h-8 w-8 animate-spin"})});if(!x)return e.jsx("div",{children:"No data available"});const v=n=>{f.mutate({format:n,filters:{as_of_date:a}})};return e.jsxs("div",{className:"space-y-6",children:[e.jsx(S,{title:"AP Aging Report",description:"Accounts Payable aging analysis"}),e.jsx("div",{className:"flex items-end gap-4",children:e.jsxs("div",{className:"w-64",children:[e.jsx(V,{children:"As of Date"}),e.jsx(K,{type:"date",value:a,onChange:n=>g(n.target.value)})]})}),e.jsx(M,{report:x,onExport:v,onPaginationChange:n=>{const _=n.pageIndex+1,j=n.pageSize;j!==l?(s(1),u(j)):s(_)}})]})}const Y=Object.freeze(Object.defineProperty({__proto__:null,AgingReportPage:G},Symbol.toStringTag,{value:"Module"}));export{M as A,G as a,Y as b};
