import{a as y,e as h,j as e,c as N,R as j,D,f as A,B as b,g as C,h as E,r as d}from"./index-C-gKvEDq.js";import{P}from"./page-header--nE6NVdA.js";import{S as c}from"./stats-card-Bu-NuPUd.js";import{D as S}from"./data-table-1lm2JMeq.js";import{D as r}from"./data-table-column-header-CHnvH8B_.js";import{a as R}from"./format-DcyqLq2i.js";import{E as w}from"./ellipsis-BDOxlwoq.js";import{E as T}from"./eye-CPt1Lma-.js";import{a as I,b as O}from"./use-aging-CXOZeZBb.js";import{I as z}from"./input-B9yFYvyi.js";import{L as K}from"./label-B3YRGmn1.js";import{L}from"./loader-circle-MiR2w4nF.js";function V({report:a,onExport:g,onPaginationChange:m}){const i=y(),{formatCurrency:t}=h(),o=[{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(j.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(w,{className:"h-4 w-4"})})}),e.jsx(C,{align:"end",children:e.jsxs(E,{onClick:l=>{l.stopPropagation(),i(j.VENDOR_AGING_DETAIL.replace(":vendorId",s.original.vendor_id))},children:[e.jsx(T,{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(c,{title:"Total Outstanding",value:t(a.summary.total_outstanding)}),e.jsx(c,{title:"Current",value:t(a.summary.total_current),description:`${a.summary.percentage_current.toFixed(1)}%`}),e.jsx(c,{title:"Overdue",value:t(a.summary.total_overdue),valueClassName:"text-red-600",description:`${a.summary.percentage_overdue.toFixed(1)}%`}),e.jsx(c,{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 ",R(a.as_of_date)]})]})}),e.jsx(S,{columns:o,data:a.lines,searchableColumns:[{id:"vendor_name",title:"Vendor"},{id:"vendor_code",title:"Code"}],onPaginationChange:m})]})}function M(){const[a,g]=d.useState(new Date().toISOString().split("T")[0]),{preferences:m,getDefaultPageSize:i}=h(),[t,o]=d.useState(1),[s,l]=d.useState(i());d.useEffect(()=>{l(i()),o(1)},[m?.items_per_page,i]);const{data:u,isLoading:p}=I({as_of_date:a,page:t,page_size:s}),f=O();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(!u)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(P,{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(K,{children:"As of Date"}),e.jsx(z,{type:"date",value:a,onChange:n=>g(n.target.value)})]})}),e.jsx(V,{report:u,onExport:v,onPaginationChange:n=>{const _=n.pageIndex+1,x=n.pageSize;x!==s?(o(1),l(x)):o(_)}})]})}const Y=Object.freeze(Object.defineProperty({__proto__:null,AgingReportPage:M},Symbol.toStringTag,{value:"Module"}));export{V as A,M as a,Y as b};
