import{u as p,a as _,e as f,r as c,j as e,B as j,A as y,C as N,b,c as v,d as D}from"./index-Cc987VYg.js";import{P as C}from"./page-header-CrLb0v5J.js";import{u as P}from"./use-patient-aging-CK-SN_ys.js";import{I as A}from"./input-DPNG9e3H.js";import{L as S,a as K}from"./label-npsA0UlW.js";import{D as z}from"./data-table-DE8WuOG4.js";import{f as n,a as I}from"./format-xRPgypNS.js";import"./command-G4m7hi6O.js";import"./separator-D14BnWPe.js";const k=[{accessorKey:"charge_number",header:"Charge Number"},{accessorKey:"service_date",header:"Service Date",cell:({row:a})=>I(a.original.service_date)},{accessorKey:"encounter_id",header:"Encounter ID"},{accessorKey:"days_outstanding",header:"Days Outstanding",cell:({row:a})=>{const s=a.original.days_outstanding;return e.jsx("span",{className:s>90?"text-red-600 font-semibold":"",children:s})}},{accessorKey:"aging_bucket",header:"Aging Bucket",cell:({row:a})=>{const s=a.original.aging_bucket,o={current:"text-green-600",days_1_30:"text-green-600",days_31_60:"text-yellow-600",days_61_90:"text-orange-600",days_91_120:"text-red-600",days_over_120:"text-red-700 font-bold"},r=s.replace("days_","").replace("_","-");return e.jsx("span",{className:o[s]||"",children:r})}},{accessorKey:"adjustment_amount",header:"Adjustment Amount",cell:({row:a})=>n(a.original.adjustment_amount)},{accessorKey:"original_amount",header:"Original Amount",cell:({row:a})=>n(a.original.original_amount)},{accessorKey:"paid_amount",header:"Paid Amount",cell:({row:a})=>n(a.original.paid_amount)},{accessorKey:"balance_due",header:"Balance Due",cell:({row:a})=>e.jsx("span",{className:"font-semibold",children:n(a.original.balance_due)})}];function $(){const{patientId:a}=p(),s=_(),{preferences:o,getDefaultPageSize:r}=f(),[d,g]=c.useState(new Date().toISOString().split("T")[0]),[h,m]=c.useState(1),[l,u]=c.useState(r());c.useEffect(()=>{u(r()),m(1)},[o?.items_per_page,r]);const{data:t,isLoading:x}=P(a,{as_of_date:d,page:h,page_size:l});return x?e.jsx("div",{className:"flex items-center justify-center h-96",children:e.jsx(S,{className:"h-8 w-8 animate-spin"})}):t?e.jsxs("div",{className:"space-y-6",children:[e.jsx(C,{title:`Patient Aging Detail: ${t.patient_name}`,description:`Account Number: ${t.account_number}`}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(j,{variant:"outline",size:"sm",onClick:()=>s(-1),children:[e.jsx(y,{className:"h-4 w-4 mr-2"}),"Back to Report"]}),e.jsxs("div",{className:"w-64",children:[e.jsx(K,{children:"As of Date"}),e.jsx(A,{type:"date",value:d,onChange:i=>g(i.target.value)})]})]}),e.jsxs(N,{children:[e.jsx(b,{children:e.jsx(v,{children:"Summary"})}),e.jsx(D,{children:e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Patient Name"}),e.jsx("p",{className:"text-lg font-semibold",children:t.patient_name})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Total Outstanding"}),e.jsx("p",{className:"text-lg font-semibold",children:n(t.total_outstanding)})]})]})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h2",{className:"text-xl font-semibold",children:["Charge Details (",t.charges?.length||0," charges)"]}),e.jsx(z,{columns:k,data:t.charges||[],searchableColumns:[{id:"charge_number",title:"Charge Number"},{id:"encounter_id",title:"Encounter ID"}],pageCount:Math.ceil((t.count||t.charges?.length||0)/l),defaultPageSize:l,onPaginationChange:i=>{m(i.pageIndex+1),u(i.pageSize)}})]})]}):e.jsx("div",{children:"No data available"})}export{$ as PatientAgingDetailPage};
