1import{j as e,a as R}from"./vendor-query-CR-VCSTz.js";import{b4 as G,cf as O,cg as K,bB as Q,cd as X,B as b,C as Z,a as ee}from"./index-BrkMe9fl.js";import{P as te}from"./PageHeader-BTrLSbzq.js";import{S as y}from"./StatCard-Ct7FvOtH.js";import{T as ae,a as ie,b as C,c as r,d as se,e as s}from"./table-tCXsHZs9.js";import{S as re}from"./StatusPill-BkU7dvVt.js";import{S as A,a as I,b as k,c as $,d as x}from"./select-C1JqqMZn.js";import{h as ne,i as le}from"./useProviderRedemption-CkIEVh2I.js";import{F as ce}from"./FinanceAccessGate-B1McwjYn.js";import{L as oe}from"./LocationSwitcher-DZSt5aL3.js";import{u as de}from"./useMyProviderRelated-D23Jl31O.js";import{a as H,b as N,p as me,f as P,c as ue}from"./providerFinancialReporting-oZSJImf6.js";import{O as T}from"./vendor-icons-Bkm9ycWJ.js";import"./vendor-react-CcMhIRHi.js";import"./vendor-charts-CBhuxwPC.js";import"./vendor-supabase-Dp23wbUo.js";import"./vendor-forms-C0xMzmLW.js";import"./drawer-BGa-U4b5.js";import"./index-BdQq_4o_.js";import"./index-boAf8wIS.js";import"./useBenefits-Cmlop74E.js";import"./useEmployerMemberId-C8tyEH97.js";const L=i=>i==null?"Unavailable":`$${(i/100).toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}`,p={mtd:"Month to date",qtd:"Quarter to date",ytd:"Year to date",last_year:"Last year"},j=50,f=i=>i.trim().toLowerCase();function he(i,n){return i==="facial_or_peel"?n==="facial"?"Facial":n==="peel"?"Peel":"Facial / Peel":i.startsWith("sunscreen")?"Sunscreen":i.replace(/_/g," ").replace(/\b\w/g,o=>o.toUpperCase())}function xe(){const i=Q(),n=ne(),o=le(),g=de(),{selectedLocationId:v}=X(),[u,V]=R.useState("ytd"),[d,W]=R.useState("all"),[Y,S]=R.useState(0),_=new Date,M=()=>{i.refetch(),n.refetch(),o.refetch(),g.refetch()};if(i.isError||n.isError)return e.jsxs("div",{role:"alert",className:"space-y-3 p-4",children:[e.jsx("p",{children:"Reconciliation unavailable. The complete practice ledger could not be loaded."}),e.jsx(b,{onClick:M,children:"Retry reconciliation"})]});if(i.isPending||i.data&&n.isPending)return e.jsx("p",{role:"status",children:"Loading reconciliationâ¦"});if(!i.data)return e.jsx("p",{children:"Reconciliation unavailable. Link this account to a practice to view its records."});if(!n.data)return e.jsx("p",{role:"alert",children:"Reconciliation unavailable. No complete ledger response was received."});const F=n.data,m=v?F.filter(t=>t.location_id===v):F,J=m.filter(t=>!["void","cancelled","canceled"].includes(f(t.status))),U=H(J.map(t=>({date:t.service_date,amount_cents:["pending","batched","paid","reconciled"].includes(f(t.status))?t.amount_cents:null})),u,_),w=H(m.filter(t=>f(t.status)==="paid").map(t=>({date:t.paid_at,amount_cents:t.amount_cents})),u,_),h=d==="all"?m:d==="undated"?m.filter(t=>N(t.service_date)==null):m.filter(t=>{const a=N(t.service_date);if(a==null)return!1;if(d in p){const l=me(d,_);return a>=l.start&&a<l.end}return new Date(a).toISOString().slice(0,7)===d}),q=[...new Set(m.flatMap(t=>N(t.service_date)==null?[]:[new Date(t.service_date).toISOString().slice(0,7)]))].sort().reverse(),c=Math.min(Y,Math.max(0,Math.ceil(h.length/j)-1)),B=h.slice(c*j,(c+1)*j),D=t=>{var l,E;if(!t)return"Unassigned clinic";const a=(l=g.data)==null?void 0:l.find(z=>z.location_id===t);return((E=a==null?void 0:a.location_name)==null?void 0:E.trim())||[a==null?void 0:a.location_city,a==null?void 0:a.location_state].filter(Boolean).join(", ")||"Clinic unavailable"};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-4 flex items-center justify-between gap-3",children:[e.jsx("h2",{className:"text-sm font-medium",children:"Recorded amounts"}),e.jsxs(A,{value:u,onValueChange:t=>V(t),children:[e.jsx(I,{className:"w-48","aria-label":"Amount period",children:e.jsx(k,{})}),e.jsx($,{children:Object.entries(p).map(([t,a])=>e.jsx(x,{value:t,children:a},t))})]})]}),e.jsxs("div",{className:"mb-4 grid gap-4 md:grid-cols-3",children:[e.jsx(y,{label:`${p[u]} recorded paid`,value:L(w.total),icon:T}),e.jsx(y,{label:`${p[u]} service obligations`,value:L(U.total),icon:T}),e.jsx(y,{label:"JOYA Wellness referral amounts",value:"Unavailable",icon:T})]}),e.jsx("p",{className:"mb-4 text-sm text-muted-foreground",children:"Paid amounts use recorded payment dates. Service obligations use linked service dates, including unpaid obligations. Calendar periods use UTC and current periods end now. Wellness referral amounts are not connected to a payment source here."}),(U.total==null||w.total==null)&&e.jsx("p",{role:"status",className:"mb-4 text-sm text-amber-800",children:"Some records have missing or conflicting date, status, or amount evidence. Affected period totals are unavailable; all ledger records remain in the history below."}),(o.isError||g.isError)&&e.jsxs("div",{role:"alert",className:"mb-4 text-sm",children:["Member or clinic labels are unavailable. Recorded amounts remain based on the practice ledger. ",e.jsx(b,{variant:"link",onClick:M,children:"Retry labels"})]}),e.jsxs("div",{className:"mb-4 flex flex-wrap items-center justify-between gap-3",children:[e.jsx("h2",{className:"text-xl font-semibold",children:"Reimbursement ledger"}),e.jsxs(A,{value:d,onValueChange:t=>{W(t),S(0)},children:[e.jsx(I,{className:"w-56","aria-label":"Service date filter",children:e.jsx(k,{})}),e.jsxs($,{children:[e.jsx(x,{value:"all",children:"All service dates"}),e.jsx(x,{value:"undated",children:"Service date unavailable"}),Object.entries(p).map(([t,a])=>e.jsx(x,{value:t,children:a},t)),q.map(t=>e.jsx(x,{value:t,children:t},t))]})]})]}),v&&e.jsxs("p",{className:"mb-3 text-sm text-muted-foreground",children:["Showing ",D(v),". Records without that clinic assignment are excluded by this filter."]}),e.jsx(Z,{children:e.jsx(ee,{className:"p-0",children:e.jsxs(ae,{children:[e.jsx(ie,{children:e.jsxs(C,{children:[e.jsx(r,{children:"Member"}),e.jsx(r,{children:"JOYA ID"}),e.jsx(r,{children:"Clinic"}),e.jsx(r,{children:"Benefit"}),e.jsx(r,{children:"Service date (UTC)"}),e.jsx(r,{children:"Recorded amount"}),e.jsx(r,{children:"Recorded on (UTC)"}),e.jsx(r,{children:"Status"}),e.jsx(r,{children:"Paid on (UTC)"})]})}),e.jsx(se,{children:B.length===0?e.jsx(C,{children:e.jsx(s,{colSpan:9,className:"py-8 text-center",children:"No ledger records match this service-date filter."})}):B.map(t=>{var l;const a=o.isError||(l=o.data)==null?void 0:l.get(t.member_id);return e.jsxs(C,{children:[e.jsx(s,{children:(a==null?void 0:a.name)||"Member name unavailable"}),e.jsx(s,{children:(a==null?void 0:a.joyaId)||"Unavailable"}),e.jsx(s,{children:D(t.location_id)}),e.jsx(s,{children:he(t.benefit_code,t.variant)}),e.jsx(s,{children:P(t.service_date)}),e.jsx(s,{children:L(ue(t.amount_cents))}),e.jsx(s,{children:P(t.created_at)}),e.jsx(s,{children:e.jsx(re,{tone:f(t.status)==="paid"?"success":"warning",children:t.status})}),e.jsx(s,{children:f(t.status)==="paid"?P(t.paid_at):"Not recorded as paid"})]},t.id)})})]})})}),e.jsxs("div",{className:"mt-4 flex items-center justify-between gap-3",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:[h.length.toLocaleStr
1ing()," matching records · page ",c+1," of ",Math.max(1,Math.ceil(h.length/j))]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(b,{variant:"outline",disabled:c===0,onClick:()=>S(c-1),children:"Previous"}),e.jsx(b,{variant:"outline",disabled:(c+1)*j>=h.length,onClick:()=>S(c+1),children:"Next"})]})]})]})}function Oe(){return e.jsxs(G,{brandLabel:"Provider",sections:K,footerName:O.name,footerEmail:O.email,children:[e.jsx(te,{eyebrow:"Reconciliation",title:"Benefit Reconciliation",description:"Recorded reimbursement obligations and payments for your practice.",actions:e.jsx(oe,{})}),e.jsx(ce,{children:e.jsx(xe,{})})]})}export{Oe as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.