import{a as u,j as e,b as x,c as g,R as d,B as j,r as p}from"./index-C9vqJYWU.js";import{P as h}from"./page-header-DC46WPrB.js";import{S as n}from"./stats-card-DlB-ZRM6.js";import{D as _}from"./data-table-omMLuxxA.js";import{D as i}from"./data-table-column-header-B3h7IX6G.js";import{f as s,a as y}from"./format-SUM4HJmt.js";import{E as f}from"./eye-B6KZMgKi.js";import{a as v,b as N}from"./use-patient-aging-CDl9FKGN.js";import{I as A}from"./input-B-hEG1q_.js";import{L as D,a as b}from"./label-CwKg3qNE.js";import"./command-CfddNxWu.js";import"./separator-XQIAzE1m.js";import"./chevrons-up-down-BHMtvqij.js";import"./eye-off-CrymLS2V.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};
