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