import{a as x,j as e,b as u,c as y,R as c,B as p,r as g}from"./index-Cc987VYg.js";import{P as j}from"./page-header-CrLb0v5J.js";import{S as l}from"./stats-card-9bgUZjvH.js";import{D as h}from"./data-table-DE8WuOG4.js";import{D as r}from"./data-table-column-header-Bq3ISNV9.js";import{f as t,a as _}from"./format-xRPgypNS.js";import{E as f}from"./eye-CXkzLhIn.js";import{a as v,b as N}from"./use-payer-aging-yxwg8Le_.js";import{I as A}from"./input-DPNG9e3H.js";import{L as C,a as D}from"./label-npsA0UlW.js";import"./command-G4m7hi6O.js";import"./separator-D14BnWPe.js";import"./chevrons-up-down-ksijt0Wf.js";import"./eye-off-DI70rQvm.js";function P({report:s,onExport:d}){const i=x(),n=[{accessorKey:"payer_code",header:({column:a})=>e.jsx(r,{column:a,title:"Code"})},{accessorKey:"payer_name",header:({column:a})=>e.jsx(r,{column:a,title:"Payer"}),cell:({row:a})=>e.jsx("button",{onClick:()=>i(c.PAYER_AGING_DETAIL.replace(":payerId",a.original.payer_id)),className:"text-blue-600 hover:text-blue-800 hover:underline text-left",children:a.original.payer_name})},{accessorKey:"current",header:({column:a})=>e.jsx(r,{column:a,title:"Current",className:"justify-end"}),cell:({row:a})=>e.jsx("div",{className:"text-right",children:t(a.original.current)})},{accessorKey:"days_31_60",header:({column:a})=>e.jsx(r,{column:a,title:"31-60 Days",className:"justify-end"}),cell:({row:a})=>e.jsx("div",{className:"text-right",children:t(a.original.days_31_60)})},{accessorKey:"days_61_90",header:({column:a})=>e.jsx(r,{column:a,title:"61-90 Days",className:"justify-end"}),cell:({row:a})=>e.jsx("div",{className:"text-right",children:t(a.original.days_61_90)})},{accessorKey:"days_91_120",header:({column:a})=>e.jsx(r,{column:a,title:"91-120 Days",className:"justify-end"}),cell:({row:a})=>e.jsx("div",{className:"text-right",children:t(a.original.days_91_120)})},{accessorKey:"days_121_plus",header:({column:a})=>e.jsx(r,{column:a,title:"121+ Days",className:"justify-end"}),cell:({row:a})=>e.jsx("div",{className:"text-right",children:t(a.original.days_121_plus)})},{accessorKey:"total_outstanding",header:({column:a})=>e.jsx(r,{column:a,title:"Total",className:"justify-end"}),cell:({row:a})=>e.jsx("div",{className:"text-right font-bold",children:t(a.original.total_outstanding)})},{id:"actions",header:"Actions",cell:({row:a})=>e.jsx(p,{variant:"ghost",size:"sm",onClick:()=>i(c.PAYER_AGING_DETAIL.replace(":payerId",a.original.payer_id)),children:e.jsx(f,{className:"h-4 w-4"})})}];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(l,{title:"Total Outstanding",value:t(s.summary.total_outstanding)}),e.jsx(l,{title:"Current",value:t(s.summary.total_current),description:`${s.summary.percentage_current.toFixed(1)}%`}),e.jsx(l,{title:"Overdue",value:t(s.summary.total_overdue),valueClassName:"text-red-600",description:`${s.summary.percentage_overdue.toFixed(1)}%`}),e.jsx(l,{title:"Total Payers",value:s.summary.total_payers})]}),e.jsx(u,{children:e.jsx("div",{className:"flex justify-between items-center",children:e.jsxs("div",{children:[e.jsx(y,{children:"Payer Aging Report"}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["As of ",_(s.as_of_date)]})]})})}),e.jsx(h,{columns:n,data:s.lines,searchableColumns:[{id:"payer_name",title:"Payer"},{id:"payer_code",title:"Code"}]})]})}function F(){const[s,d]=g.useState(new Date().toISOString().split("T")[0]),{data:i,isLoading:n}=v({as_of_date:s}),a=N();if(n)return e.jsx("div",{className:"flex items-center justify-center h-96",children:e.jsx(C,{className:"h-8 w-8 animate-spin"})});if(!i)return e.jsx("div",{children:"No data available"});const m=o=>{a.mutate({format:o,filters:{as_of_date:s}})};return e.jsxs("div",{className:"space-y-6",children:[e.jsx(j,{title:"Payer Aging Report",description:"Insurance payer aging analysis"}),e.jsx("div",{className:"flex items-end gap-4",children:e.jsxs("div",{className:"w-64",children:[e.jsx(D,{children:"As of Date"}),e.jsx(A,{type:"date",value:s,onChange:o=>d(o.target.value)})]})}),e.jsx(P,{report:i,onExport:m})]})}export{F as PayerAgingReportPage};
