import{u as y,a as b,e as N,r as i,j as e,B as C,A as P,C as D,b as v,c as S,d as K}from"./index-C-gKvEDq.js";import{P as A}from"./page-header--nE6NVdA.js";import{u as z}from"./use-payer-aging-DO5f8MeY.js";import{I as k}from"./input-B9yFYvyi.js";import{L}from"./label-B3YRGmn1.js";import{D as B}from"./data-table-1lm2JMeq.js";import{a as m}from"./format-DcyqLq2i.js";import{L as I}from"./loader-circle-MiR2w4nF.js";import"./command-CyAetjD5.js";import"./separator-Cnu0xg_i.js";function G(){const{payerId:u}=y(),g=b(),{preferences:p,getDefaultPageSize:n,formatCurrency:s}=N(),[c,x]=i.useState(new Date().toISOString().split("T")[0]),[h,o]=i.useState(1),[l,d]=i.useState(n()),_=i.useMemo(()=>[{accessorKey:"claim_number",header:"Claim Number"},{accessorKey:"payer_claim_number",header:"Payer Claim #",cell:({row:a})=>a.original.payer_claim_number||"-"},{accessorKey:"claim_date",header:"Claim Date",cell:({row:a})=>m(a.original.claim_date)},{accessorKey:"submitted_date",header:"Submitted Date",cell:({row:a})=>a.original.submitted_date?m(a.original.submitted_date):"-"},{accessorKey:"patient_name",header:"Patient Name"},{accessorKey:"days_outstanding",header:"Days Outstanding",cell:({row:a})=>{const r=a.original.days_outstanding;return e.jsx("span",{className:r>90?"text-red-600 font-semibold":"",children:r})}},{accessorKey:"aging_bucket",header:"Aging Bucket",cell:({row:a})=>{const r=a.original.aging_bucket,j={current:"text-green-600","31-60":"text-yellow-600","61-90":"text-orange-600","91-120":"text-red-600","121+":"text-red-700 font-bold"};return e.jsx("span",{className:j[r]||"",children:r})}},{accessorKey:"total_charge_amount",header:"Total Charges",cell:({row:a})=>s(a.original.total_charge_amount||a.original.original_amount)},{accessorKey:"paid_amount",header:"Paid Amount",cell:({row:a})=>s(a.original.paid_amount)},{accessorKey:"adjustment_amount",header:"Adjustments",cell:({row:a})=>s(a.original.adjustment_amount||0)},{accessorKey:"balance_due",header:"Balance Due",cell:({row:a})=>e.jsx("span",{className:"font-semibold",children:s(a.original.balance_due)})}],[s]);i.useEffect(()=>{d(n()),o(1)},[p?.items_per_page,n]);const{data:t,isLoading:f}=z(u,{as_of_date:c,page:h,page_size:l});return f?e.jsx("div",{className:"flex items-center justify-center h-96",children:e.jsx(I,{className:"h-8 w-8 animate-spin"})}):t?e.jsxs("div",{className:"space-y-6",children:[e.jsx(A,{title:`Payer Aging Detail: ${t.payer_name}`,description:`Payer Code: ${t.payer_code}`}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(C,{variant:"outline",size:"sm",onClick:()=>g(-1),children:[e.jsx(P,{className:"h-4 w-4 mr-2"}),"Back to Report"]}),e.jsxs("div",{className:"w-64",children:[e.jsx(L,{children:"As of Date"}),e.jsx(k,{type:"date",value:c,onChange:a=>x(a.target.value)})]})]}),e.jsxs(D,{children:[e.jsx(v,{children:e.jsx(S,{children:"Summary"})}),e.jsx(K,{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:"Payer Name"}),e.jsx("p",{className:"text-lg font-semibold",children:t.payer_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:s(t.total_outstanding)})]})]})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("h2",{className:"text-xl font-semibold",children:["Claim Details (",t.claims.length," claims)"]}),e.jsx(B,{columns:_,data:t.claims,searchableColumns:[{id:"claim_number",title:"Claim Number"},{id:"patient_name",title:"Patient Name"}],pageCount:Math.ceil((t.count||t.claims.length)/l),defaultPageSize:l,onPaginationChange:a=>{o(a.pageIndex+1),d(a.pageSize)}})]})]}):e.jsx("div",{children:"No data available"})}export{G as PayerAgingDetailPage};
