PageSourceSearch

https://snf-insights.ai/assets/IndustryPage-DCbTYOz2.js

js snf-insights.ai collected 2026-10-05 15:07:13 UTC 74,192 bytes, 13 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-Df108JlE.js","assets/index-Bfcugaeq.css"])))=>i.map(i=>d[i]);
2import{r as N,b as Z,j as e,D as se,H as re,aJ as We,aK as Xe,aL as Je,aM as Ze,Y as xe,C as he,X as et,a8 as Pe,a9 as tt,L as ue,q as st,ab as ce,az as at,aN as nt,aC as rt,aO as lt,aP as it,aQ as ot,aR as ct}from"./index-Df108JlE.js";import{B as De,c as Te,C as Ie}from"./BarChart-C3zlDDul.js";import{C as ye}from"./CartesianGrid-CgHY_Blv.js";import{ag as be,ah as ge,ai as fe,af as Ee}from"./CartesianChart-CxTC1H5D.js";import{a as Le,L as Ne}from"./LineChart-BhL0DOVD.js";import{L as ze}from"./Legend-DQKG7AK5.js";import{R as Ae}from"./ReferenceLine-8H7qsIer.js";import{R as dt}from"./ReferenceArea-DOXhjVlc.js";import{S as we}from"./SuiteHeader-C9T1yf5Y.js";import{C as pt}from"./columns-3-BmRNc5z4.js";import{M as mt}from"./maximize-2-C1hFM99k.js";import{u as Be}from"./useModalA11y-B5_bs4oH.js";const de={fontSize:11,fill:"#64748b"},He="#f1f5f9",xt=[t=>Math.floor(t-Math.max(1,Math.abs(t)*.08)),t=>Math.ceil(t+Math.max(1,Math.abs(t)*.08))],ht=["pct_profitable","pct_profitable_net","median_net_margin","median_op_margin","median_occupancy","median_rev_ppd","median_cost_ppd"],ut=["nursing","admin","benefits","capital","dietary","therapy","nursing_admin","plant_ops","housekeeping","drugs","social_service","laundry"],yt=[...ht,...ut.flatMap(t=>[`dept_${t}_ppd`,`dept_${t}_pct`])],Ce=.1;function te({title:t,children:c,action:x}){return e.jsxs("div",{className:"bg-white border border-slate-200 rounded-xl p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2 min-h-[26px]",children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-700",children:t}),x]}),e.jsx("div",{className:"h-52",children:e.jsx(Ee,{width:"100%",height:"100%",children:c})})]})}const bt=t=>({active:c,payload:x,label:_})=>{if(!c||!x?.length)return null;const b=new Set,C=[];for(const y of x)y.value!=null&&!b.has(y.name)&&(b.add(y.name),C.push(y));return C.length?e.jsxs("div",{className:"rounded-md border border-slate-200 bg-white px-2 py-1.5 text-xs shadow-sm",children:[e.jsxs("div",{className:"mb-0.5 font-medium text-slate-500",children:["FY ",_]}),C.map(y=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-sm",style:{background:y.color}}),e.jsx("span",{className:"text-slate-600",children:y.name})]}),e.jsx("span",{className:"ml-auto font-medium text-slate-800",children:t(y.value)})]},y.name))]}):null};function ae({data:t,series:c,fmt:x,partialFrom:_,zeroLine:b}){const C=t.length?t[t.length-1].fy_year:null;return e.jsxs(Le,{data:t,margin:{top:6,right:12,left:-12,bottom:2},children:[e.jsx(ye,{strokeDasharray:"3 3",stroke:He,vertical:!1}),e.jsx(be,{dataKey:"fy_year",tick:de}),e.jsx(ge,{tick:de,width:48,tickFormatter:x,domain:xt}),e.jsx(fe,{content:bt(x)}),c.length>1&&e.jsx(ze,{wrapperStyle:{fontSize:11},iconType:"plainline"}),b&&e.jsx(Ae,{y:0,stroke:"#cbd5e1",strokeDasharray:"2 2"}),_!=null&&C!=null&&e.jsx(dt,{x1:_,x2:C,fill:"#f59e0b",fillOpacity:.07}),c.flatMap(y=>[e.jsx(Ne,{type:"monotone",dataKey:y.key,name:y.name,stroke:y.color,strokeWidth:2,dot:{r:2.5},activeDot:{r:4}},y.key),e.jsx(Ne,{type:"monotone",dataKey:`${y.key}__d`,name:y.name,stroke:y.color,strokeWidth:2,strokeDasharray:"4 3",dot:{r:2.5},legendType:"none"},`${y.key}__d`)])]})}const ie=t=>t==null?"":`${t}%`,Se=t=>t==null?"":`$${Math.round(t)}`;function gt({state:t,states:c=[],onSelectState:x,excludeMixed:_=!0}){const[b,C]=N.useState("nursing"),[y,I]=N.useState("ppd"),{data:j,isLoading:S,isError:d}=Z({queryKey:["industry-trends",t,_],queryFn:()=>We(t,!_)}),{rows:k,partialFrom:g,anyThin:h}=N.useMemo(()=>{const p=j?.trends??[],l=j?.peak_reporting??p.reduce((P,z)=>Math.max(P,z.reporting_count||0),0);let E=null;if(l>0)for(let P=p.length-1;P>=0&&p[P].reporting_count<.5*l;P--)E=p[P].fy_year;let $=!1;return{rows:p.map((P,z)=>{const D=l>0&&P.reporting_count<Ce*l,Y=z+1<p.length&&l>0&&p[z+1].reporting_count<Ce*l;D&&($=!0);const T={...P};return yt.forEach(w=>{T[`${w}__d`]=D||Y?P[w]:null,D&&(T[w]=null)}),T}),partialFrom:E,anyThin:$}},[j]);if(S)return e.jsx("div",{className:"py-10 text-center text-sm text-slate-400",children:"Loading trends…"});if(d||!k.length)return e.jsx("div",{className:"py-10 text-center text-sm text-slate-400",children:"No trend data available."});const o=()=>{const p=j?.departments??[],l="Fiscal Year,Reporting,% Profitable,Net Margin %,Operating Margin %,Occupancy %,Revenue/Day,Cost/Day"+p.map($=>`,${$.label} $/day,${$.label} % of cost`).join("")+`
3`,E=(j?.trends??[]).map($=>[$.fy_year,$.reporting_count,$.pct_profitable,$.median_net_margin,$.median_op_margin,$.median_occupancy,$.median_rev_ppd,$.median_cost_p
3pd,...p.flatMap(V=>[$[`dept_${V.key}_ppd`]??"",$[`dept_${V.key}_pct`]??""])].join(",")).join(`
4`);re(`snf_trends_${(t||"national").toLowerCase()}.csv`,l+E)};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-base font-bold text-slate-800",children:"Trends —"}),x?e.jsxs("select",{value:t||"",onChange:p=>x(p.target.value||null),className:"text-sm font-medium text-slate-700 border border-slate-300 rounded-lg px-2 py-1 bg-white focus:outline-none focus:ring-1 focus:ring-sky-400",children:[e.jsx("option",{value:"",children:"National"}),[...c].sort().map(p=>e.jsx("option",{value:p,children:p},p))]}):e.jsx("span",{className:"text-base font-bold text-slate-800",children:t||"National"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-[11px] text-slate-400",children:"Cost-report fiscal year (not calendar)"}),e.jsxs("button",{onClick:o,className:"flex items-center gap-1 text-xs text-slate-600 hover:text-sky-600 transition-colors",children:[e.jsx(se,{size:13})," CSV"]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsx(te,{title:"% Profitable — net vs. operating",children:e.jsx(ae,{data:k,fmt:ie,partialFrom:g,series:[{key:"pct_profitable_net",name:"Net (net income > 0)",color:"#0284c7"},{key:"pct_profitable",name:"Operating (op margin > 0)",color:"#f59e0b"}]})}),e.jsx(te,{title:"Median margin — net vs. operating",children:e.jsx(ae,{data:k,fmt:ie,partialFrom:g,zeroLine:!0,series:[{key:"median_net_margin",name:"Net",color:"#0284c7"},{key:"median_op_margin",name:"Operating",color:"#f59e0b"}]})}),e.jsx(te,{title:"Median occupancy",children:e.jsx(ae,{data:k,fmt:ie,partialFrom:g,series:[{key:"median_occupancy",name:"Occupancy",color:"#0284c7"}]})}),e.jsx(te,{title:"Revenue vs. cost per day",children:e.jsx(ae,{data:k,fmt:Se,partialFrom:g,series:[{key:"median_rev_ppd",name:"Revenue / day",color:"#0284c7"},{key:"median_cost_ppd",name:"Cost / day",color:"#f59e0b"}]})}),e.jsx(te,{title:"Cost structure by department",action:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("select",{value:b,onChange:p=>C(p.target.value),"aria-label":"Department",className:"bg-white border border-slate-300 rounded-md px-2 py-1 text-xs text-slate-700 focus:outline-none focus:ring-2 focus:ring-sky-500 max-w-[190px]",children:(j?.departments??[]).map(p=>e.jsx("option",{value:p.key,children:p.label},p.key))}),e.jsx("div",{className:"flex rounded-md overflow-hidden border border-slate-300",children:[{k:"ppd",l:"$/day"},{k:"pct",l:"% of cost"}].map(p=>e.jsx("button",{onClick:()=>I(p.k),className:`px-2 py-1 text-[11px] ${y===p.k?"bg-sky-600 text-white":"bg-white text-slate-600 hover:bg-slate-50"}`,children:p.l},p.k))})]}),children:e.jsx(ae,{data:k,fmt:y==="pct"?ie:Se,partialFrom:g,series:[{key:`dept_${b}_${y}`,name:(j?.departments??[]).find(p=>p.key===b)?.label||"Department",color:"#0284c7"}]})}),e.jsx(te,{title:"Facilities reporting",children:e.jsxs(De,{data:k,margin:{top:6,right:12,left:-12,bottom:2},children:[e.jsx(ye,{strokeDasharray:"3 3",stroke:He,vertical:!1}),e.jsx(be,{dataKey:"fy_year",tick:de}),e.jsx(ge,{tick:de,width:48}),e.jsx(fe,{labelFormatter:p=>`FY ${p}`,contentStyle:{fontSize:12}}),e.jsx(Te,{dataKey:"reporting_count",name:"Reporting",radius:[2,2,0,0],children:k.map(p=>e.jsx(Ie,{fill:g!=null&&p.fy_year>=g?"#fcd34d":"#94a3b8"},p.fy_year))})]})})]}),(g!=null||h)&&e.jsxs("div",{className:"mt-3 space-y-1 text-[11px] text-slate-400",children:[g!=null&&e.jsxs("p",{children:[e.jsx("span",{className:"inline-block w-2.5 h-2.5 rounded-sm bg-amber-200 align-middle mr-1.5"}),"Recent fiscal years (FY",g,"+) are under-reported — facilities file cost reports late, so the latest year(s) are incomplete and shaded; they fill in as filings post."]}),h&&e.jsxs("p",{children:[e.jsx("span",{className:"inline-block w-5 border-t-2 border-dashed border-slate-400 align-middle mr-1.5"}),"A dashed line marks years with very few filers (<10% of the usual count) — an early, provisional signal of where current reports are landing, not an established trend."]})]})]})}const _e=t=>t!=null?`${Math.round(t)}%`:"",je=t=>t!=null?`$${t}`:"",Me=[{key:"pct_profitable",label:"% Profitable",fmt:_e},{key:"margin",label:"Median margin",fmt:_e},{key:"median_occupancy",label:"Occupancy",fmt:_e},{key:"median_rev_ppd",label:"Revenue / day",fmt:je},{key:"median_nursing_ppd",label:"Nursing cost / day",fmt:je,invert:!0}
4,{key:"median_cost_ppd",label:"Cost / day",fmt:je,invert:!0}],ft=["pct_profitable","margin","median_occupancy"],oe=5;function $e({includeMixed:t,incomeView:c,dimension:x="size"}){const[_,b]=N.useState(null),[C,y]=N.useState(ft),[I,j]=N.useState(null),S=x==="income",{data:d,isLoading:k,isError:g}=Z({queryKey:["industry-segments",t,_,x],queryFn:()=>Xe(t,_,x),staleTime:300*1e3}),h=d?.tiers||(S?["Q1","Q2","Q3","Q4"]:["Extra-rural","Rural","Semi-urban","Urban","Mega-urban"]),o=d?.tier_pop||{},p=d?.years||[],l=d?.national||{},E=c==="operating"?"median_op_margin":"median_margin",$=c==="operating"?"pct_profitable":"pct_profitable_net",V=a=>a==="margin"?E:a==="pct_profitable"?$:a,P=(a,u)=>a?a[V(u)]:null,z=Me.filter(a=>C.includes(a.key)),D=a=>y(u=>u.includes(a)?u.length>1?u.filter(v=>v!==a):u:[...u,a]),Y=(a,u)=>j(v=>v&&v.metric===a&&v.tier===u?{metric:a,tier:u,dir:v.dir==="desc"?"asc":"desc"}:{metric:a,tier:u,dir:"desc"}),T=a=>{const u=[];for(const F of d?.states||[])for(const R of h){const O=F.cells[R];if(!O||O.n<oe)continue;const A=P(O,a.key);A!=null&&u.push(A)}u.sort((F,R)=>F-R);const v=u.length;return F=>{if(F==null||v===0)return;let R=0;for(;R<v&&u[R]<F;)R++;let O=v>1?R/(v-1):.5;return a.invert&&(O=1-O),`rgba(2,132,199,${(.06+.68*O).toFixed(3)})`}},w=Object.fromEntries(z.map(a=>[a.key,T(a)])),U=a=>{let u=1/0,v=-1/0;for(const F of d?.states||[])for(const R of h){const O=F.cells[R];if(!O||O.n<oe)continue;const A=P(O,a.key);A!=null&&(A<u&&(u=A),A>v&&(v=A))}return v>=u?{min:u,max:v}:null},r=Object.fromEntries(z.map(a=>[a.key,U(a)]));let i=d?.states||[];if(I){const{metric:a,tier:u,dir:v}=I;i=[...i].sort((F,R)=>{const O=P(F.cells[u],a),A=P(R.cells[u],a);return O==null?1:A==null?-1:v==="asc"?O-A:A-O})}const m=()=>{const u=[["State","Tier","n","Pct_Profitable_Op","Pct_Profitable_Net","Rev_PPD","Nursing_PPD","Cost_PPD","Occupancy","Net_Margin","Op_Margin"].join(",")];for(const O of d?.states||[])for(const A of h){const G=O.cells[A];G&&u.push([O.state,A,G.n,G.pct_profitable??"",G.pct_profitable_net??"",G.median_rev_ppd??"",G.median_nursing_ppd??"",G.median_cost_ppd??"",G.median_occupancy??"",G.median_margin??"",G.median_op_margin??""].join(","))}const v=new Blob([u.join(`
5`)],{type:"text/csv"}),F=URL.createObjectURL(v),R=document.createElement("a");R.href=F,R.download=`snf_market_${S?"income":"size"}_${_||"latest"}.csv`,R.click(),URL.revokeObjectURL(F)},M=z[0]?.key,n=(a,u,v,F)=>{const R=P(a,u.key),O=!!a&&a.n<oe;return e.jsx("td",{className:"px-2 py-1.5 text-center tabular-nums border-b border-slate-100",style:{backgroundColor:O?void 0:w[u.key]?.(R)},title:a?`${u.label}: ${u.fmt(R)} (n=${a.n})${O?" — small sample":""}`:"no data",children:R!=null?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:O?"text-slate-400 italic":"font-medium",children:u.fmt(R)}),v&&e.jsxs("span",{className:"text-slate-500 text-[11px] ml-0.5",children:["·",a.n]})]}):e.jsx("span",{className:"text-slate-300",children:"—"})},u.key+F)},q={width:"16px",minWidth:"16px"};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3 mb-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-xs text-slate-500",children:"Fiscal year"}),e.jsxs("select",{value:_??"",onChange:a=>b(a.target.value?Number(a.target.value):null),className:"text-xs border border-slate-200 rounded-md px-2 py-1 bg-white text-slate-700",children:[e.jsx("option",{value:"",children:"Latest (most recent report)"}),p.map(a=>e.jsxs("option",{value:a,children:["FY",a]},a))]})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-wrap",children:[e.jsx("span",{className:"text-xs text-slate-500 mr-1",children:"Metrics"}),Me.map(a=>e.jsx("button",{onClick:()=>D(a.key),className:`px-2.5 py-1 text-xs font-medium rounded-md border transition-colors ${C.includes(a.key)?"bg-sky-600 text-white border-sky-600":"bg-white text-slate-600 border-slate-200 hover:bg-slate-50"}`,children:a.label},a.key))]}),e.jsxs("button",{onClick:m,className:"ml-auto flex items-center gap-1.5 text-xs text-slate-600 hover:text-sky-600 transition-colors",children:[e.jsx(se,{size:13})," Export CSV"]})]}),k&&e.jsx("div",{className:"text-sm text-slate-400 py-8 text-center",children:"Loading…"}),g&&e.jsxs("div",{className:"text-sm text-red-500 py-8 text-center",children:["Could not load the ",S?"market-income":"market-size"," heatmap."]}),!k&&!g&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex flex-wrap items-center gap-x-5 gap-y-1.5 mb-2",children:z.map(a=>{const u=r[a.key],v=a.invert?"linear-gradient(to right, rgba(2,132,199,0.74), rgba(2,132,199,0.06))":"linear-gradient(to right, rgba(2,132,199,0.06), rgba(2,132,199,0.74))";return e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-slate-500",children:[e.jsx("span",{className:"font-medium text-slate-600",children:a.key==="margin"?`Margin (${c==="operating"?"Op":"Net"})`:a.label}),e.jsx("span",{className:"tabular-nums",children:u?a.fmt(u.min):""}
5),e.jsx("span",{className:"inline-block h-2.5 w-14 rounded-sm border border-slate-200",style:{background:v}}),e.jsx("span",{className:"tabular-nums",children:u?a.fmt(u.max):""})]},a.key)})}),e.jsx("div",{className:"bg-white border border-slate-200 rounded-xl overflow-hidden shadow-sm w-fit max-w-full",children:e.jsx("div",{className:"overflow-x-auto max-h-[70vh] overflow-y-auto",children:e.jsxs("table",{className:"text-[12px] border-separate border-spacing-0",children:[e.jsxs("thead",{children:[e.jsxs("tr",{className:"bg-slate-50",children:[e.jsx("th",{rowSpan:2,onClick:()=>j(null),role:"button",tabIndex:0,onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),j(null))},"aria-label":"Reset sort to alphabetical",className:"sticky top-0 left-0 z-30 bg-slate-50 px-3 py-2 text-left font-semibold uppercase tracking-wide text-slate-500 border-b border-slate-200 cursor-pointer select-none align-bottom",children:"State"}),z.map((a,u)=>e.jsxs(N.Fragment,{children:[u>0&&e.jsx("th",{"aria-hidden":!0,style:q,className:"sticky top-0 z-10 bg-white border-b border-slate-100"}),e.jsx("th",{colSpan:h.length,className:"sticky top-0 z-10 bg-slate-50 px-2 pt-2 pb-1 text-center font-semibold text-slate-600 border-b border-slate-100 whitespace-nowrap",children:a.key==="margin"?`Median margin (${c==="operating"?"Operating":"Net"})`:a.label})]},a.key))]}),e.jsx("tr",{className:"bg-slate-50",children:z.map((a,u)=>e.jsxs(N.Fragment,{children:[u>0&&e.jsx("th",{"aria-hidden":!0,style:q,className:"sticky top-[33px] z-10 bg-white border-b border-slate-200"}),h.map(v=>{const F=I&&I.metric===a.key&&I.tier===v;return e.jsx("th",{"aria-sort":F?I.dir==="asc"?"ascending":"descending":"none",className:"sticky top-[33px] z-10 bg-slate-50 border-b border-slate-200 whitespace-nowrap p-0",children:e.jsxs("button",{type:"button",onClick:()=>Y(a.key,v),title:`Sort states by ${a.label} · ${v}`,className:`w-full px-2 pb-2 pt-1 flex flex-col items-center bg-transparent font-semibold select-none cursor-pointer hover:bg-slate-100 transition-colors ${F?"text-sky-700":"text-slate-500"}`,children:[e.jsxs("span",{children:[v,F&&e.jsx("span",{className:"ml-0.5",children:I.dir==="asc"?"▲":"▼"})]}),e.jsx("span",{className:"text-[10px] font-normal text-slate-400",children:o[v]})]})},a.key+v)})]},a.key))})]}),e.jsxs("tbody",{className:"text-slate-800",children:[i.map(a=>e.jsxs("tr",{className:"hover:bg-sky-50/40",children:[e.jsx("td",{className:"sticky left-0 z-10 bg-white px-3 py-1.5 font-semibold text-slate-700 border-b border-slate-100",children:a.state}),z.map((u,v)=>e.jsxs(N.Fragment,{children:[v>0&&e.jsx("td",{"aria-hidden":!0,style:q,className:"border-b border-slate-100"}),h.map(F=>n(a.cells[F],u,u.key===M,F))]},u.key))]},a.state)),e.jsxs("tr",{className:"bg-slate-100 font-semibold",children:[e.jsx("td",{className:"sticky left-0 z-10 bg-slate-100 px-3 py-2 text-slate-700 border-t border-slate-300",children:"U.S."}),z.map((a,u)=>e.jsxs(N.Fragment,{children:[u>0&&e.jsx("td",{"aria-hidden":!0,style:q,className:"bg-white border-t border-slate-300"}),h.map(v=>{const F=l[v],R=P(F,a.key);return e.jsx("td",{className:"px-2 py-2 text-center tabular-nums border-t border-slate-300",title:F?`U.S. · ${a.label} · ${v}: ${a.fmt(R)} (n=${F.n})`:"",children:R!=null?e.jsxs(e.Fragment,{children:[a.fmt(R),a.key===M&&e.jsxs("span",{className:"text-slate-500 text-[11px] ml-0.5 font-normal",children:["·",F.n]})]}):"—"},a.key+v)})]},a.key))]})]})]})})})]}),e.jsxs("p",{className:"text-[11px] text-slate-400 mt-2",children:["Freestanding SNFs by state and ",S?"county median household-income quartile, computed within each state (Q1 = that state’s lowest-income quarter of SNFs; the U.S. row pools each state’s Q1, Q2, …). Quartiles let you read down a state row to see how profitability tracks local income, holding the state’s Medicaid rates and rules constant":"county-population tier",". Shaded per block: darker = higher, except Cost / day and Nursing cost / day where darker = lower. Cells with fewer than ",oe," facilities are muted and left out of the color scale (small sample). ·n = SNFs with a ",_?`FY${_}`:"recent"," cost report (shown once per row). Click a tier to sort — click again to flip direction; margin uses the ",c==="operating"?"Operating":"Net"," Income basis."]})]})}const pe={fontSize:11,fill:"#64748b"},Ke="#f1f5f9",_t=[t=>Math.floor(t-Math.max(1,Math.abs(t)*.08)),t=>Math.ceil(t+Math.max(1,Math.abs(t)*.08))],ne=t=>t==null?"":`${t}%`,Fe=t=>
5t==null?"":`$${Math.round(t).toLocaleString()}`,jt=t=>t==null?"":`${Math.round(t)}`,vt=t=>t==null?"":`$${(t/1e6).toFixed(1)}M`,Re={title:"% Profitable — net vs. operating",fmt:ne,series:[{key:"pct_profitable_net",name:"Net (net income > 0)",color:"#0284c7"},{key:"pct_profitable",name:"Operating (op margin > 0)",color:"#f59e0b"}]},Nt={hospital:[Re,{title:"Median margin — net vs. operating",fmt:ne,zeroLine:!0,series:[{key:"median_margin",name:"Net",color:"#0284c7"},{key:"median_op_margin",name:"Operating",color:"#f59e0b"}]},{title:"Median occupancy",fmt:ne,series:[{key:"median_occupancy",name:"Occupancy",color:"#0284c7"}]},{title:"Median cost per day",fmt:Fe,series:[{key:"median_cost_per_day",name:"Cost / day",color:"#0284c7"}]},{title:"Median Medicare day mix",fmt:ne,series:[{key:"median_medicare_day_pct",name:"Medicare days",color:"#0284c7"}]}],home_health:[Re,{title:"Median margin — net vs. operating",fmt:ne,zeroLine:!0,series:[{key:"median_margin",name:"Net",color:"#0284c7"},{key:"median_op_margin",name:"Operating",color:"#f59e0b"}]},{title:"Median cost per visit",fmt:Fe,series:[{key:"median_cost_per_visit",name:"Cost / visit",color:"#0284c7"}]},{title:"Median visits per patient",fmt:jt,series:[{key:"median_visits_per_patient",name:"Visits / patient",color:"#0284c7"}]},{title:"Median net revenue",fmt:vt,series:[{key:"median_revenue",name:"Net revenue",color:"#0284c7"}]}]},kt={hospital:["fy_year","reporting_count","pct_profitable_net","pct_profitable","median_margin","median_op_margin","median_occupancy","median_cost_per_day","median_medicare_day_pct"],home_health:["fy_year","reporting_count","pct_profitable_net","pct_profitable","median_margin","median_op_margin","median_cost_per_visit","median_visits_per_patient","median_revenue"]};function Oe({title:t,children:c}){return e.jsxs("div",{className:"bg-white border border-slate-200 rounded-xl p-4",children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-700 mb-2",children:t}),e.jsx("div",{className:"h-52",children:e.jsx(Ee,{width:"100%",height:"100%",children:c})})]})}const wt=t=>({active:c,payload:x,label:_})=>{if(!c||!x?.length)return null;const b=x.filter(C=>C.value!=null);return b.length?e.jsxs("div",{className:"rounded-md border border-slate-200 bg-white px-2 py-1.5 text-xs shadow-sm",children:[e.jsxs("div",{className:"mb-0.5 font-medium text-slate-500",children:["FY ",_]}),b.map(C=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-sm",style:{background:C.color}}),e.jsx("span",{className:"text-slate-600",children:C.name})]}),e.jsx("span",{className:"ml-auto font-medium text-slate-800",children:t(C.value)})]},C.name))]}):null};function Ct({data:t,series:c,fmt:x,zeroLine:_}){return e.jsxs(Le,{data:t,margin:{top:6,right:12,left:-12,bottom:2},children:[e.jsx(ye,{strokeDasharray:"3 3",stroke:Ke,vertical:!1}),e.jsx(be,{dataKey:"fy_year",tick:pe}),e.jsx(ge,{tick:pe,width:48,tickFormatter:x,domain:_t}),e.jsx(fe,{content:wt(x)}),c.length>1&&e.jsx(ze,{wrapperStyle:{fontSize:11},iconType:"plainline"}),_&&e.jsx(Ae,{y:0,stroke:"#cbd5e1",strokeDasharray:"2 2"}),c.map(b=>e.jsx(Ne,{type:"monotone",dataKey:b.key,name:b.name,stroke:b.color,strokeWidth:2,dot:{r:2.5},activeDot:{r:4}},b.key))]})}function St({setting:t,geo:c,states:x=[],onSelectGeo:_}){const b=t==="hospital",{data:C,isLoading:y,isError:I}=Z({queryKey:["industry-costreport-trends",t,c||"US"],queryFn:()=>b?Je(c):Ze(c),staleTime:1e3*60*60}),j=C?.trends??[];if(y)return e.jsx("div",{className:"py-10 text-center text-sm text-slate-400",children:"Loading trends…"});if(I||!j.length)return e.jsx("div",{className:"py-10 text-center text-sm text-slate-400",children:"No trend data for this selection."});const S=()=>{const d=kt[t],k=d.join(",")+`
6`,g=j.map(h=>d.map(o=>h[o]??"").join(",")).join(`
7`);re(`${t}_trends_${(c||"national").toLowerCase()}.csv`,k+g)};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 mb-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"text-base font-bold text-slate-800",children:"Trends —"}),_?e.jsxs("select",{value:c||"",onChange:d=>_(d.target.value||null),className:"text-sm font-medium text-slate-700 border border-slate-300 rounded-lg px-2 py-1 bg-white focus:outline-none focus:ring-1 focus:ring-sky-400",children:[e.jsx("option",{value:"",children:"National"}),[...x].sort().map(d=>e.jsx("option",{value:d,children:d},d))]}):e.jsx("span",{className:"text-base font-bold text-slate-800",children:c||"National"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-[11px] text-slate-400",children:"Cost-report fiscal year (not calendar)"}),e.jsxs("button",{onClick:S,className:"flex items-center gap-1 text-xs text-slate-600 hover:text-sky-600 transition-colors",children:[e.jsx(se,{size:13})," CSV"]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[Nt[t].map(d=>e.jsx(Oe,{title:d.title,children:e.jsx(Ct,{data:j,series:d.series,fmt:d.fmt,zeroLine:d.zeroLine})},d.title)),e.jsx(Oe,{title:b?"Hospitals reporting":"Agencies reporting",children:e.jsxs(De,{data:j,margin:{top:6,right:12,left:-12,bottom:2},children:[e.jsx(ye,{strokeDasharray:"3 3",stroke:Ke,vertical:!1}),e.jsx(be,{dataKey:"fy_year",tick:pe}),e.jsx(ge,{tick:pe,width:48}),e.jsx(fe,{labelFormatter:d=>`FY ${d}`,contentStyle:{fontSize:12}}),e.jsx(Te,{dataKey:"reporting_count",name:"Reporting",radius:[2,2,0,0],children:j.map(d=>e.jsx(Ie,{fill:"#94a3b8"},d.fy_year))})]})})]}),e.jsxs("p",{className:"mt-3 text-[11px] text-slate-400",children:["Median across providers with a cost report each fiscal year (CMS HCRIS ",b?"Form 2552-10":"Form 1728-20",").",!b&&" Revenue is a median, not a sum, since chains file consolidated financials."]})]})}const Ye=[{key:"departments",label:"Department cost PPD",note:"Median cost per patient day by department. Independent medians — they will not sum exactly to Cost PPD.",columns:[{key:"dept_nursing_ppd",label:"Nursing",fmt:"money2"},{key:"dept_admin_ppd",label:"Admin & Gen",fmt:"money2"},{key:"dept_benefits_ppd",label:"Benefits",fmt:"money2"},{key:"dept_capital_ppd",label:"Capital",fmt:"money2",title:"Building and equipment"},{key:"dept_dietary_ppd",label:"Dietary",fmt:"money2"},{key:"dept_therapy_ppd",label:"Therapy",fmt:"money2",title:"PT / OT / SLP"},{key:"dept_nursing_admin_ppd",label:"Nursing Admin",fmt:"money2"},{key:"dept_plant_ops_ppd",label:"Plant Ops",fmt:"money2",title:"Operations & maintenance"},{key:"dept_housekeeping_ppd",label:"Housekeeping",fmt:"money2"},{key:"dept_drugs_ppd",label:"Drugs",fmt:"money2"},{key:"dept_social_service_ppd",label:"Social Svc",fmt:"money2"},{key:"dept_laundry_ppd",label:"Laundry",fmt:"money2",title:"Laundry & linen"}]},{key:"receivables",label:"Receivables",note:"AR is Worksheet G line 4 as filed (gross). Net AR applies the allowance and can be negative where a filer reserves more than it holds — that is their filing, not an error. DSO uses the gross figure.",columns:[{key:"ar_gross",label:"AR",fmt:"money0",title:"Accounts receivable as filed, before the allowance for doubtful accounts."},{key:"ar_net",label:"Net AR",fmt:"money0",title:"AR less the allowance for doubtful accounts. Negative where the reserve exceeds receivables, which 2,956 filings do."},{key:"bad_debt_allowance",label:"Allow. Doubtful",fmt:"money0",title:"Allowance for doubtful accounts (Worksheet G line 6). Reported by about 70% of facilities — a dash means the line was not filed, not that the allowance is zero."}
7,{key:"dso_days",label:"DSO",fmt:"days",title:"Days Sales Outstanding — gross AR divided by average daily revenue. How many days of billing sit on the aging report. Deliberately does NOT net out the allowance: a reserve is a judgement about collectability, not a statement that the invoices stopped being outstanding."}]},{key:"liquidity",label:"Liquidity & working capital",columns:[{key:"days_cash",label:"Days Cash",fmt:"days",title:"Days cash on hand."},{key:"current_ratio",label:"Current Ratio",fmt:"ratio"},{key:"quick_ratio",label:"Quick Ratio",fmt:"ratio",title:"Equal to the current ratio for about 80% of SNFs, which carry almost no inventory. That is expected, not a data error."},{key:"payment_period",label:"Days Payable",fmt:"days",title:"Current liabilities divided by average daily operating expense — days taken to pay suppliers. The payables mirror of DSO."}]},{key:"operations",label:"Operations",columns:[{key:"personnel_pct",label:"Personnel %",fmt:"pct",title:"Personnel expense as a share of revenue. Labour is the dominant SNF cost, so this is the cost-structure ratio that holds up regardless of who owns the building."},{key:"medicare_alos",label:"Medicare ALOS",fmt:"days",title:"Median average length of stay for Medicare residents — a post-acute population, so far shorter than Medicaid."},{key:"medicaid_alos",label:"Medicaid ALOS",fmt:"days",title:"Median average length of stay for Medicaid residents. Long-stay custodial care, so figures in the hundreds of days are normal."},{key:"discharges",label:"Discharges",fmt:"int",title:"Median total annual discharges per facility."}]}],Mt=new Set(["ar_gross","ar_net","bad_debt_allowance","dso_days","days_cash","current_ratio","quick_ratio","payment_period"]),$t=Ye.flatMap(t=>t.columns),Ft=Object.fromEntries($t.map(t=>[t.key,t])),Rt=[{key:"snf_count",label:"SNFs"},{key:"total_beds",label:"Beds"},{key:"avg_beds",label:"Avg Beds"},{key:"median_occupancy",label:"Occupancy"},{key:"total_revenue",label:"Revenue"},{key:"income",label:"Income"},{key:"margin",label:"Margin"},{key:"median_rev_ppd",label:"Rev PPD"},{key:"median_cost_ppd",label:"Cost PPD"},{key:"avg_medicare_pct",label:"Medicare"},{key:"avg_medicaid_pct",label:"Medicaid"},{key:"pct_profitable",label:"Profitable"}],Ot=[{key:"citytown",label:"City"},{key:"overall_rating",label:"Stars"},{key:"beds",label:"Beds"},{key:"occupancy",label:"Occ"},{key:"fy_year",label:"FY"},{key:"total_revenue",label:"Revenue"},{key:"income",label:"Income"},{key:"margin",label:"Margin"},{key:"rev_ppd",label:"Rev PPD"},{key:"cost_ppd",label:"Cost PPD"},{key:"medicare_pct",label:"Medicare"},{key:"medicaid_pct",label:"Medicaid"},{key:"chain_name",label:"Chain"}];function Ue(){const[t,c]=N.useState([]),[x,_]=N.useState([]),b=N.useMemo(()=>t.map(S=>Ft[S]).filter(Boolean),[t]);return{extraCols:t,setExtraCols:c,activeExtras:b,toggleCol:S=>c(d=>d.includes(S)?d.filter(k=>k!==S):[...d,S]),hiddenCore:x,setHiddenCore:_,toggleCore:S=>_(d=>d.includes(S)?d.filter(k=>k!==S):[...d,S]),show:S=>!x.includes(S),reset:()=>{c([]),_([])}}}function qe({extraCols:t,activeExtras:c,toggleCol:x,hiddenCore:_,toggleCore:b,reset:C,coreColumns:y=[],onExpand:I,onClose:j,grainNote:S,title:d}){const[k,g]=N.useState(!1);return e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2 flex-shrink-0",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[d&&e.jsx("p",{className:"text-sm font-semibold text-slate-800 truncate mr-1",children:d}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{onClick:()=>g(h=>!h),"aria-expanded":k,className:`inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-md border transition-colors ${c.length||_.length?"bg-sky-50 text-sky-700 border-sky-200":"bg-white text-slate-600 border-slate-200 hover:bg-slate-50"}`,children:[e.jsx(pt,{size:13}),"Columns",c.length?` +${c.length}`:"",_.length?` −${_.length}`:"",k?e.jsx(xe,{size:11}):e.jsx(he,{size:11})]}),k&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-30",onClick:()=>g(!1)}),e.jsxs("div",{className:"absolute z-40 left-0 top-full mt-1 w-[22rem] max-w-[calc(100vw-1.5rem)] max-h-[26rem] overflow-y-auto bg-white border border-slate-200 rounded-lg shadow-xl p-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("p",{className:"text-xs font-semibold text-slate-700",children:"Add columns"}),e.jsx("button",{onClick:C,disabled:!c.length&&!_.length,className:"text-[11px] text-slate-500 hover:text-sky-600 disabled:text-slate-300 disabled:cursor-default",children:"Reset"})]}),S&&e.jsx("p",{className:"text-[11px] text-slate-500 leading-snug mb-2",children:S}),y.length>0&&e.jsxs("div",{className:"mb-2.5 pb-2.5 border-b border-slate-100",children:[e.jsx("p",{className:"text-[11px] font-semibold text-slate-600 uppercase tracking-wide mb-1",children:"Shown by default"}),e.jsx("p",{className:"text-[10px] text-slate-400 leading-snug mb-1",children:"Uncheck to hide and free up width."}),e.jsx("div",{className:"grid grid-cols-2 gap-x-2 gap-y-0.5",children:y.map(h=>e.jsxs("label",{className:"flex items-center gap-1.5 text-[12px] text-slate-700 cursor-pointer hover:text-sky-700 py-0.5",children:[e.jsx("input",{type:"checkbox",className:"rounded border-slate-300",checked:!_.includes(h.key),onChange:()=>b(h.key)}),h.label]},h.key))})]}),Ye.map(h=>e.jsxs("div",{className:"mb-2.5 last:mb-0",children:[e.jsx("p",{className:"text-[11px] font-semibold text-slate-600 uppercase tracking-wide mb-1",children:h.label}),h.note&&e.jsx("p",{className:"text-[10px] text-slate-400 leading-snug mb-1",children:h.note}),e.jsx("div",{className:"grid grid-cols-2 gap-x-2 gap-y-0.5",children:h.columns.map(o=>e.jsxs("label",{title:o.title,className:"flex items-center gap-1.5 text-[12px] text-slate-700 cursor-pointer hover:text-sky-700 py-0.5",children:[e.jsx("input",{type:"checkbox",className:"rounded border-slate-300",checked:t.includes(o.key),onChange:()=>x(o.key)}),o.label]},o.key))})]},h.key))]})]})]})]}),I&&e.jsxs("button",{onClick:I,className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-md border bg-white text-slate-600 border-slate-200 hover:bg-slate-50 transition-colors flex-shrink-0",title:"Open the table full screen",children:[e.jsx(mt,{size:13})," Expand"]}),j&&e.jsxs("button",{onClick:j,className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-md border bg-white text-slate-600 border-slate-200 hover:bg-slate-50 transition-colors flex-shrink-0",children:[e.jsx(et,{size:13})," Close"]})]})}const ve=t=>t!=null?`$${(t/1e9).toFixed(1)}B`:"—",me=t=>t!=null?`$${(t/1e6).toFixed(0)}M`:"—",W=t=>
7t!=null?`$${Math.round(t).toLocaleString()}`:"—",K=t=>t!=null?`${t.toFixed(1)}%`:"—",H=t=>t!=null?t.toLocaleString():"—",Pt=t=>t!=null?`$${t.toFixed(2)}`:"—",Dt=t=>t!=null?t.toFixed(2):"—",Tt=t=>t!=null?t.toFixed(1):"—",It=t=>t!=null?`$${Math.round(t).toLocaleString()}`:"—",Et=()=>e.jsx("span",{className:"text-[11px] italic text-slate-400",title:"This facility filed its parent organization's balance sheet, so per-facility receivable and liquidity figures are not meaningful.",children:"Suppressed"}),Ve={money0:It,money2:Pt,ratio:Dt,days:Tt,pct:t=>t!=null?`${t.toFixed(1)}%`:"—",int:t=>t!=null?t.toLocaleString():"—"},X=t=>{if(t==null)return"—";const c=Math.abs(t),x=t<0?"-":"";return c>=1e9?x+`$${(c/1e9).toFixed(1)}B`:c>=1e7?x+`$${(c/1e6).toFixed(0)}M`:c>=1e6?x+`$${(c/1e6).toFixed(1)}M`:x+`$${Math.round(c/1e3)}K`};function Zt(){const t=Pe(),[c]=tt(),[x,_]=N.useState(()=>{const s=c.get("setting");return["snf","hospital","home_health"].includes(s)?s:"snf"}),[b,C]=N.useState(!0),{data:y,isLoading:I}=Z({queryKey:["industry-overview",b],queryFn:()=>nt(!b),staleTime:1e3*60*60,enabled:x==="snf"}),[j,S]=N.useState("total_revenue"),[d,k]=N.useState("desc"),[g,h]=N.useState("net"),o=Ue(),{activeExtras:p,show:l}=o,[E,$]=N.useState(!1),V=Be(()=>$(!1),{enabled:E}),[P,z]=N.useState(!1),[D,Y]=N.useState(!1),[T,w]=N.useState(null),[U,r]=N.useState("snapshot"),i=N.useMemo(()=>y?.states?[...y.states].sort((s,Q)=>{let L=s[j],f=Q[j];return L==null&&f==null?0:L==null?1:f==null?-1:typeof L=="string"||typeof f=="string"?d==="desc"?String(f).localeCompare(String(L)):String(L).localeCompare(String(f)):d==="desc"?f-L:L-f}):[],[y,j,d]),m=y?.national||{};function M(s){j===s?k(Q=>Q==="desc"?"asc":"desc"):(S(s),k("desc"))}function n({col:s,children:Q,align:L="right",title:f}){const ee=j===s;return e.jsx("th",{title:f,className:`px-3 py-2 text-${L} cursor-pointer select-none hover:text-sky-600 transition-colors ${ee?"text-sky-600":"text-slate-600"}`,onClick:()=>M(s),children:e.jsxs("span",{className:"inline-flex items-center gap-0.5",children:[Q,ee&&(d==="desc"?e.jsx(he,{size:10}):e.jsx(xe,{size:10}))]})})}const q=s=>g==="operating"?s.operating_income:s.net_income,a=s=>g==="operating"?s.median_op_margin:s.median_margin,u=()=>g==="operating"?m.operating_income:m.net_income,v=()=>g==="operating"?m.median_op_margin:m.median_margin,F=g==="operating"?"Operating Income":"Net Income",R=g==="operating"?"Op Margin":"Net Margin",O=s=>g==="operating"?s.pct_profitable:s.pct_profitable_net,A=g==="operating"?"operating margin > 0":"net income > 0",G=s=>g==="operating"?s.prof_delta_op:s.prof_delta_net,le=(s,Q="")=>{if(s==null)return e.jsx("span",{className:"text-slate-300",children:"—"});const L=s>0?"text-emerald-700":s<0?"text-rose-700":"text-slate-400",f=s>0?"▲":s<0?"▼":"";return e.jsxs("span",{className:`tabular-nums ${L}`,children:[f,s>0?"+":"",s,Q]})},J=P&&U==="snapshot",B=T&&i.find(s=>s.state===T)||m,ke=s=>g==="operating"?s.overall_op_margin_pct??(s.total_revenue?s.operating_income/s.total_revenue*100:null):s.overall_margin_pct??(s.total_revenue?s.net_income/s.total_revenue*100:null),Ge=s=>s.occupancy_pct!=null?s.occupancy_pct:s.median_occupancy;function Qe(){if(!i.length)return;const s=[["State",f=>f.state],...l("snf_count")?[["SNFs",f=>f.snf_count]]:[],...l("total_beds")?[["Beds",f=>f.total_beds]]:[],...l("avg_beds")?[["Avg Beds",f=>f.avg_beds??""]]:[],...l("median_occupancy")?[["Occupancy",f=>f.median_occupancy??""]]:[],["Reporting",f=>f.reporting],...l("total_revenue")?[["Total Revenue",f=>f.total_revenue],["Total Expenses",f=>f.total_expenses]]:[],...l("income")?[[F,f=>q(f)]]:[],...l("margin")?[[`Median ${R} %`,f=>a(f)??""]]:[],...l("median_rev_ppd")?[["Median Rev PPD",f=>f.median_rev_ppd??""]]:[],...l("median_cost_ppd")?[["Median Cost PPD",f=>f.median_cost_ppd??""]]:[],...l("avg_medicare_pct")?[["Medicare %",f=>f.avg_medicare_pct??""]]:[],...l("avg_medicaid_pct")?[["Medicaid %",f=>f.avg_medicaid_pct??""]]:[],...l("pct_profitable")?[[`% Profitable (${A})`,f=>O(f)??""]]:[],...p.map(f=>[`Median ${f.label}`,ee=>ee[f.key]??""])],Q=s.map(f=>f[0]).join(",")+`
8`,L=i.map(f=>s.map(ee=>ee[1](f)).join(",")).join(`
9`);re(`snf_industry_${g}.csv`,Q+L)}return I?e.jsx("div",{className:"min-h-screen bg-slate-50 flex items-center justify-center",children:e.jsx(ue,{size:24,className:"animate-spin text-sky-600"})}):x!=="snf"?e.jsx("div",{className:"min-h-screen bg-slate-50 text-slate-700",children:e.jsxs("div",{className:"max-w-7xl mx-auto px-4 py-8",children:[e.jsx(we,{title:"Industry Financials",current:x,onSetting:_,subt
9itle:`CMS ${x==="hospital"?"Form 2552-10":"Form 1728-20"} cost reports · national & state medians`}),e.jsx(zt,{setting:x}),x==="hospital"&&e.jsx("div",{className:"mt-6 pt-4 border-t border-slate-100",children:e.jsx("button",{onClick:()=>t("/hospital-fa"),className:"inline-flex items-center gap-1 text-sm text-sky-700 hover:text-sky-800 hover:underline",title:"Reference: hospital charity-care / financial-assistance policies by hospital",children:"Hospital financial-assistance policies ↗"})})]})}):e.jsx("div",{className:"min-h-screen bg-slate-50 text-slate-700",children:e.jsxs("div",{className:"max-w-7xl mx-auto px-4 py-8",children:[e.jsxs(we,{title:"Industry Financials",current:x,onSetting:_,subtitle:`${H(m.snf_count)} facilities · ${H(m.reporting)} with cost reports · ${i.length} states`,children:[e.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-slate-600 cursor-pointer select-none",title:"Hospital-based, CCRC, and government facilities have mixed/subsidized cost structures that distort market-rate SNF margins — excluded from all figures by default. Uncheck to include them everywhere.",children:[e.jsx("input",{type:"checkbox",checked:b,onChange:s=>C(s.target.checked),className:"rounded border-slate-300 text-sky-600 focus:ring-sky-500"}),"Exclude hospital / CCRC / gov"]}),U!=="trends"&&e.jsxs("div",{className:"flex rounded-lg overflow-hidden border border-slate-300",children:[e.jsx("button",{onClick:()=>h("net"),className:`px-3 py-1.5 text-xs font-medium ${g==="net"?"bg-sky-600 text-white":"bg-white text-slate-600 hover:text-slate-900"}`,children:"Net Income"}),e.jsx("button",{onClick:()=>h("operating"),className:`px-3 py-1.5 text-xs font-medium ${g==="operating"?"bg-sky-600 text-white":"bg-white text-slate-600 hover:text-slate-900"}`,children:"Operating Income"})]}),U==="snapshot"&&e.jsxs("label",{className:"flex items-center gap-1.5 text-xs text-slate-600 cursor-pointer",title:"Add year-over-year change columns (Δ % profitable, Δ occupancy) — same-store: each facility's latest cost report vs its prior fiscal-year report. Suppressed for cohorts under 15.",children:[e.jsx("input",{type:"checkbox",checked:P,onChange:s=>z(s.target.checked),className:"rounded border-slate-300 text-sky-600 focus:ring-sky-500"}),"vs prior year (Δ)"]}),e.jsxs("button",{onClick:()=>Y(s=>!s),className:"flex items-center gap-1 text-xs text-slate-600 hover:text-sky-600 transition-colors",children:[e.jsx(st,{size:13})," Methodology"]})]}),D&&e.jsxs("div",{className:"bg-white border border-slate-200 rounded-xl p-5 mb-6 text-xs text-slate-600 space-y-2 shadow-sm",children:[e.jsx("h3",{className:"text-sm font-semibold text-slate-700 mb-2",children:"Methodology & Limitations"}),e.jsxs("div",{className:"grid md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-slate-700 mb-1",children:"Net Income (Cost Report)"}),e.jsxs("p",{children:["Uses the ",e.jsx("code",{className:"text-sky-600",children:"net_income"})," field from CMS HCRIS Form 2540-10. Includes operating revenue, operating expenses, ",e.jsx("em",{children:"plus"})," non-operating items: interest expense, depreciation, Medicare cost settlements, and other adjustments. This is the most comprehensive measure but can be volatile due to one-time settlement adjustments."]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-slate-700 mb-1",children:"Operating Income"}),e.jsxs("p",{children:["Calculated as ",e.jsx("code",{className:"text-sky-600",children:"total_revenue - total_expenses"})," from the cost report. Excludes non-operating items. This provides a cleaner view of operational performance but may overstate profitability by omitting real costs like interest and depreciation."]})]})]}),e.jsxs("div",{className:"border-t border-slate-200 pt-2 mt-2",children:[e.jsx("p",{className:"font-semibold text-slate-700 mb-1",children:"Exclusions & Data Quality"}),e.jsxs("ul",{className:"list-disc list-inside space-y-1 text-slate-600",children:[e.jsxs("li",{children:["Hospital-based SNFs, CCRCs, and government-owned facilities are excluded ",e.jsx("strong",{children:"by default"})," — hospital overhead allocation, CCRC cross-subsidies, and tax-funded operating deficits distort market-rate margins. The ",e.jsx("em",{children:"Exclude hospital / CCRC / gov"})," toggle in the header applies to everything (the state/national aggregates, the Trends charts, and the facility drill-through); uncheck it to include them, with HOSP/CCRC/GOV badges in the drill-through."]}),e.jsx("li",{children:"Partial-year cost reports (<180 days) are excluded to avoid skewed annualized figures from facility openings, closings, or ownership changes."}),e.jsx("li",{children:"Facilities with fewer than 20 beds are excluded (micro-facilities with volatile margins)."}),e.jsx("li",{children:"Facilities with expenses > 3x revenue or net losses exceeding total revenue are excluded (data errors)."}),e.jsx("li",{children:"Facilities with net losses exceeding total revenue are excluded as likely data errors."}),e.jsxs("li",{children:["Not all facilities file cost reports — approximately ",m.reporting&&m.snf_count?Math.round(m.reporting/m.snf_count*100):"?","% coverage nationally."]}),e.jsx("li",{children:"Cost reports are self-reported to CMS and are not independently audited."}),e.jsx("li",{children:"Fiscal years vary by facility — the most recent available year per facility is used."}),e.jsx("li",{children:"Cost reports may not capture all expenses (lease/rent payments, management company fees, corporate overhead allocations) that affect true profitability."}),e.jsx("li",{children:"Public company financials (10-K filings) will show different margins due to GAAP accounting standards vs. cost report methodology."})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("h2",{className:"text-xs font-semibold text-slate-500 uppercase tracking-wide",children:T?`${T} — Financial Summary`:"National Financial Summary"}),T&&e.jsxs("button",{onClick:()=>w(null),className:"inline-flex items-center gap-1 text-xs text-sky-600 hover:text-sky-700",children:[e.jsx(ce,{size:12})," Back to national"]})]}),e.jsx("div",{className:"bg-white border border-slate-200 rounded-xl shadow-sm mb-6 overflow-hidden grid grid-cols-2 sm:grid-cols-4 lg:grid-cols-8 [&>div]:px-4 [&>div]:py-3 [&>div]:border-r [&>div]:border-b [&>div]:border-slate-100 lg:[&>div]:border-b-0 [&>div:last-child]:border-r-0",children:[{label:"Total SNFs",value:H(B.snf_count),color:"text-slate-900"},{label:"Total Beds",value:H(B.total_beds),color:"text-slate-900",sub:B.total_beds&&B.snf_count?`${Math.round(B.total_beds/B.snf_count)}
9 avg`:""},{label:"Total Revenue",value:B.total_revenue>1e9?ve(B.total_revenue):me(B.total_revenue),color:"text-slate-900"},{label:F,value:X(q(B)),color:q(B)>=0?"text-slate-700":"text-red-600"},{label:`Median ${R}`,value:K(a(B)),color:a(B)>=0?"text-slate-700":"text-red-600"},{label:`Industry ${R}`,value:K(ke(B)),color:ke(B)>=0?"text-slate-700":"text-red-600"},{label:"% Profitable",value:O(B)!=null?`${O(B)}%`:"—",color:"text-slate-900",sub:A},{label:"Occupancy",value:K(Ge(B)),color:"text-slate-900"}].map(s=>e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] text-slate-500 uppercase tracking-wide whitespace-nowrap",children:s.label}),e.jsx("p",{className:`text-lg font-bold ${s.color} mt-0.5 tabular-nums`,children:s.value}),s.sub&&e.jsx("p",{className:"text-[9px] text-slate-400 leading-tight",children:s.sub})]},s.label))}),e.jsx("div",{className:"flex items-center gap-1 mb-3",children:[["snapshot","Snapshot"],["segments","By market size"],["income","By market income"],["trends","Trends"]].map(([s,Q])=>e.jsx("button",{onClick:()=>r(s),className:`px-3 py-1 text-xs font-medium rounded-md border transition-colors ${U===s?"bg-sky-600 text-white border-sky-600":"bg-white text-slate-600 border-slate-200 hover:bg-slate-50"}`,children:Q},s))}),U==="segments"&&e.jsx($e,{includeMixed:!b,incomeView:g,dimension:"size"}),U==="income"&&e.jsx($e,{includeMixed:!b,incomeView:g,dimension:"income"}),U==="trends"&&e.jsx(gt,{state:T,states:i.map(s=>s.state),onSelectState:w,excludeMixed:b}),U==="snapshot"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[T&&e.jsxs("button",{onClick:()=>w(null),className:"flex items-center gap-1 text-xs text-sky-600 hover:text-sky-700",children:[e.jsx(ce,{size:13})," All States"]}),e.jsx("h2",{className:"text-sm font-semibold text-slate-600 uppercase tracking-wide",children:T?`${T} — Facility Detail`:"State-by-State Breakdown"})]}),!T&&e.jsxs("button",{onClick:Qe,className:"flex items-center gap-1.5 text-xs text-slate-600 hover:text-sky-600 transition-colors",children:[e.jsx(se,{size:13})," Export CSV"]})]}),T?e.jsx(Lt,{state:T,stateData:i.find(s=>s.state===T),incomeView:g,excludeMixed:b,onBack:()=>w(null),showExportTop:!0}):e.jsx(e.Fragment,{children:e.jsxs("div",{ref:E?V:null,role:E?"dialog":void 0,"aria-modal":E?"true":void 0,"aria-label":E?"Industry financials by state, full screen":void 0,className:E?"fixed inset-0 z-50 bg-white flex flex-col p-3 sm:p-4":"",children:[e.jsx(qe,{...o,coreColumns:Rt,onExpand:E?null:()=>$(!0),onClose:E?()=>$(!1):null,title:E?"Industry Financials by State":null,grainNote:"State medians, from the same facilities as the columns already shown."}),e.jsx("div",{className:E?"overflow-auto flex-1 min-h-0 border border-slate-200 rounded-lg":"overflow-x-auto bg-white border border-slate-200 rounded-xl shadow-sm",children:e.jsxs("table",{className:"w-full text-[13px] [&_td]:border-r [&_td]:border-slate-100 [&_th]:border-r [&_th]:border-slate-100 [&_td:last-child]:border-r-0 [&_th:last-child]:border-r-0",children:[e.jsx("thead",{className:"bg-slate-50 border-b border-slate-200",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 text-center font-normal text-slate-400 select-none",title:"Rank in the current sort",children:"#"}),e.jsx(n,{col:"state",align:"left",children:"State"}),l("snf_count")&&e.jsx(n,{col:"snf_count",children:"SNFs"}),l("total_beds")&&e.jsx(n,{col:"total_beds",children:"Beds"}),l("avg_beds")&&e.jsx(n,{col:"avg_beds",children:"Avg Beds"}),l("median_occupancy")&&e.jsx(n,{col:"median_occupancy",children:"Occupancy"}),l("total_revenue")&&e.jsx(n,{col:"total_revenue",children:"Revenue"}),l("income")&&e.jsx(n,{col:g==="operating"?"operating_income":"net_income",children:F}),l("margin")&&e.jsx(n,{col:g==="operating"?"median_op_margin":"median_margin",children:R}),l("median_rev_ppd")&&e.jsx(n,{col:"median_rev_ppd",children:"Rev PPD"}),l("median_cost_ppd")&&e.jsx(n,{col:"median_cost_ppd",children:"Cost PPD"}),l("avg_medicare_pct")&&e.jsx(n,{col:"avg_medicare_pct",children:"Medicare"}),l("avg_medicaid_pct")&&e.jsx(n,{col:"avg_medicaid_pct",children:"Medicaid"}),l("pct_profitable")&&e.jsx(n,{col:g==="operating"?"pct_profitable":"pct_profitable_net",children:"Profitable"}),J&&e.jsx(n,{col:g==="operating"?"prof_delta_op":"prof_delta_net",title:"SAME-STORE change in % profitable: only facilities with BOTH a latest and a prior fiscal-year cost report (others excluded). This is why it differs from the by-year Trends graph, which uses all facilities that filed each year.",children:"Δ Prof*"}),J&&e.jsx(n,{col:"occupancy_delta",title:"SAME-STORE change in occupancy vs each facility's own prior fiscal-year cost report.",children:"Δ Occ*"}),p.map(s=>e.jsx(n,{col:s.key,title:s.title,children:s.label},s.key))]})}),e.jsx("tbody",{className:"divide-y divide-slate-200 text-slate-800",children:i.map((s,Q)=>e.jsxs("tr",{className:"even:bg-slate-50 hover:bg-sky-50 transition-colors cursor-pointer",onClick:()=>w(s.state),role:"button",tabIndex:0,onKeyDown:L=>{(L.key==="Enter"||L.key===" ")&&(L.preventDefault(),w(s.state))},children:[e.jsx("td",{className:"px-3 py-2 text-center tabular-nums text-slate-400",children:Q+1}),e.jsx("td",{className:"px-3 py-2 font-semibold text-sky-600 hover:text-sky-700",children:s.state}),l("snf_count")&&e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:H(s.snf_count)}
9),l("total_beds")&&e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:H(s.total_beds)}),l("avg_beds")&&e.jsx("td",{className:"px-3 py-2 text-right tabular-nums text-slate-600",children:s.avg_beds||"—"}),l("median_occupancy")&&e.jsx("td",{className:"px-3 py-2 text-right tabular-nums text-slate-700",children:s.median_occupancy!=null?`${s.median_occupancy.toFixed(0)}%`:"—"}),l("total_revenue")&&e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:s.total_revenue>1e9?ve(s.total_revenue):me(s.total_revenue)}),l("income")&&e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:e.jsx("span",{className:q(s)>=0?"text-slate-700":"text-red-600",children:X(q(s))})}),l("margin")&&e.jsx("td",{className:"px-3 py-2 text-right",children:e.jsx("span",{className:a(s)>=0?"text-slate-700":"text-red-600",children:K(a(s))})}),l("median_rev_ppd")&&e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:W(s.median_rev_ppd)}),l("median_cost_ppd")&&e.jsx("td",{className:"px-3 py-2 text-right tabular-nums text-slate-600",children:W(s.median_cost_ppd)}),l("avg_medicare_pct")&&e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:s.avg_medicare_pct!=null?`${s.avg_medicare_pct.toFixed(0)}%`:"—"}),l("avg_medicaid_pct")&&e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:s.avg_medicaid_pct!=null?`${s.avg_medicaid_pct.toFixed(0)}%`:"—"}),l("pct_profitable")&&e.jsx("td",{className:"px-3 py-2 text-right tabular-nums text-slate-700",children:O(s)!=null?`${O(s)}%`:"—"}),J&&e.jsx("td",{className:"px-3 py-2 text-right",children:le(G(s),"pp")}),J&&e.jsx("td",{className:"px-3 py-2 text-right",children:le(s.occupancy_delta,"pp")}),p.map(L=>e.jsx("td",{className:"px-3 py-2 text-right tabular-nums text-slate-600",children:Ve[L.fmt](s[L.key])},L.key))]},s.state))}),e.jsx("tfoot",{className:"bg-slate-100 border-t-2 border-slate-300",children:e.jsxs("tr",{className:"text-slate-900 font-semibold",children:[e.jsx("td",{className:"px-3 py-2.5"}),e.jsx("td",{className:"px-3 py-2.5",children:"NATIONAL"}),l("snf_count")&&e.jsx("td",{className:"px-3 py-2.5 text-right tabular-nums",children:H(m.snf_count)}),l("total_beds")&&e.jsx("td",{className:"px-3 py-2.5 text-right tabular-nums",children:H(m.total_beds)}),l("avg_beds")&&e.jsx("td",{className:"px-3 py-2.5 text-right tabular-nums text-slate-600",children:m.total_beds&&m.snf_count?Math.round(m.total_beds/m.snf_count):"—"}),l("median_occupancy")&&e.jsx("td",{className:"px-3 py-2.5 text-right text-sky-600",children:K(m.occupancy_pct)}),l("total_revenue")&&e.jsx("td",{className:"px-3 py-2.5 text-right tabular-nums",children:ve(m.total_revenue)}),l("income")&&e.jsx("td",{className:"px-3 py-2.5 text-right tabular-nums",children:e.jsx("span",{className:u()>=0?"text-slate-700":"text-red-600",children:X(u())})}),l("margin")&&e.jsx("td",{className:"px-3 py-2.5 text-right",children:e.jsx("span",{className:v()>=0?"text-slate-700":"text-red-600",children:K(v())})}),l("median_rev_ppd")&&e.jsx("td",{className:"px-3 py-2.5 text-right tabular-nums",children:W(m.median_rev_ppd)}),l("median_cost_ppd")&&e.jsx("td",{className:"px-3 py-2.5 text-right tabular-nums",children:W(m.median_cost_ppd)}),l("avg_medicare_pct")&&e.jsx("td",{className:"px-3 py-2.5 text-right",children:"—"}),l("avg_medicaid_pct")&&e.jsx("td",{className:"px-3 py-2.5 text-right",children:"—"}),l("pct_profitable")&&e.jsx("td",{className:"px-3 py-2.5 text-right tabular-nums",children:O(m)!=null?`${O(m)}%`:"—"}),J&&e.jsx("td",{className:"px-3 py-2.5 text-right",children:le(G(m),"pp")}),J&&e.jsx("td",{className:"px-3 py-2.5 text-right",children:le(m.occupancy_delta,"pp")}),p.map(s=>e.jsx("td",{className:"px-3 py-2.5 text-right text-slate-400",title:"No national median is published for this column.",children:"—"},s.key))]})})]})}),J&&e.jsxs("p",{className:"text-[11px] text-slate-400 mt-2 flex-shrink-0",children:["* ",e.jsx("span",{className:"font-medium",children:"Δ columns are same-store:"})," the change vs each facility's own prior fiscal-year cost report (facilities without a prior report are excluded). This intentionally differs from the by-year profitability trend on the Trends tab, which uses every facility that filed each year."]})]})})]}),e.jsx("p",{className:"text-[10px] text-slate-400 mt-4 text-center",children:"Source: CMS HCRIS Cost Reports (Form 2540-10) · CMS Provider Data · SNF Insights by BARA Analytics"})]})})}function Lt({state:t,stateData:c,incomeView:x="net",excludeMixed:_=!0,onBack:b,showExportTop:C}){Pe();const{data:y,isLoading:I}=Z({queryKey:["industry-state-fin",t],queryFn:async()=>{const{getIndustryState:r}=await rt(async()=>{const{getIndustryState:i}=await import("./index-Df108JlE.js").then(m=>m.e8);return{getIndustryState:i}},__vite__mapDeps([0,1]));return r(t)},enabled:!!t}),[j,S]=N.useState("total_revenue"),[d,k]=N.useState("desc"),g=Ue(),{activeExtras:h,show:o}=g,[p,l]=N.useState(!1),E=Be(()=>l(!1),{enabled:p}),$=r=>r.ccrc||r.in_hospital||r.government,V=N.useMemo(()=>(y?.facilities||[]).filter($).length,[y]),P=N.useMemo(()=>y?.facilities?[..._?y.facilities.filter(i=>!$(i)):y.facilities].sort((i,m)=>{let M=i[j],n=m[j];return M==null&&(M=d==="desc"?-1/0:1/0),n==null&&(n=d==="desc"?-1/0:1/0),typeof M=="str
9ing"?d==="desc"?String(n).localeCompare(String(M)):String(M).localeCompare(String(n)):d==="desc"?n-M:M-n}):[],[y,j,d,_]);function z(r){j===r?k(i=>i==="desc"?"asc":"desc"):(S(r),k("desc"))}function D({col:r,children:i,align:m="right"}){const M=j===r;return e.jsx("th",{className:`px-3 py-2 text-${m} cursor-pointer select-none hover:text-sky-600 transition-colors text-xs ${M?"text-sky-600":"text-slate-600"}`,onClick:()=>z(r),children:e.jsxs("span",{className:"inline-flex items-center gap-0.5",children:[i,M&&(d==="desc"?e.jsx(he,{size:10}):e.jsx(xe,{size:10}))]})})}const Y=r=>x==="operating"?r.operating_income:r.net_income,T=r=>x==="operating"?r.op_margin:r.net_margin;function w(){if(!P.length)return;const r=n=>`"${String(n??"").replace(/"/g,'""')}"`,i=[["CCN",n=>n.ccn],["Facility",n=>r(n.provider_name)],...o("citytown")?[["City",n=>n.citytown]]:[],...o("overall_rating")?[["Stars",n=>n.overall_rating??""]]:[],...o("beds")?[["Beds",n=>n.beds??""]]:[],...o("occupancy")?[["Occupancy %",n=>n.beds&&n.adc?(n.adc/n.beds*100).toFixed(0):""]]:[],...o("fy_year")?[["FY",n=>n.fy_year??""]]:[],...o("total_revenue")?[["Revenue",n=>n.total_revenue??""],["Expenses",n=>n.total_expenses??""]]:[],...o("income")?[["Net Income",n=>n.net_income??""],["Op Income",n=>n.operating_income??""]]:[],...o("margin")?[["Net Margin",n=>n.net_margin??""],["Op Margin",n=>n.op_margin??""]]:[],...o("rev_ppd")?[["Rev PPD",n=>n.rev_ppd??""]]:[],...o("cost_ppd")?[["Cost PPD",n=>n.cost_ppd??""]]:[],...o("medicare_pct")?[["Medicare %",n=>n.medicare_pct??""]]:[],...o("medicaid_pct")?[["Medicaid %",n=>n.medicaid_pct??""]]:[],...o("chain_name")?[["Chain",n=>r(n.chain_name)]]:[],["CCRC",n=>n.ccrc?"Y":"N"],["Hospital",n=>n.in_hospital?"Y":"N"],["Government",n=>n.government?"Y":"N"],...h.map(n=>[n.label,q=>q[n.key]??""])],m=i.map(n=>n[0]).join(",")+`
10`,M=P.map(n=>i.map(q=>q[1](n)).join(",")).join(`
11`);re(`snf_industry_${t}.csv`,m+M)}if(I)return e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(ue,{size:20,className:"animate-spin text-sky-600"})});const U=c;return e.jsxs("div",{children:[U&&e.jsx("div",{className:"flex flex-wrap items-center justify-end gap-4 mb-2",children:e.jsxs("button",{onClick:w,className:"flex items-center gap-1.5 text-xs text-slate-600 hover:text-sky-600 transition-colors",children:[e.jsx(se,{size:13})," Export CSV"]})}),e.jsxs("div",{ref:p?E:null,role:p?"dialog":void 0,"aria-modal":p?"true":void 0,"aria-label":p?`${t} facilities, full screen`:void 0,className:p?"fixed inset-0 z-50 bg-white flex flex-col p-3 sm:p-4":"",children:[e.jsx(qe,{...g,coreColumns:Ot,onExpand:p?null:()=>l(!0),onClose:p?()=>l(!1):null,title:p?`${t} facilities`:null,grainNote:"Each facility's own value for the same metrics the state table shows as medians."}),e.jsx("div",{className:p?"overflow-auto flex-1 min-h-0 border border-slate-200 rounded-lg":"overflow-x-auto bg-white border border-slate-200 rounded-xl shadow-sm",children:e.jsxs("table",{className:"w-full text-[13px] [&_td]:border-r [&_td]:border-slate-100 [&_th]:border-r [&_th]:border-slate-100 [&_td:last-child]:border-r-0 [&_th:last-child]:border-r-0",children:[e.jsx("thead",{className:"bg-slate-50 border-b border-slate-200",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 text-center font-normal text-slate-400 select-none text-xs",title:"Rank in the current sort",children:"#"}),e.jsx(D,{col:"provider_name",align:"left",children:"Facility"}),o("citytown")&&e.jsx(D,{col:"citytown",align:"left",children:"City"}),o("overall_rating")&&e.jsx(D,{col:"overall_rating",children:"Stars"}),o("beds")&&e.jsx(D,{col:"beds",children:"Beds"}),o("occupancy")&&e.jsx(D,{col:"occupancy",children:"Occ"}),o("fy_year")&&e.jsx(D,{col:"fy_year",children:"FY"}),o("total_revenue")&&e.jsx(D,{col:"total_revenue",children:"Revenue"}),o("income")&&e.jsx(D,{col:x==="operating"?"operating_income":"net_income",children:x==="operating"?"Op Income":"Net Income"}),o("margin")&&e.jsx(D,{col:x==="operating"?"op_margin":"net_margin",children:"Margin"}),o("rev_ppd")&&e.jsx(D,{col:"rev_ppd",children:"Rev PPD"}),o("cost_ppd")&&e.jsx(D,{col:"cost_ppd",children:"Cost PPD"}),o("medicare_pct")&&e.jsx(D,{col:"medicare_pct",children:"Medicare"}),o("medicaid_pct")&&e.jsx(D,{col:"medicaid_pct",children:"Medicaid"}),o("chain_name")&&e.jsx(D,{col:"chain_name",align:"left",children:"Chain"}),h.map(r=>e.jsx(D,{col:r.key,title:r.title,children:r.label},r.key))]})}),e.jsx("tbody",{className:"divide-y divide-slate-200 text-slate-800",children:P.map((r,i)=>e.jsxs("tr",{className:"even:bg-slate-50 hover:bg-sky-50 transition-colors cursor-pointer",onClick:()=>window.open(`/facility/${r.ccn}?tab=Financial`,"_blank"),role:"button",tabIndex:0,onKeyDown:m=>{(m.key==="Enter"||m.key===" ")&&(m.preventDefault(),window.open(`/facility/${r.ccn}?tab=Financial`,"_blank"))},children:[e.jsx("td",{className:"px-3 py-2 text-center tabular-nums text-slate-400",children:i+1}),e.jsx("td",{className:"px-3 py-2",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sky-600 font-medium hover:text-sky-700 max-w-[180px] truncate",children:r.provider_name}),e.jsx("p",{className:"text-[10px] text-slate-400",children:r.ccn})]}),r.ccrc&&e.jsx("span",{className:"text-[8px] bg-slate-100 text-slate-600 px-1 py-0.5 rounded font-medium flex-shrink-0",children:"CCRC"}),r.in_hospital&&e.jsx("span",{className:"text-[8px] bg-slate-100 text-slate-600 px-1 py-0.5 rounded font-medium flex-shrink-0",children:"HOSP"}),r.government&&e.jsx("span",{className:"text-[8px] bg-slate-100 text-slate-600 px-1 py-0.5 rounded font-medium flex-shrink-0",children:"GOV"})]})}),o("citytown")&&e.jsx("td",{className:"px-3 py-2 text-slate-600",children:r.citytown}),o("overall_rating")&&e.jsx("td",{className:"px-3 py-2 text-right",children:e.jsx("span",{className:"font-semibold tabular-nums",style:r.overall_rating?{color:at(r.overall_rating)}:{color:"#94a3b8"},children:r.overall_rating||"—"})}),o("beds")&&e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:r.beds??"—"}),o("occupancy")&&e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:r.beds&&r.adc?`${(r.adc/r.beds*100).toFixed(0)}%`:"—"}),o("fy_year")&&e.jsx("td",{className:"px-3 py-2 text-right tabular-nums text-slate-600",children:r.fy_year||"—"}),o("total_revenue")&&e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:r.total_revenue?me(r.total_revenue):"—"}),o("income")&&e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:Y(r)!=null?e.jsx("span",{className:Y(r)>=0?"text-slate-700":"text-red-600",children:me(Y(r))}):"—"}),o("margin")&&e.jsx("td",{className:"px-3 py-2 text-right",children:T(r)!=null?e.jsx("span",{className:T(r)>=0?"text-slate-700":"text-red-600",children:K(T(r))}):"—"}),o("rev_ppd")&&e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:r.rev_ppd?r.ppd_outlier?e.jsxs("span",{className:"text-amber-600 cursor-help",title:"Unusually high — may include non-SNF revenue (consolidated cost report)",children:["*",W(r.rev_ppd)]}):W(r.rev_ppd):"—"}),o("cost_ppd")&&e.jsx("td",{className:"px-3 py-2 text-right tabular-nums text-slate-600",children:r.cost_p
11pd?r.ppd_outlier?e.jsxs("span",{className:"text-amber-600 cursor-help",title:"Unusually high — may include non-SNF costs",children:["*",W(r.cost_ppd)]}):W(r.cost_ppd):"—"}),o("medicare_pct")&&e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:r.medicare_pct!=null?`${r.medicare_pct.toFixed(0)}%`:"—"}),o("medicaid_pct")&&e.jsx("td",{className:"px-3 py-2 text-right tabular-nums",children:r.medicaid_pct!=null?`${r.medicaid_pct.toFixed(0)}%`:"—"}),o("chain_name")&&e.jsx("td",{className:"px-3 py-2 text-slate-600 max-w-[100px] truncate",children:r.chain_name||"—"}),h.map(m=>e.jsx("td",{className:"px-3 py-2 text-right tabular-nums text-slate-600",children:r.bs_suppressed&&Mt.has(m.key)?e.jsx(Et,{}):Ve[m.fmt](r[m.key])},m.key))]},r.ccn))})]})}),e.jsxs("p",{className:"text-[10px] text-slate-400 px-3 py-2 border-t border-slate-200 flex-shrink-0",children:[P.length," facilities in ",t,_&&V>0?` · ${V} hospital/CCRC/gov hidden`:""," · Click any row to view full profile"]})]})]})}function zt({setting:t}){const c=t==="hospital",[x,_]=N.useState("snapshot"),[b,C]=N.useState(null),{data:y,isLoading:I}=Z({queryKey:["industry-costreport",t],queryFn:()=>c?lt():it(),staleTime:1e3*60*60}),[j,S]=N.useState("count"),[d,k]=N.useState("desc"),[g,h]=N.useState("financials"),o=y?.national||{},p=y?.states||[],l=N.useMemo(()=>[...p].sort((i,m)=>{const M=i[j]??-1/0,n=m[j]??-1/0;return d==="desc"?n-M:M-n}),[p,j,d]);function E(i){j===i?k(m=>m==="desc"?"asc":"desc"):(S(i),k("desc"))}const $=i=>i!=null?`${i}%`:"—",V=i=>i!=null?i.toFixed(1):"—",P=c?[["count","Hospitals",H],["total_beds","Beds",H],["median_margin","Median Margin",K],["median_cost_per_day","Cost/Day",W],["median_occupancy","Occupancy",K],["median_medicare_day_pct","Medicare Days",K],["median_revenue","Median Net Rev",X],["pct_profitable","% Profitable",$]]:[["count","Agencies",H],["total_visits","Visits",H],["median_margin","Median Margin",K],["median_cost_per_visit","Cost/Visit",W],["median_visits_per_patient","Visits/Patient",V],["median_revenue","Median Net Rev",X],["pct_profitable","% Profitable",$]],z=[["n_charity","Hospitals",H],["charity_care_cost","Charity care cost",X],["uncompensated_care_cost","Uncompensated care",X],["uncompensated_pct_rev","Uncomp. % of rev",$]],D=c&&g==="charity",Y=D?z:P;function T(i){h(i),S(i==="charity"?"uncompensated_care_cost":"count"),k("desc")}const w=b&&p.find(i=>i.state===b)||o,U=c?[["Hospitals",H(w.count)],["Total Beds",H(w.total_beds)],["Median Margin",K(w.median_margin),w.median_margin==null?void 0:w.median_margin<0?"text-red-600":"text-emerald-600"],["Median Cost/Day",W(w.median_cost_per_day)],["Median Occupancy",K(w.median_occupancy)],["Median Medicare Days",K(w.median_medicare_day_pct)],["Median Net Rev",X(w.median_revenue)],["% Profitable",$(w.pct_profitable)]]:[["Agencies",H(w.count)],["Total Visits",H(w.total_visits)],["Median Margin",K(w.median_margin),w.median_margin==null?void 0:w.median_margin<0?"text-red-600":"text-emerald-600"],["Median Cost/Visit",W(w.median_cost_per_visit)],["Median Visits/Patient",V(w.median_visits_per_patient)],["Median Net Rev",X(w.median_revenue)],["% Profitable",$(w.pct_profitable)]];function r(){if(!l.length)return;const i="State,"+Y.map(M=>M[1]).join(",")+`
12`,m=l.map(M=>[M.state,...Y.map(n=>M[n[0]]??"")].join(",")).join(`
13`);re(`${t}_industry${D?"_charity":""}.csv`,i+m)}return I?e.jsx("div",{className:"flex justify-center py-20",children:e.jsx(ue,{size:24,className:"animate-spin text-sky-600"})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("h2",{className:"text-xs font-semibold text-slate-500 uppercase tracking-wide",children:b?`${b} — Financial Summary`:"National Financial Summary"}),b&&e.jsxs("button",{onClick:()=>C(null),className:"inline-flex items-center gap-1 text-xs text-sky-600 hover:text-sky-700",children:[e.jsx(ce,{size:12})," Back to national"]})]}),e.jsx("div",{className:`bg-white border border-slate-200 rounded-xl shadow-sm mb-6 overflow-hidden grid grid-cols-2 sm:grid-cols-4 ${c?"lg:grid-cols-8":"lg:grid-cols-7"} [&>div]:px-4 [&>div]:py-3 [&>div]:border-r [&>div]:border-b [&>div]:border-slate-100 lg:[&>div]:border-b-0 [&>div:last-child]:border-r-0`,children:U.map(([i,m,M])=>e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] text-slate-500 uppercase tracking-wide whitespace-nowrap",children:i}),e.jsx("p",{className:`text-lg font-bold mt-0.5 tabular-nums ${M||"text-slate-900"}`,children:m})]},i))}),e.jsx("div",{className:"flex items-center gap-1 mb-3",children:[["snapshot","Snapshot"],["trends","Trends"]].map(([i,m])=>e.jsx("button",{onClick:()=>_(i),className:`px-3 py-1 text-xs font-medium rounded-md border transition-colors ${x===i?"bg-sky-600 text-white border-sky-600":"bg-white text-slate-600 border-slate-200 hover:bg-slate-50"}`,children:m},i))}),x==="trends"&&e.jsx(St,{setting:t,geo:b,states:p.map(i=>i.state),onSelectGeo:C}),x==="snapshot"&&b&&e.jsx(At,{setting:t,state:b,onBack:()=>C(null)}),x==="snapshot"&&!b&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3 gap-2 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h2",{className:"text-sm font-semibold text-slate-600 uppercase tracking-wide",children:"State-by-State Breakdown"}),c&&e.jsxs("div",{className:"flex text-xs rounded-md border border-slate-300 overflow-hidden",children:[e.jsx("button",{onClick:()=>T("financials"),className:`px-2.5 py-1 ${g==="financials"?"bg-sky-600 text-white":"text-slate-600 hover:bg-slate-50"}`,children:"Financials"}),e.jsx("button",{onClick:()=>T("charity"),className:`px-2.5 py-1 border-l border-slate-300 ${g==="charity"?"bg-sky-600 text-white":"text-slate-600 hover:bg-slate-50"}`,children:"Charity & uncompensated care"})]})]}),e.jsxs("button",{onClick:r,className:"flex items-center gap-1.5 text-xs text-slate-600 hover:text-sky-600 transition-colors",children:[e.jsx(se,{size:13})," Export CSV"]})]}),e.jsxs("div",{className:"bg-white border border-slate-200 rounded-xl overflow-hidden shadow-sm",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 border-b border-slate-200 text-xs",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 text-center font-normal text-slate-400 select-none",title:"Rank in the current sort",children:"#"}),e.jsx("th",{className:"px-3 py-2 text-left text-slate-600",children:"State"}),Y.map(([i,m])=>e.jsx("th",{onClick:()=>E(i),className:`px-3 py-2 text-right cursor-pointer select-none hover:text-sky-600 transition-colors ${j===i?"text-sky-600":"text-slate-600"}`,children:e.jsxs("span",{className:"inline-flex items-center gap-0.5",children:[m,j===i&&(d==="desc"?e.jsx(he,{size:10}):e.jsx(xe,{size:10}))]})},i))]})}),e.jsx("tbody",{className:"divide-y divide-slate-100",children:l.map((i,m)=>e.jsxs("tr",{onClick:()=>C(i.state),className:"hover:bg-sky-50/60 cursor-pointer",title:`View all ${i.state} providers`,children:[e.jsx("td",{className:"px-3 py-1.5 text-center tabular-nums text-slate-400",children:m+1}),e.jsx("td",{className:"px-3 py-1.5 font-medium text-sky-700",children:i.state}),Y.map(([M,,n])=>e.jsx("td",{className:`px-3 py-1.5 text-right tabular-nums whitespace-nowrap ${M==="median_margin"?i[M]<0?"text-red-600":"text-emerald-600":"text-slate-700"}`,children:n(i[M])},M))]},i.state))})]})}),e.jsxs("p",{className:"text-[10px] text-slate-400 px-3 py-2 border-t border-slate-200",children:["Click a state to list its providers, then a provider for its full multi-year cost report.",D?" Charity care & uncompensated care are self-reported (Worksheet S-10), summed across the state's hospitals; uncompensated % of revenue = total uncompensated-care cost ÷ total net patient revenue. Higher levels often track states that did not expand Medicaid.":` Source: CMS HCRIS ${c?"Form 2552-10":"Form 1728-20"} (latest year per provider); medians across providers with a report.${c?"":" Chains file consolidated revenue across sub-agencies, so revenue is a median, not a sum."}`]})]})]})]})}function At({setting:t,state:c,onBack:x}){const _=t==="hospital",{data:b,isLoading:C}=Z({queryKey:["costreport-by-state",t,c],queryFn:()=>_?ot(c):ct(c),staleTime:1e3*60*5}),y=(_?b?.hospitals:b?.agencies)||[],I=_?"/hospital-cost-reports":"/home-health-cost-reports",j=_?[["
13net_patient_revenue","Net Patient Rev",X],["uncompensated_pct_rev","Uncomp. % Rev",K]]:[["net_patient_revenue","Net Patient Rev",X],["total_margin_pct","Total Margin",K],["cost_per_visit","Cost/Visit",W]],S=new Set(["net_patient_revenue","total_margin_pct"]),d={};y.forEach(h=>{if(h.net_patient_revenue!=null){const o=Math.round(h.net_patient_revenue);d[o]=(d[o]||0)+1}});const k=h=>h.net_patient_revenue!=null&&d[Math.round(h.net_patient_revenue)]>1,g=y.some(k);return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[e.jsxs("button",{onClick:x,className:"flex items-center gap-1 text-xs text-sky-600 hover:text-sky-700",children:[e.jsx(ce,{size:13})," All states"]}),e.jsxs("h2",{className:"text-sm font-semibold text-slate-600 uppercase tracking-wide",children:[c," — ",y.length," ",_?"hospitals":"agencies"]})]}),C?e.jsx("div",{className:"flex justify-center py-16",children:e.jsx(ue,{size:22,className:"animate-spin text-sky-600"})}):e.jsxs("div",{className:"bg-white border border-slate-200 rounded-xl overflow-hidden shadow-sm",children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 border-b border-slate-200 text-xs",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 text-center font-normal text-slate-400 select-none",children:"#"}),e.jsx("th",{className:"px-3 py-2 text-left font-medium text-slate-600",children:"Provider"}),e.jsx("th",{className:"px-3 py-2 text-right font-medium text-slate-600",children:"FY"}),j.map(([h,o])=>e.jsx("th",{className:"px-3 py-2 text-right font-medium text-slate-600",children:o},h))]})}),e.jsx("tbody",{className:"divide-y divide-slate-100",children:y.map((h,o)=>{const p=k(h);return e.jsxs("tr",{onClick:()=>window.open(`${I}?ccn=${h.ccn}`,"_blank","noopener"),className:"hover:bg-sky-50/60 cursor-pointer",title:"Open full cost report in a 
13new tab",children:[e.jsx("td",{className:"px-3 py-1.5 text-center tabular-nums text-slate-400",children:o+1}),e.jsxs("td",{className:"px-3 py-1.5",children:[e.jsx("span",{className:"font-medium text-sky-700 hover:underline",children:h.name}),p&&e.jsx("span",{className:"ml-1.5 text-[9px] font-medium text-amber-700 bg-amber-50 border border-amber-200 px-1 py-0.5 rounded uppercase align-middle",title:"This chain files one consolidated income statement, so revenue & margin repeat across its agencies; visits & cost/visit are per-agency.",children:"consolidated"}),e.jsxs("span",{className:"text-slate-400",children:[h.city?` · ${h.city}`:""," · ",h.ccn]})]}),e.jsx("td",{className:"px-3 py-1.5 text-right text-slate-400",children:h.fy_year||"—"}),j.map(([l,,E])=>e.jsx("td",{className:`px-3 py-1.5 text-right tabular-nums whitespace-nowrap ${p&&S.has(l)?"italic text-slate-400":l==="total_margin_pct"?h[l]<0?"text-red-600":"text-emerald-600":"text-slate-700"}`,children:E(h[l])},l))]},h.ccn)})})]})}),e.jsxs("p",{className:"text-[10px] text-slate-400 px-3 py-2 border-t border-slate-200",children:["Click a provider to open its full multi-year cost report in a 
13new tab.",g&&" Rows tagged “consolidated” share one chain-level income statement — the revenue & margin (shown muted) repeat across the chain’s agencies; visits & cost/visit are per-agency."]})]})]})}export{Zt 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.