1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/leaflet-src-84_lqfRu.js","assets/index-Df108JlE.js","assets/index-Bfcugaeq.css","assets/leaflet.markercluster-src-CNh4IanG.js"])))=>i.map(i=>d[i]); 2import{c as ht,b as Ye,j as e,r as d,C as Ge,ax as At,ay as Et,az as Me,aA as Z,aB as he,I as Ke,X as Fe,aC as Ae,a8 as Dt,a9 as Pt,aD as Tt,aE as Ot,ah as It,aF as Ht,ag as lt,F as Ve,L as We,D as qt,ai as ot,a3 as ke,Y as Bt,H as Vt,av as Wt,aG as it,aH as Yt,aI as Gt}from"./index-Df108JlE.js";import{Q as Kt}from"./QueryError-Csi7m0zt.js";import{A as Zt,a as Qt}from"./AnalysisRequestModal-Dkb7uKyY.js";import{C as Ut}from"./chevron-right-C5-qd-S8.js";import{C as Jt}from"./chevron-left-BG1_bPN5.js";import{B as _t,a as bt}from"./basemap-jxEMHhBQ.js";import{M as ft}from"./minimize-2-xTu8mWpA.js";import{M as gt}from"./maximize-2-C1hFM99k.js";/* empty css */import{C as ct}from"./columns-2-Bj6wLKAU.js";import"./useModalA11y-B5_bs4oH.js";const Xt=[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"22",x2:"18",y1:"12",y2:"12",key:"l9bcsi"}],["line",{x1:"6",x2:"2",y1:"12",y2:"12",key:"13hhkx"}],["line",{x1:"12",x2:"12",y1:"6",y2:"2",key:"10w3f3"}],["line",{x1:"12",x2:"12",y1:"22",y2:"18",key:"15g9kq"}]],en=ht("crosshair",Xt);const tn=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],Ee=ht("square",tn);function me({title:t,children:n,defaultOpen:l=!1}){const[i,o]=d.useState(l);return e.jsxs("div",{className:"border-b border-slate-100 last:border-0",children:[e.jsxs("button",{type:"button",onClick:()=>o(m=>!m),className:"w-full flex items-center justify-between px-3 py-2.5 hover:bg-slate-50 transition-colors",children:[e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wide text-slate-600",children:t}),e.jsx(Ge,{size:14,className:`text-slate-400 transition-transform ${i?"rotate-180":""}`})]}),i&&e.jsx("div",{className:"px-3 pb-3 pt-1 space-y-2",children:n})]})}function F({label:t,value:n,onChange:l,type:i="number",placeholder:o="",step:m=1}){return e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[11px] text-slate-500",children:t}),e.jsx("input",{type:i,value:n??"",onChange:j=>l(j.target.value===""?null:i==="number"?Number(j.target.value):j.target.value),placeholder:o,step:m,className:"mt-0.5 w-full px-2 py-1 text-xs border border-slate-300 rounded-md focus:outline-none focus:ring-1 focus:ring-sky-500 focus:border-sky-500"})]})}function ee({label:t,value:n,onChange:l,options:i}){return e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[11px] text-slate-500",children:t}),e.jsxs("select",{value:n??"",onChange:o=>l(o.target.value===""?null:isNaN(Number(o.target.value))?o.target.value:Number(o.target.value)),className:"mt-0.5 w-full px-2 py-1 text-xs border border-slate-300 rounded-md focus:outline-none focus:ring-1 focus:ring-sky-500 focus:border-sky-500 bg-white",children:[e.jsx("option",{value:"",children:"Any"}),i.map(o=>e.jsx("option",{value:o.value,children:o.label},o.value))]})]})}function oe({label:t,checked:n,onChange:l}){return e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-xs text-slate-700 hover:text-slate-900",children:[e.jsx("input",{type:"checkbox",checked:!!n,onChange:i=>l(i.target.checked||null),className:"rounded border-slate-300 text-sky-600 focus:ring-sky-500"}),t]})}function nn({open:t,onToggle:n,pending:l,active:i,onChange:o,onApply:m,onClear:j,dirty:N,geoParams:P}){const f=Object.keys(i).length,{data:A}=Ye({queryKey:["market-count",P,l],queryFn:()=>At({...P,...l}),enabled:!!P&&N,staleTime:3e4});if(!t)return e.jsxs("button",{type:"button",onClick:n,className:"flex flex-col items-center gap-2 py-3 px-2 rounded-xl border border-slate-200 bg-white shadow-sm hover:bg-slate-50 transition-colors self-start",title:"Show filters",children:[e.jsx(Ut,{size:16,className:"text-slate-500"}),e.jsxs("span",{className:"text-[10px] font-semibold text-slate-500 [writing-mode:vertical-rl] rotate-180",children:["Filters",f>0?` (${f})`:""]})]});const $=[{value:1,label:"1 â "},{value:2,label:"2 â "},{value:3,label:"3 â "},{value:4,label:"4 â "},{value:5,label:"5 â "}];return e.jsxs("aside",{className:"w-72 shrink-0 bg-white rounded-xl border border-slate-200 shadow-sm sticky top-4 self-start max-h-[calc(100vh-6rem)] flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-slate-100",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-semibold text-slate-700",children:"Filters"}),f>0&&e.jsxs("span",{className:"text-[10px] font-semibold bg-sky-100 text-sky-700 rounded-full px-2 py-0.5",children:[f," active"]})]}),e.jsx("button",{onClick:n,className:"text-slate-400 hover:text-slate-600",title:"Hide filters",children:e.jsx(Jt,{size:16})})]}),e.jsxs("div",{className:"overflow-y-auto flex-1",children:[e.jsxs(me,{title:"Quality â Star Ratings",defaultOpen:!0,children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(ee,{label:"Min overall",value:l.min_overall_rating,onChange:a=>o("min_overall_rating",a),options:$}),e.jsx(ee,{label:"Max overall",value:l.max_overall_rating,onChange:a=>o("max_overall_rating",a),options:$})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(ee,{label:"Min health",value:l.min_health_rating,onChange:a=>o("min_health_rating",a),options:$}),e.jsx(ee,{label:"Max health",value:l.max_health_rating,onChange:a=>o("max_health_rating",a),options:$})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(ee,{label:"Min staffing",value:l.min_staffing_rating,onChange:a=>o("min_staffing_rating",a),options:$}),e.jsx(ee,{label:"Max staffing",value:l.max_staffing_rating,onChange:a=>o("max_staffing_rating",a),options:$})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(ee,{label:"Min QM",value:l.min_qm_rating,onChange:a=>o("min_qm_rating",a),options:$}),e.jsx(ee,{label:"Max QM",value:l.max_qm_rating,onChange:a=>o("max_qm_rating",a),options:$})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(ee,{label:"Min LS QM",value:l.min_longstay_qm_rating,onChange:a=>o("min_longstay_qm_rating",a),options:$}),e.jsx(ee,{label:"Max LS QM",value:l.max_longstay_qm_rating,onChange:a=>o("max_longstay_qm_rating",a),options:$})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(ee,{label:"Min SS QM",value:l.min_shortstay_qm_rating,onChange:a=>o("min_shortstay_qm_rating",a),options:$}),e.jsx(ee,{label:"Max SS QM",value:l.max_shortstay_qm_rating,onChange:a=>o("max_shortstay_qm_rating",a),options:$})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(F,{label:"Min chain avg",value:l.min_chain_avg_rating,onChange:a=>o("min_chain_avg_rating",a),placeholder:"1",step:.1}),e.jsx(F,{label:"Max chain avg",value:l.max_chain_avg_rating,onChange:a=>o("max_chain_avg_rating",a),placeholder:"5",step:.1})]}),e.jsx(oe,{label:"Special Focus only",checked:l.sff_status,onChange:a=>o("sff_status",a)}),e.jsx(oe,{label:"Abuse icon only",checked:l.abuse_icon,onChange:a=>o("abuse_icon",a)})]}),e.jsxs(me,{title:"Census / Size",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(F,{label:"Min beds",value:l.min_beds,onChange:a=>o("min_beds",a),placeholder:"0"}),e.jsx(F,{label:"Max beds",value:l.max_beds,onChange:a=>o("max_beds",a),placeholder:""})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(F,{label:"Min ADC",value:l.min_adc,onChange:a=>o("min_adc",a),placeholder:"0",step:5}),e.jsx(F,{label:"Max ADC",value:l.max_adc,onChange:a=>o("max_adc",a),placeholder:"",step:5})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(F,{label:"Min occ %",value:l.min_occupancy_pct,onChange:a=>o("min_occupancy_pct",a),placeholder:"0",step:5}),e.jsx(F,{label:"Max occ %",value:l.max_occupancy_pct,onChange:a=>o("max_occupancy_pct",a),placeholder:"100",step:5})]})]}),e.jsxs(me,{title:"Ownership / Structure",children:[e.jsx(oe,{label:"Hospital-based",checked:l.hospital_based,onChange:a=>o("hospital_based",a)}),e.jsx(oe,{label:"CCRC",checked:l.ccrc,onChange:a=>o("ccrc",a)}),e.jsx(oe,{label:"Government-owned",checked:l.government_owned,onChange:a=>o("government_owned",a)}),e.jsx(oe,{label:"Non-profit",checked:l.nonprofit,onChange:a=>o("nonprofit",a)}),e.jsx(oe,{label:"For-profit",checked:l.forprofit,onChange:a=>o("forprofit",a)}),e.jsx(oe,{label:"Has resident/family council",checked:l.has_council,onChange:a=>o("has_council",a)}),e.jsx(oe,{label:"Recent change of ownership",checked:l.recent_ownership_change,onChange:a=>o("recent_ownership_change",a)}),e.jsx(oe,{label:"In a chain (independents excluded)",checked:l.in_chain===!0,onChange:a=>o("in_chain",a?!0:null)})]}),e.jsxs(me,{title:"Workforce â Turnover",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(F,{label:"Min RN turn %",value:l.min_rn_turnover_pct,onChange:a=>o("min_rn_turnover_pct",a),placeholder:"0",step:5}),e.jsx(F,{label:"Max RN turn %",value:l.max_rn_turnover_pct,onChange:a=>o("max_rn_turnover_pct",a),placeholder:"",step:5})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(F,{label:"Min total turn %",value:l.min_total_turnover_pct,onChange:a=>o("min_total_turnover_pct",a),placeholder:"0",step:5}),e.jsx(F,{label:"Max total turn %",value:l.max_total_turnover_pct,onChange:a=>o("max_total_turnover_pct",a),placeholder:"",step:5})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(F,{label:"Min admins left",value:l.min_admin_turnover,onChange:a=>o("min_admin_turnover",a),placeholder:"0"}),e.jsx(F,{label:"Max admins left",value:l.max_admin_turnover,onChange:a=>o("max_admin_turnover",a),placeholder:""})]})]}),e.jsxs(me,{title:"Workforce â Staffing Hours (HPRD)",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(F,{label:"Min total HPRD",value:l.min_total_hprd,onChange:a=>o("min_total_hprd",a),placeholder:"0",step:.1}),e.jsx(F,{label:"Max total HPRD",value:l.max_total_hprd,onChange:a=>o("max_total_hprd",a),placeholder:"",step:.1})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(F,{label:"Min RN HPRD",value:l.min_rn_hprd,onChange:a=>o("min_rn_hprd",a),placeholder:"0",step:.1}),e.jsx(F,{label:"Max RN HPRD",value:l.max_rn_hprd,onChange:a=>o("max_rn_hprd",a),placeholder:"",step:.1})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(F,{label:"Min LPN HPRD",value:l.min_lpn_hprd,onChange:a=>o("min_lpn_hprd",a),placeholder:"0",step:.1}),e.jsx(F,{label:"Max LPN HPRD",value:l.max_lpn_hprd,onChange:a=>o("max_lpn_hprd",a),placeholder:"",step:.1})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(F,{label:"Min CNA HPRD",value:l.min_cna_hprd,onChange:a=>o("min_cna_hprd",a),placeholder:"0",step:.1}),e.jsx(F,{label:"Max CNA HPRD",value:l.max_cna_hprd,onChange:a=>o("max_cna_hprd",a),placeholder:"",step:.1})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(F,{label:"Min wknd RN HPRD",value:l.min_weekend_rn_hprd,onChange:a=>o("min_weekend_rn_hprd",a),placeholder:"0",step:.1}),e.jsx(F,{label:"Max wknd RN HPRD",value:l.max_weekend_rn_hprd,onChange:a=>o("max_weekend_rn_hprd",a),placeholder:"",step:.1})]})]}),e.jsxs(me,{title:"Geography / Chain",children:[e.jsx(F,{label:"States (2-letter, comma-separated)",type:"text",value:Array.isArray(l.states)?l.states.join(","):l.states||"",onChange:a=>{if(!a)return o("states",null);const M=String(a).split(/[\s,]+/).map(p=>
2p.trim().toUpperCase()).filter(Boolean);o("states",M.length?M:null)},placeholder:"KY, TN, NC"}),e.jsx(F,{label:"City contains",type:"text",value:l.city_contains,onChange:a=>o("city_contains",a),placeholder:"Louisville"}),e.jsx(F,{label:"ZIP starts with",type:"text",value:l.zip_starts,onChange:a=>o("zip_starts",a),placeholder:"402"}),e.jsx(F,{label:"Chain name contains",type:"text",value:l.chain_contains,onChange:a=>o("chain_contains",a),placeholder:"Genesis"})]})]}),e.jsxs("div",{className:"border-t border-slate-100 px-3 py-3 flex items-center gap-2 bg-white",children:[e.jsx("button",{type:"button",onClick:j,disabled:Object.keys(l).length===0&&f===0,className:"text-xs text-slate-500 hover:text-slate-700 disabled:text-slate-300 disabled:cursor-not-allowed",children:"Clear all"}),N&&A?.count!=null&&e.jsxs("span",{className:"text-[11px] text-slate-500 ml-1",children:["â ",e.jsx("span",{className:"font-semibold text-slate-700",children:A.count.toLocaleString()})," match"]}),e.jsx("button",{type:"button",onClick:m,disabled:!N,className:`ml-auto text-xs font-medium px-4 py-1.5 rounded-lg transition-colors ${N?"bg-sky-600 hover:bg-sky-700 text-white shadow-sm":"bg-slate-100 text-slate-400 cursor-not-allowed"}`,children:"Apply"})]})]})}function sn(t){const n=Number(t);return!n||n<1?"Not rated":n+" star"+(n!==1?"s":"")}const Le=[{key:"insight",label:"InsightScore"},{key:"rank",label:"InsightScore Rank"},{key:"stars",label:"Overall Stars"},{key:"health",label:"Health Insp."},{key:"staffing",label:"Staffing Rating"},{key:"qm",label:"QM Rating"},{key:"occupancy",label:"Occupancy %"},{key:"adc",label:"ADC"},{key:"beds",label:"Beds"},{key:"hprd",label:"Nurse HPRD"},{key:"turnover",label:"Turnover %"},{key:"ss_rehosp",label:"SS Rehospitalization %"},{key:"ss_ed",label:"SS ED Visits %"},{key:"ls_hosp",label:"LS Hospitalizations"},{key:"ls_ed",label:"LS ED Visits"},{key:"agency",label:"Agency %"},{key:"admin_tenure",label:"Admin Tenure",tip:"Time the current administrator (job code 1) has been continuously employed at this facility, based on CMS Payroll-Based Journal (PBJ) data. Gaps of 6+ months reset the tenure clock â returning employees are measured from their most recent start date."},{key:"don_tenure",label:"DON Tenure",tip:"Time the current Director of Nursing (job code 5) has been continuously employed at this facility, based on CMS PBJ data. Gaps of 6+ months reset the tenure clock â returning employees are measured from their most recent start date."},{key:"op_margin",label:"Operating Margin",tip:"Operating income as % of revenue from CMS cost reports. Green = profitable, red = losing money."},{key:"rev_ppd",label:"Revenue PPD",tip:"Net revenue per patient day (after Medicare PPS adjustment) from CMS cost reports."},{key:"exp_ppd",label:"Expense PPD",tip:"Total cost per patient day from CMS cost reports."},{key:"dso",label:"DSO (Days)",tip:"Days sales outstanding from CMS cost reports. Lower = faster collections."}];function dt(t,n,l){if(n==="insight"){const i=t.insight_score;return i==null?"#cbd5e1":i>=70?"#059669":i>=50?"#0284c7":i>=35?"#d97706":"#dc2626"}if(n==="rank")return Et(t.market_rank,t._totalRanked);if(n==="stars")return Me(t.overall_rating);if(n==="health")return Me(t.health_inspection_rating);if(n==="staffing")return Me(t.staffing_rating);if(n==="qm")return Me(t.qm_rating);if(n==="occupancy")return Z(t.occupancy_pct,40,95,[239,68,68],[16,185,129]);if(n==="adc")return Z(Number(t.average_number_of_residents_per_day),0,200,[203,213,225],[14,116,144]);if(n==="beds")return Z(Number(t.number_of_certified_beds),0,250,[203,213,225],[14,116,144]);if(n==="hprd")return Z(t.total_nurse_hprd,2.5,5.5,[239,68,68],[16,185,129]);if(n==="turnover")return Z(t.nursing_turnover,20,80,[16,185,129],[239,68,68]);if(n==="ss_rehosp")return t.ss_rehospitalization!=null?Z(t.ss_rehospitalization,15,30,[16,185,129],[239,68,68]):"#cbd5e1";if(n==="ss_ed")return t.ss_ed_visits!=null?Z(t.ss_ed_visits,8,20,[16,185,129],[239,68,68]):"#cbd5e1";if(n==="ls_hosp")return t.ls_hospitalizations!=null?Z(t.ls_hospitalizations,1,4,[16,185,129],[239,68,68]):"#cbd5e1";if(n==="ls_ed")return t.ls_ed_visits!=null?Z(t.ls_ed_visits,.5,3,[16,185,129],[239,68,68]):"#cbd5e1";if(n==="agency"){const i=l?.[t.ccn]?.nursing_agency_pct;return i==null?"#cbd5e1":i===0?"#94a3b8":Z(i,1,30,[252,200,200],[185,28,28])}if(n==="admin_tenure"){const i=l?.[t.ccn]?.admin_tenure_days;return i==null?"#cbd5e1":Z(i,0,1825,[239,68,68],[16,185,129])}if(n==="don_tenure"){const i=l?.[t.ccn]?.don_tenure_days;return i==null?"#cbd5e1":Z(i,0,1825,[239,68,68],[16,185,129])}if(n==="op_margin"){const i=t._fin?.operating_margin_pct;return i==null?"#cbd5e1":Z(i,-15,15,[239,68,68],[16,185,129])}if(n==="rev_ppd"){const i=t._fin?.net_revenue_ppd;return i==null?"#cbd5e1":Z(i,200,600,[239,68,68],[16,185,129])}if(n==="exp_ppd"){const i=t._fin?.cost_per_day;return i==null?"#cbd5e1":Z(i,200,600,[16,185,129],[239,68,68])}if(n==="dso"){const i=t._fin?.dso_days;return i==null?"#cbd5e1":Z(i,20,80,[16,185,129],[239,68,68])}return"#94a3b8"}function ut(t,n,l){if(n==="insight")return t.market_rank!=null?t.market_rank:"?";if(n==="rank")return t.market_rank!=null?t.market_rank:"";if(n==="stars")return parseInt(t.overall_rating,10)||"?";if(n==="health")return parseInt(t.health_inspection_rating,10)||"?";if(n==="staffing")return parseInt(t.staffing_rating,10)||"?";if(n==="qm")return parseInt(t.qm_rating,10)||"?";if(n==="occupancy")return t.occupancy_pct!=null?Math.round(t.occupancy_pct):"?";
2if(n==="hprd")return t.total_nurse_hprd!=null?t.total_nurse_hprd.toFixed(1):"?";if(n==="turnover")return t.nursing_turnover!=null?Math.round(t.nursing_turnover):"?";if(n==="ss_rehosp")return t.ss_rehospitalization!=null?t.ss_rehospitalization.toFixed(0):"?";if(n==="ss_ed")return t.ss_ed_visits!=null?t.ss_ed_visits.toFixed(0):"?";if(n==="ls_hosp")return t.ls_hospitalizations!=null?t.ls_hospitalizations.toFixed(1):"?";if(n==="ls_ed")return t.ls_ed_visits!=null?t.ls_ed_visits.toFixed(1):"?";if(n==="agency"){const i=l?.[t.ccn]?.nursing_agency_pct;return i!=null?Math.round(i):"?"}if(n==="admin_tenure")return he(l?.[t.ccn]?.admin_tenure_days);if(n==="don_tenure")return he(l?.[t.ccn]?.don_tenure_days);if(n==="op_margin"){const i=t._fin?.operating_margin_pct;return i!=null?`${i.toFixed(0)}%`:"?"}if(n==="rev_ppd"){const i=t._fin?.net_revenue_ppd;return i!=null?`$${Math.round(i)}`:"?"}if(n==="exp_ppd"){const i=t._fin?.cost_per_day;return i!=null?`$${Math.round(i)}`:"?"}if(n==="dso"){const i=t._fin?.dso_days;return i!=null?Math.round(i):"?"}return""}function rn(t,n,l,i,o){if(t==null||isNaN(t))return null;const m=Math.max(0,Math.min(1,(t-n)/(l-n)));return Math.round(i+(o-i)*m)}function pt(t,n,l,i=14,o=56){const m=(N,P,f)=>rn(N,P,f,i,o);if(n==="uniform"||!n)return null;if(n==="stars")return m(parseInt(t.overall_rating,10),1,5);if(n==="health")return m(parseInt(t.health_inspection_rating,10),1,5);if(n==="staffing")return m(parseInt(t.staffing_rating,10),1,5);if(n==="qm")return m(parseInt(t.qm_rating,10),1,5);if(n==="occupancy")return m(Number(t.occupancy_pct),40,100);if(n==="adc")return m(Number(t.average_number_of_residents_per_day),0,200);if(n==="beds")return m(Number(t.number_of_certified_beds),0,250);if(n==="hprd")return m(Number(t.total_nurse_hprd),2.5,5.5);if(n==="turnover")return m(Number(t.nursing_turnover),20,80);if(n==="ss_rehosp")return m(Number(t.ss_rehospitalization),15,30);if(n==="ss_ed")return m(Number(t.ss_ed_visits),8,20);if(n==="ls_hosp")return m(Number(t.ls_hospitalizations),1,4);if(n==="ls_ed")return m(Number(t.ls_ed_visits),.5,3);const j=l?.[t.ccn];return n==="agency"?m(Number(j?.nursing_agency_pct),0,30):n==="admin_tenure"?m(Number(j?.admin_tenure_days),0,1825):n==="don_tenure"?m(Number(j?.don_tenure_days),0,1825):n==="op_margin"?m(Number(t._fin?.operating_margin_pct),-15,15):n==="rev_ppd"?m(Number(t._fin?.net_revenue_ppd),200,600):n==="exp_ppd"?m(Number(t._fin?.cost_per_day),200,600):n==="dso"?m(Number(t._fin?.dso_days),20,80):n==="insight"?m(Number(t.insight_score),20,80):n==="rank"?m(Number(t.market_rank),1,50):null}function an(t){return t==="rank"?[{color:"#1e3a5f",label:"Top 3"},{color:"#94a3b8",label:"Middle"},{color:"#b91c1c",label:"Bottom 3"}]:["stars","qm","staffing","health"].includes(t)?[{color:"#059669",label:"4-5â
"},{color:"#94a3b8",label:"3â
"},{color:"#d97706",label:"2â
"},{color:"#dc2626",label:"1â
"}]:t==="agency"?[{color:"#94a3b8",label:"0%"},{color:"rgb(252,200,200)",label:"Low"},{color:"rgb(220,114,114)",label:"Mid"},{color:"rgb(185,28,28)",label:"30%+"}]:t==="turnover"?[{color:"rgb(16,185,129)",label:"â¤20%"},{color:"rgb(200,130,80)",label:"~50%"},{color:"rgb(239,68,68)",label:"80%+"}]:t==="admin_tenure"||t==="don_tenure"?[{color:"rgb(239,68,68)",label:"<1yr"},{color:"rgb(200,130,80)",label:"~2.5yr"},{color:"rgb(16,185,129)",label:"5yr+"}]:t==="hprd"?[{color:"rgb(239,68,68)",label:"â¤2.5"},{color:"rgb(200,130,80)",label:"~4.0"},{color:"rgb(16,185,129)",label:"5.5+"}]:t==="occupancy"?[{color:"rgb(239,68,68)",label:"â¤40%"},{color:"rgb(200,130,80)",label:"~65%"},{color:"rgb(16,185,129)",label:"95%+"}]:[]}function ln({data:t,rankedResults:n,liteMarkers:l,submitted:i,selectedLabel:o,showSNFs:m,setShowSNFs:j,showHospitals:N,setShowHospitals:P,showHomeHealth:f,setShowHomeHealth:A,showRadius:$,setShowRadius:a,clusterMarkers:M,setClusterMarkers:p,mapFullscreen:L,setMapFullscreen:Y,highlightCcn:b,colorMode:E,setColorMode:k,sizeBy:S,setSizeBy:V,staffingMap:Q,drawMode:U,setDrawMode:te,onBboxSelect:G}){const _=d.useRef(null),y=()=>{_.current&&(document.fullscreenElement?document.exitFullscreen().catch(()=>{}):_.current.requestFullscreen().catch(()=>{}))};d.useEffect(()=>{const h=()=>Y(!!document.fullscreenElement);return document.addEventListener("fullscreenchange",h),()=>document.removeEventListener("fullscreenchange",h)},[Y]);const x=d.useMemo(()=>an(E),[E]),z=Le.find(h=>h.key===E)?.label||"",R=Le.find(h=>h.key===E)?.tip;return e.jsxs("div",{ref:_,className:"bg-white rounded-xl border border-slate-200 shadow-sm overflow-hidden flex flex-col",style:L?{height:"100vh"}:{},children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-2.5 border-b border-slate-200 flex-shrink-0",style:{position:"relative",zIndex:10},children:[e.jsxs("p",{className:"text-sm font-semibold text-slate-700",children:[i?.bbox?`${t.total_facilities} SNFs in selected area`:`${t.total_facilities}
2 SNFs within ${t.radius_miles} miles${o?` of ${o}`:i?.ccn?` of ${i.ccn}`:""}`,t.county_name&&e.jsxs("span",{className:"text-slate-400 font-normal",children:[" (",t.county_name,")"]})]}),e.jsx("button",{onClick:y,className:"text-slate-400 hover:text-sky-600 transition-colors",title:L?"Exit fullscreen":"Fullscreen",children:L?e.jsx(ft,{size:16}):e.jsx(gt,{size:16})})]}),e.jsxs("div",{className:"relative flex-1 flex flex-col",children:[e.jsx(xn,{data:t,rankedResults:n,liteMarkers:l,clusterMarkers:M,showSNFs:m,showHospitals:N,showHomeHealth:f,showRadius:$,fullscreen:L,submitted:i,highlightCcn:b||t.center_ccn,colorMode:E,sizeBy:S,staffingMap:Q,drawMode:U,onBboxSelect:G}),e.jsxs("div",{className:"absolute top-3 left-3 z-[400] bg-white/95 backdrop-blur-sm border border-slate-200 rounded-lg shadow-md px-3 py-2.5 flex flex-col gap-2 text-xs w-[230px]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-slate-500 uppercase tracking-wide font-medium w-9 flex-shrink-0",children:"Color"}),e.jsx("select",{value:E,onChange:h=>k(h.target.value),className:"flex-1 text-xs border border-slate-200 rounded px-2 py-1 bg-white focus:ring-2 focus:ring-sky-500 outline-none min-w-0",children:Le.map(h=>e.jsx("option",{value:h.key,children:h.label},h.key))}),R&&e.jsx(Ke,{text:R,size:11,position:"below"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-slate-500 uppercase tracking-wide font-medium w-9 flex-shrink-0",children:"Size"}),e.jsxs("select",{value:S,onChange:h=>V(h.target.value),className:"flex-1 text-xs border border-slate-200 rounded px-2 py-1 bg-white focus:ring-2 focus:ring-sky-500 outline-none min-w-0",children:[e.jsx("option",{value:"uniform",children:"Uniform"}),Le.map(h=>e.jsx("option",{value:h.key,children:h.label},h.key))]})]}),e.jsx("div",{className:"h-px bg-slate-100"}),e.jsxs("div",{className:"grid grid-cols-2 gap-x-3 gap-y-1.5 text-[11px] text-slate-600",children:[e.jsxs("label",{className:"flex items-center gap-1.5 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:m,onChange:h=>j(h.target.checked),className:"rounded border-slate-300 text-sky-600 focus:ring-sky-500"}),"SNFs"]}),e.jsxs("label",{className:"flex items-center gap-1.5 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:N,onChange:h=>P(h.target.checked),className:"rounded border-slate-300 text-sky-600 focus:ring-sky-500"}),"Hospitals"]}),e.jsxs("label",{className:"flex items-center gap-1.5 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:f,onChange:h=>A(h.target.checked),className:"rounded border-slate-300 text-teal-600 focus:ring-teal-500"}),"Home Health"]}),e.jsxs("label",{className:"flex items-center gap-1.5 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:$,onChange:h=>a(h.target.checked),className:"rounded border-slate-300 text-slate-400 focus:ring-slate-400"}),i?.bbox?"Selection":"Radius"]}),e.jsxs("label",{className:"flex items-center gap-1.5 cursor-pointer",title:"Group nearby markers into clusters",children:[e.jsx("input",{type:"checkbox",checked:M,onChange:h=>p(h.target.checked),className:"rounded border-slate-300 text-slate-600 focus:ring-slate-500"}),"Cluster"]})]}),e.jsx("div",{className:"h-px bg-slate-100"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("button",{onClick:()=>te(!U),className:`flex-1 flex items-center justify-center gap-1.5 border rounded px-2 py-1.5 transition-colors ${U?"bg-sky-100 border-sky-300 text-sky-700":"border-slate-200 text-slate-600 hover:text-sky-600 hover:bg-sky-50"}`,children:[e.jsx(Ee,{size:11}),U?"Cancel":"Draw Box"]}),i?.bbox&&!U&&e.jsx("button",{onClick:()=>te(!0),className:"flex items-center gap-1 border border-slate-200 text-slate-500 hover:text-slate-700 hover:bg-slate-50 rounded px-2 py-1.5 transition-colors",title:"Redraw selection",children:e.jsx(Fe,{size:11})})]})]}),x.length>0&&e.jsxs("div",{className:"absolute bottom-3 right-3 z-[400] bg-white/95 backdrop-blur-sm border border-slate-200 rounded-lg shadow-md px-3 py-2 text-[11px] max-w-[180px]",children:[e.jsx("div",{className:"text-[10px] text-slate-500 uppercase tracking-wide font-medium mb-1.5",children:z}),e.jsxs("div",{className:"flex flex-col gap-1",children:[x.map((h,q)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full flex-shrink-0",style:{background:h.color}}),e.jsx("span",{className:"text-slate-600",children:h.label})]},q)),N&&e.jsxs("div",{className:"flex items-center gap-2 pt-1 mt-0.5 border-t border-slate-100",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-sm flex-shrink-0",style:{background:"#7c3aed"}}),e.jsx("span",{className:"text-slate-600",children:"Hospital"})]})]})]}),U&&e.jsxs("div",{className:"absolute top-3 left-1/2 -translate-x-1/2 z-[450] bg-slate-900/90 backdrop-blur-sm text-white text-xs rounded-lg shadow-md px-3 py-1.5 flex items-center gap-2 pointer-events-none",children:[e.jsx(Ee,{size:11,className:"text-sky-300"}),e.jsx("span",{children:"Click two corners to draw a box"}),e.jsx("span",{className:"text-slate-400",children:"·"}),e.jsx("span",{className:"text-slate-300",children:"Esc to cancel"})]})]})]})}const on='<div class="snf-hospital-marker"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="14" height="14"><path d="M12 5v14M5 12h14" stroke="white" stroke-width="3" stroke-linecap="round"/></svg></div>',cn='<div style="width:20px;height:20px;border-radius:50%;background:#0d9488;border:2px solid white;box-shadow:0 1px 3px rgba(0,0,0,.4);display:flex;align-items:center;justify-content:center;"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="white" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><path d="M3 10.5L12 3l9 7.5"/><path d="M5 9.5V21h14V9.5"/></svg></div>';let ye=null,ve=null;async function dn(){if(ye)return ye;try{ye=await(await fetch("/geo/us-states.json")).json()}catch{ye=null}return ye}async function un(){if(ve)return ve;try{const[t,n]=await Promise.all([fetch("/geo/us-counties-10m.json"),Ae(()=>import("./index-BnENo9bV.js"),[])]),l=await t.json();ve=(n.default||n).feature(l,l.objects.counties)}catch{ve=null}return ve}function pn(t,n){dn().then(m=>{!m||!n||t.geoJSON(m,{style:()=>({color:"#94a3b8",weight:.8,opacity:.6,fill:!1,interactive:!1})}).addTo(n)});let l=null,i=!1;const o=()=>{const m=n.getZoom();if(m<8){l&&l.setStyle({opacity:0}
2);return}if(l){const j=Math.min(.5,Math.max(0,(m-8)*.25));l.setStyle({opacity:j});return}i||(i=!0,un().then(j=>{i=!1,!(!j||!n)&&(l=t.geoJSON(j,{style:()=>({color:"#cbd5e1",weight:.5,opacity:0,fill:!1,interactive:!1})}).addTo(n),o())}))};n.on("zoomend",o),o()}function xn({data:t,rankedResults:n,liteMarkers:l,clusterMarkers:i=!0,showSNFs:o,showHospitals:m,showHomeHealth:j,showRadius:N,fullscreen:P,submitted:f,highlightCcn:A,colorMode:$,sizeBy:a="uniform",staffingMap:M,drawMode:p,onBboxSelect:L}){const Y=d.useRef(null),b=d.useRef(null),E=d.useRef({snf:[],hospital:[],homehealth:[],radius:null,center:null,snfCluster:null}),k=d.useRef(new Map),S=d.useRef(null),V=d.useRef(null),Q=d.useRef(null);d.useEffect(()=>{if(!Y.current||b.current)return;let _=!1;return Ae(()=>import("./leaflet-src-84_lqfRu.js").then(y=>y.l),__vite__mapDeps([0,1,2])).then(async y=>{const x=y.default||y;typeof window<"u"&&(window.L=x);try{await Ae(()=>import("./leaflet.markercluster-src-CNh4IanG.js").then(R=>R.l),__vite__mapDeps([3,1,2]))}catch{}if(_||!Y.current)return;Q.current=x,delete x.Icon.Default.prototype._getIconUrl,x.Icon.Default.mergeOptions({iconRetinaUrl:"https://unpkg.com/[email protected]/dist/images/marker-icon-2x.png",iconUrl:"https://unpkg.com/[email protected]/dist/images/marker-icon.png",shadowUrl:"https://unpkg.com/[email protected]/dist/images/marker-shadow.png"});const z=x.map(Y.current,{center:[t.center_lat,t.center_lon],zoom:10,scrollWheelZoom:!0,zoomDelta:.5,zoomSnap:.5,wheelPxPerZoomLevel:300});if(x.tileLayer(_t,{...bt,maxZoom:19}).addTo(z),b.current=z,G(x,z),pn(x,z),f?.bbox&&f.north!=null)z.fitBounds(x.latLngBounds([f.south,f.west],[f.north,f.east]),{padding:[40,40],animate:!1});else if(t?.center_lat&&t?.center_lon){const R=(f?.radius||t.radius_miles||15)/69,h=[Number(t.center_lat),Number(t.center_lon)];z.fitBounds(x.latLngBounds([h[0]-R,h[1]-R*1.3],[h[0]+R,h[1]+R*1.3]),{padding:[40,40],animate:!1})}setTimeout(()=>z.invalidateSize({animate:!1}),50),setTimeout(()=>z.invalidateSize({animate:!1}),250)}),()=>{_=!0}},[]),d.useEffect(()=>{!b.current||!Q.current||G(Q.current,b.current)},[t,n,l,o,m,j,N,A,$,a,M,i]);const U=d.useRef(!0);d.useEffect(()=>{if(!b.current)return;const _=b.current,y=[setTimeout(()=>_.invalidateSize({animate:!1}),100),setTimeout(()=>_.invalidateSize({animate:!1}),400)];return()=>y.forEach(clearTimeout)},[P]),d.useEffect(()=>{if(!b.current||!Q.current||!f)return;const _=b.current,y=Q.current;if(f.bbox&&f.north!=null)_.fitBounds(y.latLngBounds([f.south,f.west],[f.north,f.east]),{padding:[40,40],animate:!0});else if(t?.center_lat&&t?.center_lon){const x=(f.radius||t.radius_miles||15)/69,z=[Number(t.center_lat),Number(t.center_lon)],R=y.latLngBounds([z[0]-x,z[1]-x*1.3],[z[0]+x,z[1]+x*1.3]);_.fitBounds(R,{padding:[40,40],animate:!0})}},[f,t?.center_lat,t?.center_lon]);const te=d.useRef(null);d.useEffect(()=>{if(!b.current||!A||A===t?.center_ccn||te.current===A)return;te.current=A;const y=(l||n||[]).find(R=>R.ccn===A);if(!y||!y.latitude||!y.longitude)return;const x=b.current,z=Math.max(x.getZoom(),12);x.flyTo([Number(y.latitude),Number(y.longitude)],z,{duration:.85,easeLinearity:.25})},[A,t?.center_ccn,l,n]),d.useEffect(()=>{if(!b.current||!Q.current)return;const _=b.current,y=Q.current,x=_.getContainer();if(p){x.style.cursor="crosshair",_.dragging.disable(),_.doubleClickZoom.disable(),_.boxZoom.disable();const z=I=>{const K=x.getBoundingClientRect();return y.point(I.clientX-K.left,I.clientY-K.top)},R=I=>_.containerPointToLatLng(z(I)),h=I=>{if(!(I.button!==void 0&&I.button!==0))if(I.preventDefault(),I.stopPropagation(),!S.current)S.current=R(I);else{const K=y.latLngBounds(S.current,R(I));if(S.current=null,_.latLngToLayerPoint(K.getNorthEast()).distanceTo(_.latLngToLayerPoint(K.getSouthWest
2()))<20){V.current&&(_.removeLayer(V.current),V.current=null);return}L({north:K.getNorth(),south:K.getSouth(),east:K.getEast(),west:K.getWest()})}},q=I=>{if(!S.current)return;const K=y.latLngBounds(S.current,R(I));V.current?V.current.setBounds(K):V.current=y.rectangle(K,{color:"#0ea5e9",weight:2,dashArray:"6 4",fillOpacity:.1,interactive:!1}).addTo(_)},X=I=>{I.key==="Escape"&&(S.current=null,V.current&&(_.removeLayer(V.current),V.current=null))};return x.addEventListener("pointerdown",h,!0),x.addEventListener("pointermove",q,!0),window.addEventListener("keydown",X),()=>{x.style.cursor="",_.dragging.enable(),_.doubleClickZoom.enable(),_.boxZoom.enable(),x.removeEventListener("pointerdown",h,!0),x.removeEventListener("pointermove",q,!0),window.removeEventListener("keydown",X),V.current&&(_.removeLayer(V.current),V.current=null),S.current=null}}else x.style.cursor="",_.dragging.enable()},[p,L]);const G=d.useCallback((_,y)=>{const x=E.current;if(U.current!==i){for(const[,r]of k.current.entries())x.snfCluster&&x.snfCluster.removeLayer(r),y.removeLayer(r);k.current.clear(),U.current=i}if(x.hospital.forEach(r=>y.removeLayer(r)),x.homehealth.forEach(r=>y.removeLayer(r)),x.radius&&y.removeLayer(x.radius),x.center&&y.removeLayer(x.center),x.hospital=[],x.homehealth=[],x.radius=null,x.center=null,!x.snfCluster&&_.markerClusterGroup){const r=c=>{const C=c.getChildCount(),T={5:0,4:0,3:0,2:0,1:0,0:0};c.getAllChildMarkers().forEach(W=>{const D=W.options._rating;D>=1&&D<=5?T[D]++:T[0]++});const v={5:"#059669",4:"#22c55e",3:"#0284c7",2:"#d97706",1:"#dc2626",0:"#94a3b8"},O=[];let H=0;for(const W of[5,4,3,2,1,0]){if(T[W]===0)continue;const D=T[W]/C*100;O.push(`${v[W]} ${H.toFixed(2)}% ${(H+D).toFixed(2)}%`),H+=D}return O.length===0?"#94a3b8":O.length===1?v[Object.keys(T).find(W=>T[W]===C)]:`conic-gradient(${O.join(", ")})`};x.snfCluster=_.markerClusterGroup({chunkedLoading:!0,spiderfyOnMaxZoom:!0,showCoverageOnHover:!1,maxClusterRadius:80,animate:!0,animateAddingMarkers:!1,iconCreateFunction:c=>{const C=c.getChildCount(),T=r(c);if(C<5)return _.divIcon({html:`<div class="snf-marker-dot" style="width:24px;height:24px;background:${T};"></div>`,className:"",iconSize:[24,24],iconAnchor:[12,12]});const v=C<25?40:C<100?48:C<500?56:C<2e3?64:72,O=Math.max(v-14,22),H=` 3 <div class="snf-cluster" style="width:${v}px;height:${v}px;background:${T};"> 4 <div style="width:${O}px;height:${O}px;background:white;border-radius:50%;display:flex;align-items:center;justify-content:center;font-size:${v>56?14:12}px;font-weight:700;color:#0f172a;">${C.toLocaleString()}</div> 5 </div>`;return _.divIcon({html:H,className:"",iconSize:[v,v],iconAnchor:[v/2,v/2]})}}),y.addLayer(x.snfCluster)}const z=n?.length?n:t.results||[],R=l&&l.length>z.length,h=R?l:z,q={};h.forEach(r=>{if(!r.latitude||!r.longitude)return;const c=`${(+r.latitude).toFixed(4)},${(+r.longitude).toFixed(4)}`;(q[c]=q[c]||[]).push(r.ccn)});const X=.009,I=r=>{let c=+r.latitude,C=+r.longitude;const T=`${c.toFixed(4)},${C.toFixed(4)}`,v=q[T];if(v&&v.length>1){const O=v.indexOf(r.ccn),H=2*Math.PI*O/v.length,W=Math.cos(c*Math.PI/180)||1;c+=X*Math.cos(H),C+=X/W*Math.sin(H)}return[c,C]},K=f?`?from=market${f.ccn?`&market_ccn=${f.ccn}`:""}&radius=${f.radius||""}`:"",je=A||t.center_ccn;if(N&&(f?.bbox?x.radius=_.rectangle([[f.south,f.west],[f.north,f.east]],{color:"#0ea5e9",fillColor:"#0ea5e9",fillOpacity:.06,weight:1.5,dashArray:"6 4"}).addTo(y):x.radius=_.circle([t.center_lat,t.center_lon],{radius:t.radius_miles*1609.34,color:"#0ea5e9",fillColor:"#0ea5e9",fillOpacity:.06,weight:1.5,dashArray:"6 4"}).addTo(y)),!R){for(const[,r]of k.current.entries())x.snfCluster&&x.snfCluster.removeLayer(r),y.removeLayer(r);k.current.clear()}const Ne=new Set;o&&h.length&&h.forEach(r=>{r.latitude&&r.longitude&&Ne.add(`${r.ccn}__${R?"lite":"full"}`)});for(const[r,c]of[...k.current.entries()])Ne.has(r)||(x.snfCluster&&x.snfCluster.removeLayer(c),y.removeLayer(c),k.current.delete(r));const de=[],_e=new Set(["stars","health","staffing","qm","occupancy","hprd","turnover"]).has($)?$:"stars",De=r=>{if(a==="uniform"||!a)return 24;
5const c=pt(r,a,M,14,56);return c??24};if(o&&h.length&&R)h.forEach(r=>{if(!r.latitude||!r.longitude)return;const c=`${r.ccn}__lite__${_e}__${a}`;if(k.current.has(c))return;const C=parseInt(r.overall_rating,10),T=dt(r,_e,M)||"#94a3b8",v=De(r),O=ut(r,_e,M),H=v>=22&&O!==""&&O!=="?",W=v>=32?11:v>=26?10:9,D=_.divIcon({html:`<div class="snf-marker-dot" style="width:${v}px;height:${v}px;background:${T};${H?`font-size:${W}px;`:""}">${H?O:""}</div>`,iconSize:[v,v],iconAnchor:[v/2,v/2],className:""}),J=_.marker(I(r),{icon:D,_rating:C}).bindPopup(`<div style="min-width:180px;font-size:12px;line-height:1.5;"><b style="font-size:13px;">${r.provider_name||""}</b><br><span style="color:#64748b;">${r.ccn}</span><br>${r.citytown||""}, ${r.state||""}<br>${C?C+"â
":"Unrated"}`+(r.number_of_certified_beds?` · ${r.number_of_certified_beds} beds`:"")+(r.average_number_of_residents_per_day?` · ADC ${Math.round(Number(r.average_number_of_residents_per_day))}`:"")+`<br><a href="/facility/${r.ccn}${K}" style="color:#0ea5e9;text-decoration:underline;font-size:11px;">Open facility →</a></div>`,{maxWidth:280});k.current.set(c,J),de.push(J)});else if(o&&h.length){const r=c=>{if(a==="uniform"||!a)return 24;const C=pt(c,a,M,16,56);return C??24};h.forEach(c=>{if(!c.latitude||!c.longitude)return;const C=`${c.ccn}__full__${$}__${a}`;if(k.current.has(C))return;const T=c.ccn===je,v={...c,_fin:M[c.ccn]||{}},O=dt(v,$,M),H=ut(v,$,M),W=r(c),D=T?W+6:W,J=D>=36?13:D>=28?11:D>=22?10:9,be=D>=20&&H!==""&&H!=="?",pe=_.divIcon({html:`<div class="snf-marker-dot${T?" is-selected":""}" style="width:${D}px;height:${D}px;background:${O};font-size:${J}px;">${be?H:""}</div>`,iconSize:[D,D],iconAnchor:[D/2,D/2],className:""}),ne=M?.[c.ccn],ie=[["Overall Rating",c.overall_rating],["Health Inspection",c.health_inspection_rating],["Staffing Rating",c.staffing_rating],["QM Rating",c.qm_rating],["Occupancy",c.occupancy_pct!=null?c.occupancy_pct+"%":null],["Total Nurse HPRD",c.total_nurse_hprd],["RN HPRD",c.rn_hprd],["Nursing Turnover",c.nursing_turnover!=null?c.nursing_turnover+"%":null],["Agency %",ne?.nursing_agency_pct!=null?ne.nursing_agency_pct.toFixed(1)+"%":null],["Admin Tenure",ne?.admin_tenure_days!=null?he(ne.admin_tenure_days):null],["DON Tenure",ne?.don_tenure_days!=null?he(ne.don_tenure_days):null],["Case Mix Index",c.case_mix_index],["Admin Turnover",c.admin_turnover],["SS Rehospitalization",c.ss_rehospitalization!=null?c.ss_rehospitalization+"%":null],["SS ED Visits",c.ss_ed_visits!=null?c.ss_ed_visits+"%":null],["LS Hospitalizations",c.ls_hospitalizations],["LS ED Visits",c.ls_ed_visits]].filter(([,re])=>re!=null),xe=(re,ue)=>`<td style="color:#64748b;padding-right:6px;white-space:nowrap;">${re}</td><td style="font-weight:600;padding-right:16px;">${ue}</td>`;let se="";for(let re=0;re<ie.length;re+=2){const ue=ie[re+1];se+=`<tr>${xe(ie[re][0],ie[re][1])}${ue?xe(ue[0],ue[1]):"<td></td><td></td>"}</tr>`}const we=c.market_rank!=null?c.market_rank:"",Pe=c.insight_score!=null?c.insight_score>=70?"#059669":c.insight_score>=50?"#0284c7":c.insight_score>=35?"#d97706":"#dc2626":"#94a3b8",Te=c.insight_score!=null?`<span style="font-weight:700;color:${Pe};">InsightScore: ${Math.round(c.insight_score)}</span>${c.market_rank!=null?` · #${we} in market`:""}<br>`:"",Se=_.marker(I(c),{icon:pe,zIndexOffset:T?1e3:c.market_rank!=null&&c.market_rank<=3?500:0,_rating:Number(c.overall_rating)}).bindPopup(`<div style="min-width:320px;font-size:12px;line-height:1.5;"><b style="font-size:13px;">${c.provider_name}</b><br><span style="color:#64748b;">${c.ccn}</span><br>${c.citytown||""}, ${c.state||""}<br>`+Te+`<b>${sn(c.overall_rating)}</b> · ${c.number_of_certified_beds||"?"} beds · ${c.distance_miles?.toFixed(1)||"?"} mi`+(c.chain_name?`<br><span style="color:#94a3b8;font-size:11px;">${c.chain_name}</span>`:"")+(se?`<table style="margin-top:4px;font-size:11px;border-collapse:collapse;">${se}</table>`:"")+`<br><a href="/facility/${c.ccn}${K}" style="color:#0ea5e9;text-decoration:underline;font-size:11px;">Open facility →</a></div>`,{maxWidth:420});k.current.set(C,Se),de.push(Se)})}de.length&&(i&&x.snfCluster?x.snfCluster.addLayers(de):de.forEach(r=>
5r.addTo(y))),m&&t.hospitals&&t.hospitals.forEach(r=>{if(!r.latitude||!r.longitude)return;const c=_.divIcon({html:on,iconSize:[22,22],iconAnchor:[11,11],className:""}),C=r.hospital_overall_rating&&/^[1-5]$/.test(r.hospital_overall_rating)?`${r.hospital_overall_rating}-Star Overall`:null,T=[r.pt_exp_measures?`${r.pt_exp_measures} patient-survey measures`:null,r.te_measures?`${r.te_measures} timely & effective care measures`:null].filter(Boolean).join(" · "),v=/Worse/i.test(r.hwr_compared||"")?"#dc2626":/Better/i.test(r.hwr_compared||"")?"#059669":"#64748b",O=r.hwr_compared?r.hwr_compared.replace(/ Than the National Rate$/i,"").toLowerCase():null,H=r.hwr_rate!=null?`<div style="margin-top:4px;padding:3px 0;border-top:1px solid #eef2f7;"><b>30-day readmission: ${r.hwr_rate.toFixed(1)}%</b>`+(O?` <span style="color:${v};font-weight:600;">(${O})</span>`:"")+(r.hwr_denominator?`<br><span style="color:#94a3b8;font-size:10px;">${r.hwr_denominator.toLocaleString()} eligible discharges</span>`:"")+"</div>":"",W=[r.readm_hf!=null?`HF ${r.readm_hf.toFixed(1)}%`:null,r.readm_pn!=null?`Pneumonia ${r.readm_pn.toFixed(1)}%`:null,r.readm_copd!=null?`COPD ${r.readm_copd.toFixed(1)}%`:null].filter(Boolean).join(" · "),D=W?`<div style="color:#64748b;font-size:10px;">By condition: ${W}</div>`:"",J=se=>se>=1e9?`$${(se/1e9).toFixed(2)}B`:se>=1e6?`$${Math.round(se/1e6).toLocaleString()}M`:`$${Math.round(se).toLocaleString()}`,be=r.cr_total_margin_pct==null?"#64748b":r.cr_total_margin_pct<0?"#dc2626":"#059669",pe=[r.cr_occupancy_pct!=null?`Occupancy ${r.cr_occupancy_pct.toFixed(1)}%`:null,r.cr_staffed_beds!=null?`${r.cr_staffed_beds.toLocaleString()} beds`:null].filter(Boolean).join(" · "),ne=[r.cr_medicare_day_pct!=null?`Medicare days ${r.cr_medicare_day_pct.toFixed(1)}%`:null,r.cr_cost_per_day!=null?`Cost/day $${Math.round(r.cr_cost_per_day).toLocaleString()}`:null].filter(Boolean).join(" · "),ie=r.cr_fy_year!=null?`<div style="margin-top:4px;padding-top:3px;border-top:1px solid #eef2f7;"><b>Financials · FY${r.cr_fy_year}</b> <span style="color:#94a3b8;font-size:10px;">(${r.cr_status||"cost report"})</span>`+(r.cr_net_patient_revenue!=null?`<br>Net patient revenue: <b>${J(r.cr_net_patient_revenue)}</b>`:"")+(r.cr_total_margin_pct!=null?`<br>Total margin: <b style="color:${be};">${r.cr_total_margin_pct.toFixed(1)}%</b>`:"")+(pe?`<br><span style="color:#64748b;">${pe}</span>`:"")+(ne?`<br><span style="color:#64748b;">${ne}</span>`:"")+`<div style="color:#94a3b8;font-size:10px;margin-top:1px;">CMS cost report (Form 2552-10)</div><a href="/hospital-cost-reports?ccn=${r.facility_id}" target="_blank" rel="noopener noreferrer" style="display:inline-block;margin-top:5px;padding:3px 9px;background:#f8fafc;border:1px solid #e2e8f0;border-radius:6px;color:#0369a1;font-size:11px;font-weight:600;text-decoration:none;">View full cost report →</a></div>`:"",xe=_.marker([r.latitude,r.longitude],{icon:c,zIndexOffset:500}).addTo(y).bindPopup(`<div style="min-width:300px;font-size:12px;line-height:1.5;"><b style="font-size:13px;color:#7c3aed;">${r.facility_name}</b><br><span style="color:#64748b;">${r.facility_id||""}</span><br>`+(r.address?`${r.address}<br>`:"")+`${r.citytown||""}, ${r.state||""} ${r.zip_code||""}<br>`+(r.telephone_number?`${r.telephone_number}<br>`:"")+`<b>${r.hospital_type||"Hospital"}</b>`+(C?` · <b style="color:#7c3aed;">${C}</b>`:"")+`<br>${r.hospital_ownership||""}<br>Emergency: ${r.emergency_services||"N/A"}`+H+D+ie+(T?`<div style="margin-top:3px;color:#94a3b8;font-size:10px;">${T}</div>`:"")+"</div>",{maxWidth:380});x.hospital.push(xe)}),j&&t.home_health&&t.home_health.forEach(r=>{if(!r.latitude||!r.longitude)return;const c=_.divIcon({html:cn,iconSize:[20,20],iconAnchor:[10,10],className:""}),C=/^[0-9]/.test(r.quality_star_rating||""),T=[r.offers_nursing==="Yes"?"Nursing":null,r.offers_pt==="Yes"?"PT":null,r.offers_ot==="Yes"?"OT":null,r.offers_speech==="Yes"?"Speech":null,r.offers_social==="Yes"?"MSW":null,r.offers_aide==="Yes"?"Aide":null].filter(Boolean).join(" · "),v=J=>J>=1e9?`$${(J/1e9).toFixed(2)}B`:J>
5=1e6?`$${Math.round(J/1e6).toLocaleString()}M`:`$${Math.round(J).toLocaleString()}`,O=r.cr_total_margin_pct==null?"#64748b":r.cr_total_margin_pct<0?"#dc2626":"#059669",H=[r.cr_total_visits!=null?`${r.cr_total_visits.toLocaleString()} visits`:null,r.cr_unduplicated_census!=null?`${r.cr_unduplicated_census.toLocaleString()} patients`:null,r.cr_cost_per_visit!=null?`$${Math.round(r.cr_cost_per_visit).toLocaleString()}/visit`:null].filter(Boolean).join(" · "),W=r.cr_fy_year!=null?`<div style="margin-top:4px;padding-top:3px;border-top:1px solid #eef2f7;"><b>Financials · FY${r.cr_fy_year}</b> <span style="color:#94a3b8;font-size:10px;">(${r.cr_status||"cost report"})</span>`+(r.cr_net_patient_revenue!=null?`<br>Net patient revenue: <b>${v(r.cr_net_patient_revenue)}</b>`:"")+(r.cr_total_margin_pct!=null?`<br>Total margin: <b style="color:${O};">${r.cr_total_margin_pct.toFixed(1)}%</b>`:"")+(H?`<br><span style="color:#64748b;">${H}</span>`:"")+`<div style="color:#94a3b8;font-size:10px;margin-top:1px;">CMS cost report (Form 1728-20)</div><a href="/home-health-cost-reports?ccn=${r.ccn}" target="_blank" rel="noopener noreferrer" style="display:inline-block;margin-top:5px;padding:3px 9px;background:#f8fafc;border:1px solid #e2e8f0;border-radius:6px;color:#0369a1;font-size:11px;font-weight:600;text-decoration:none;">View full cost report →</a></div>`:"",D=_.marker([r.latitude,r.longitude],{icon:c,zIndexOffset:400}).addTo(y).bindPopup(`<div style="min-width:240px;font-size:12px;line-height:1.5;"><b style="font-size:13px;color:#0d9488;">${r.provider_name}</b><br><span style="color:#64748b;">${r.ccn||""}</span><br>${r.citytown||""}, ${r.state||""}<br>`+(r.telephone_number?`${r.telephone_number}<br>`:"")+"<b>Home Health Agency</b>"+(C?` · <b style="color:#f59e0b;">${r.quality_star_rating}★ quality</b>`:' · <span style="color:#94a3b8;">not rated</span>')+`<br>${r.ownership||""}`+(r.timely_care_pct!=null?`<div style="margin-top:4px;padding-top:3px;border-top:1px solid #eef2f7;">Timely start of care: <b>${r.timely_care_pct.toFixed(1)}%</b></div>`:"")+(T?`<div style="color:#64748b;font-size:10px;margin-top:2px;">Services: ${T}</div>`:"")+'<div style="color:#94a3b8;font-size:10px;margin-top:1px;">CMS Home Health Compare</div>'+W+"</div>",{maxWidth:320});x.homehealth.push(D)})},[t,n,l,o,m,j,N,f,A,$,a,M,i]);return e.jsx("div",{ref:Y,style:P?{flex:1}:{height:"650px",width:"100%"}})}function mn({drawMode:t,setDrawMode:n,onBboxSelect:l}){const i=d.useRef(null),o=d.useRef(null),m=d.useRef(null),j=d.useRef(null),N=d.useRef(null),P=d.useRef(null),[f,A]=d.useState(!1);d.useEffect(()=>{if(!i.current||o.current)return;let a=!1;return Ae(()=>import("./leaflet-src-84_lqfRu.js").then(M=>M.l),__vite__mapDeps([0,1,2])).then(M=>{if(a||!i.current)return;P.current=M;const p=M.map(i.current,{center:[39.5,-98.5],zoom:5,scrollWheelZoom:!0,zoomDelta:.5,zoomSnap:.5,wheelPxPerZoomLevel:300});M.tileLayer(_t,{...bt,maxZoom:19}).addTo(p),o.current=p,setTimeout(()=>p.invalidateSize({animate:!1}),50)}),()=>{a=!0}},[]),d.useEffect(()=>{if(!o.current||!P.current)return;const a=o.current,M=P.current,p=a.getContainer();if(t){p.style.cursor="crosshair",a.dragging.disable(),a.doubleClickZoom.disable(),a.boxZoom.disable();const L=k=>{const S=p.getBoundingClientRect();return a.containerPointToLatLng(M.point(k.clientX-S.left,k.clientY-S.top))},Y=k=>{if(!(k.button!==void 0&&k.button!==0))if(k.preventDefault(),k.stopPropagation(),!j.current)j.current=L(k);else{const S=M.latLngBounds(j.current,L(k));if(j.current=null,a.latLngToLayerPoint(S.getNorthEast()).distanceTo(a.latLngToLayerPoint(S.getSouthWest
5()))<20){N.current&&(a.removeLayer(N.current),N.current=null);return}l({north:S.getNorth(),south:S.getSouth(),east:S.getEast(),west:S.getWest()})}},b=k=>{if(!j.current)return;const S=M.latLngBounds(j.current,L(k));N.current?N.current.setBounds(S):N.current=M.rectangle(S,{color:"#0ea5e9",weight:2,dashArray:"6 4",fillOpacity:.1,interactive:!1}).addTo(a)},E=k=>{k.key==="Escape"&&(j.current=null,N.current&&(a.removeLayer(N.current),N.current=null))};return p.addEventListener("pointerdown",Y,!0),p.addEventListener("pointermove",b,!0),window.addEventListener("keydown",E),()=>{p.style.cursor="",a.dragging.enable(),a.doubleClickZoom.enable(),a.boxZoom.enable(),p.removeEventListener("pointerdown",Y,!0),p.removeEventListener("pointermove",b,!0),window.removeEventListener("keydown",E),N.current&&(a.removeLayer(N.current),N.current=null),j.current=null}}else p.style.cursor="",a.dragging.enable()},[t,l]),d.useEffect(()=>{const a=()=>A(!!document.fullscreenElement);return document.addEventListener("fullscreenchange",a),()=>document.removeEventListener("fullscreenchange",a)},[]);const $=()=>{m.current&&(document.fullscreenElement?document.exitFullscreen().catch(()=>{}):m.current.requestFullscreen().catch(()=>{}))};return d.useEffect(()=>{n(!0)},[]),e.jsxs("div",{ref:m,className:"bg-white rounded-xl border border-slate-200 shadow-sm overflow-hidden flex flex-col",style:f?{height:"100vh"}:{},children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-slate-200 flex-shrink-0 flex-wrap gap-2",style:{position:"relative",zIndex:10},children:[e.jsx("p",{className:"text-sm font-semibold text-slate-700",children:"Search a market above or draw a box below"}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("button",{onClick:()=>n(!t),className:`flex items-center gap-1 text-xs border rounded-lg px-2.5 py-1.5 transition-colors ${t?"bg-sky-100 border-sky-300 text-sky-700":"border-slate-200 text-slate-500 hover:text-sky-600 hover:bg-slate-50"}`,children:[e.jsx(Ee,{size:12}),t?"Drawing...":"Draw Box"]}),e.jsx("button",{onClick:$,className:"text-slate-400 hover:text-sky-600 transition-colors",children:f?e.jsx(ft,{size:16}):e.jsx(gt,{size:16})})]})]}),e.jsxs("div",{className:"px-4 py-2.5 bg-sky-50 border-b border-sky-200 text-sm text-sky-700 flex items-center gap-2",children:[e.jsx(Ee,{size:14,className:"flex-shrink-0"}),e.jsx("span",{children:"Click two corners on the map to draw a box around your target area (Esc to cancel). You can also search by facility or city above."})]}),e.jsx("div",{ref:i,style:f?{flex:1}:{height:"550px",width:"100%"}})]})}function xt(t){const n=t.filter(i=>i!=null).sort((i,o)=>i-o);if(!n.length)return null;const l=Math.floor(n.length/2);return n.length%2!==0?n[l]:Math.round((n[l-1]+n[l])/2)}function hn({rankedResults:t,staffingMap:n}){if(!t?.length||!n)return e.jsx("span",{className:"text-slate-400",children:"â"});const l=t.filter(o=>n[o.ccn]?.operating_margin_pct!=null),i=l.filter(o=>n[o.ccn].operating_margin_pct>0);return l.length===0?e.jsx("span",{className:"text-slate-400",children:"â"}):e.jsxs("span",{className:"text-slate-800",children:[Math.round(i.length/l.length*100),"%",e.jsxs("span",{className:"text-[10px] text-slate-400 ml-1",children:["(",i.length,"/",l.length,")"]})]})}function _n({data:t,staffingMap:n,rankedResults:l}){const{totalBeds:i,totalADC:o,occupancy:m,starCounts:j,medAdminTenure:N,medDonTenure:P,agencyPct:f,yoyGrowth:A}=d.useMemo(()=>{let b=0,E=0,k=0,S=0;const V={5:0,4:0,3:0,2:0,1:0};(t.results||[]).forEach(h=>{const q=Number(h.number_of_certified_beds),X=Number(h.average_number_of_residents_per_day);q>0&&(b+=q),X>0&&(E+=X),q>0&&X>0&&(k+=q,S+=X);const I=Number(h.overall_rating);I>=1&&I<=5&&V[I]++});const Q=k>0?S/k*100:null,U=[],te=[];let G=0,_=0;const y=n||{};(t.results||[]).forEach(h=>{const q=y[h.ccn];q&&(q.admin_tenure_days!=null&&U.push(q.admin_tenure_days),q.don_tenure_days!=null&&te.push(q.don_tenure_days),q.nursing_agency_pct!=null&&(_++,q.nursing_agency_pct>0&&G++))});const x=Math.round(E),z=t.prior_year_adc;let R=null;return z&&z>0&&x>0&&(R=(x-z)/z*100),{totalBeds:b,totalADC:Math.round(E),occupancy:Q,starCounts:V,medAdminTenure:xt(U),medDonTenure:xt(te),agencyPct:_>0?Math.round(G/_*100):null,yoyGrowth:R}}
5,[t.results,t.prior_year_adc,n]),$=(t.ma_top_plans||[]).slice(0,5),a=t.county_state||"state";function M(b){return b==null?"":b>=1095?"text-emerald-600":b<365?"text-red-600":""}function p(b){return b==null?"":b<=25?"text-emerald-600":b>=60?"text-red-600":""}function L({label:b,children:E,tip:k,sub:S}){return e.jsxs("div",{className:"bg-white rounded-lg border border-slate-200 px-3 py-2.5",children:[e.jsxs("p",{className:"text-[10px] text-slate-400 uppercase tracking-wide leading-tight",children:[b," ",k&&e.jsx(Ke,{text:k,size:10})]}),e.jsx("p",{className:"text-lg font-bold leading-snug",children:E}),S&&e.jsx("p",{className:"text-[10px] text-slate-400 mt-0.5",children:S})]})}function Y(b,E,k){return b==null||E==null?null:`#${b}/${E} in ${a}`}return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"grid grid-cols-3 md:grid-cols-6 gap-2",children:[e.jsx(L,{label:"SNFs",children:e.jsx("span",{className:"text-slate-800",children:t.total_facilities})}),e.jsx(L,{label:"Profitable",tip:"% of SNFs in market with positive operating margin (from cost reports)",children:e.jsx(hn,{rankedResults:t.results||[],staffingMap:n})}),e.jsx(L,{label:"Occupancy",tip:"ADC / Beds across all SNFs in market",sub:`${o>0?o.toLocaleString():"â"} ADC / ${i>0?i.toLocaleString():"â"} beds${t.state_occupancy_rank!=null?` · #${t.state_occupancy_rank}/${t.state_occupancy_total} in ${a}`:""}`,children:e.jsx("span",{className:"text-slate-800",children:m!=null?m.toFixed(1)+"%":"â"})}),e.jsx(L,{label:"Agency Use",tip:"% of centers using contract/agency nursing staff",sub:Y(t.county_agency_rank,t.county_agency_total),children:e.jsx("span",{className:p(f)||"text-slate-800",children:f!=null?f+"% of ctrs":"â"})}),e.jsx(L,{label:"ADC Growth",tip:"Year-over-year change in total market ADC (average daily census)",sub:Y(t.county_adc_growth_rank,t.county_adc_growth_total),children:A!=null?e.jsxs("span",{className:A>=0?"text-emerald-600":"text-red-600",children:[A>=0?"+":"",A.toFixed(1),"%"]}):e.jsx("span",{className:"text-slate-800",children:"â"})}),e.jsxs("div",{className:"bg-white rounded-lg border border-slate-200 px-3 py-2.5 overflow-hidden",children:[e.jsx("p",{className:"text-[10px] text-slate-400 uppercase tracking-wide leading-tight mb-1",children:"Stars"}),e.jsx("div",{className:"flex items-center justify-between",children:[5,4,3,2,1].map(b=>e.jsxs("div",{className:"flex items-center gap-0.5 min-w-0",children:[e.jsxs("span",{className:"text-[10px] text-slate-400",children:[b,"â
"]}),e.jsx("span",{className:"text-xs font-bold text-slate-700",children:j[b]})]},b))})]})]}),e.jsxs("div",{className:"grid grid-cols-3 md:grid-cols-6 gap-2",children:[e.jsx(L,{label:"Med. Admin Tenure",tip:"Median administrator tenure across market facilities",sub:Y(t.county_admin_tenure_rank,t.county_admin_tenure_total),children:e.jsx("span",{className:M(N)||"text-slate-800",children:N!=null?he(N):"â"})}),e.jsx(L,{label:"Med. DON Tenure",tip:"Median Director of Nursing tenure across market facilities",sub:Y(t.county_don_tenure_rank,t.county_don_tenure_total),children:e.jsx("span",{className:M(P)||"text-slate-800",children:P!=null?he(P):"â"})}),e.jsx(L,{label:"MA Penetration",sub:t.ma_county_ranks?.pen_rank!=null?`#${t.ma_county_ranks.pen_rank}/${t.ma_county_ranks.pen_total} in state`:null,children:t.ma_penetration!=null?t.ma_penetration.toFixed(1)+"%":"â"}),e.jsx(L,{label:"MA Enrolled",sub:t.ma_county_ranks?.enroll_rank!=null?`#${t.ma_county_ranks.enroll_rank}/${t.ma_county_ranks.enroll_total} in state`:null,children:t.ma_county_enrolled!=null?t.ma_county_enrolled.toLocaleString():"â"}),e.jsx(L,{label:"MA Eligible",tip:"Total Medicare beneficiaries eligible for MA in this county",sub:t.ma_county_ranks?.elig_rank!=null?`#${t.ma_county_ranks.elig_rank}/${t.ma_county_ranks.elig_total} in state`:null,children:t.ma_eligible!=null?t.ma_eligible.toLocaleString():"â"}),e.jsx(L,{label:"Elig / Bed",tip:"MA-eligible beneficiaries per SNF bed. Higher = more demand vs supply",sub:t.ma_county_ranks?.elig_bed_rank!=null?`#${t.ma_county_ranks.elig_bed_rank}/${t.ma_county_ranks.elig_bed_total} in state`:null,children:t.ma_eligible>0&&i>0?(t.ma_eligible/i).toFixed(1):"â"})]}),$.length>0&&e.jsxs("div",{className:"bg-white rounded-lg border border-slate-200 px-3 py-2.5",children:[e.jsx("p",{className:"text-[10px] text-slate-400 uppercase tracking-wide mb-1",children:"Top MA Plans"}),e.jsx("div",{className:"flex items-center gap-4 flex-wrap",children:$.map((b,E)=>e.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[e.jsxs("span",{className:"font-bold text-slate-500",children:[E+1,"."]}),e.jsx("span",{className:"font-medium text-slate-700 truncate max-w-[200px]",title:b.organization_marketing_name||b.parent_organization,children:b.organization_marketing_name||b.parent_organization||b.contract_id}),b.enrolled!=null&&e.jsx("span",{className:"text-slate-400",children:b.enrolled.toLocaleStr
5ing()})]},E))})]})]})}const ze=[{key:"insight_score",label:"InsightScore",on:!0,fixed:!0,render:t=>{const n=t.insight_score;if(n==null)return e.jsx("span",{className:"text-slate-300",children:"â"});const l=n>=70?"#059669":n>=50?"#0284c7":n>=35?"#d97706":"#dc2626";return e.jsxs("span",{className:"inline-flex items-baseline gap-1.5 tabular-nums",children:[t.market_rank!=null&&e.jsxs("span",{className:"text-xs text-slate-400",children:["#",t.market_rank]}),e.jsx("span",{className:"font-semibold",style:{color:l},children:Math.round(n)})]})}},{key:"provider_name",label:"Facility",on:!0,fixed:!0,render:t=>e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"font-medium text-slate-800",children:t.provider_name}),e.jsx("p",{className:"text-xs text-slate-400",children:t.ccn})]})},{key:"citytown",label:"City",on:!0,render:t=>t.citytown},{key:"distance_miles",label:"Miles",on:!0,render:t=>t.distance_miles?.toFixed(1)},{key:"overall_rating",label:"Overall",on:!0,render:t=>e.jsx(ke,{rating:t.overall_rating})},{key:"health_inspection_rating",label:"Health",on:!0,render:t=>e.jsx(ke,{rating:t.health_inspection_rating})},{key:"staffing_rating",label:"Staffing",on:!0,render:t=>e.jsx(ke,{rating:t.staffing_rating})},{key:"qm_rating",label:"Quality",on:!1,render:t=>e.jsx(ke,{rating:t.qm_rating})},{key:"number_of_certified_beds",label:"Beds",on:!0},{key:"average_number_of_residents_per_day",label:"ADC",on:!0},{key:"occupancy_pct",label:"Occ %",on:!0,render:t=>t.occupancy_pct!=null?`${t.occupancy_pct.toFixed(1)}%`:"â"},{key:"total_nurse_hprd",label:"Nurse HPRD",on:!1,render:t=>t.total_nurse_hprd!=null?t.total_nurse_hprd.toFixed(2):"â"},{key:"rn_hprd",label:"RN HPRD",on:!1,render:t=>t.rn_hprd!=null?t.rn_hprd.toFixed(2):"â"},{key:"nursing_turnover",label:"Turnover %",on:!1,render:t=>t.nursing_turnover!=null?`${t.nursing_turnover.toFixed(1)}%`:"â"},{key:"case_mix_index",label:"Case Mix",on:!1,render:t=>t.case_mix_index!=null?t.case_mix_index.toFixed(3):"â"},{key:"chain_name",label:"Chain",on:!1,render:t=>e.jsx("span",{className:"text-xs max-w-[120px] truncate block",title:t.chain_name,children:t.chain_name??"â"})},{key:"ownership_type",label:"Ownership",on:!0,render:t=>e.jsx("span",{className:"text-xs",children:t.ownership_type??"â"})}],Re=[{key:"provider_name",label:"Agency",on:!0,fixed:!0,render:t=>e.jsxs(e.Fragment,{children:[t.cr_fy_year?e.jsx("a",{href:`/home-health-cost-reports?ccn=${t.ccn}`,target:"_blank",rel:"noopener noreferrer",className:"font-medium text-sky-700 hover:underline",title:"Open the home health cost report (new tab)",children:t.provider_name}):e.jsx("p",{className:"font-medium text-slate-800",children:t.provider_name}),e.jsx("p",{className:"text-xs text-slate-400",children:t.ccn})]})},{key:"citytown",label:"City",on:!0,render:t=>t.citytown},{key:"ownership",label:"Ownership",on:!0,render:t=>e.jsx("span",{className:"text-xs",children:t.ownership})},{key:"quality_star_rating",label:"Rating",on:!0,render:t=>/^[0-9]/.test(t.quality_star_rating||"")?e.jsxs("span",{className:"text-amber-500 font-medium whitespace-nowrap",children:[t.quality_star_rating,"â
"]}):e.jsx("span",{className:"text-xs text-slate-400",children:"Not rated"})},{key:"medicare_spending",label:"Spend/ep vs natl",on:!0,render:t=>t.medicare_spending!=null?e.jsxs("span",{className:"tabular-nums",title:"Medicare spend per episode of care vs national average (1.00)",children:[t.medicare_spending.toFixed(2),"Ã"]}):"â"},{key:"medicare_episode_count",label:"Episodes",on:!0,render:t=>t.medicare_episode_count!=null?t.medicare_episode_count.toLocaleString():"â"},{key:"certification_date",label:"Certified",on:!0,render:t=>e.jsx("span",{className:"whitespace-nowrap",children:t.certification_date||"â"})},{key:"distance_miles",label:"Distance",on:!0,render:t=>t.distance_miles!=null?`${t.distance_miles} mi`:"â"},{key:"timely_care_pct",label:"Timely care",on:!1,render:t=>t.timely_care_pct!=null?`${t.timely_care_pct.toFixed(1)}%`:"â"},{key:"services",label:"Services",on:!1,render:t=>{const n=[t.offers_nursing==="Yes"?"Nursing":null,t.offers_pt==="Yes"?"PT":null,t.offers_ot==="Yes"?"OT":null,t.offers_speech==="Yes"?"Speech":null,t.offers_social==="Yes"?"MSW":null,t.offers_aide==="Yes"?"Aide":null].filter(
5Boolean).join(" · ");return e.jsx("span",{className:"text-xs",children:n||"â"})}},{key:"dtc_perf",label:"Discharge to community",on:!1,render:t=>e.jsx("span",{className:"text-xs",children:t.dtc_perf||"â"})},{key:"ppr_perf",label:"Readmission",on:!1,render:t=>e.jsx("span",{className:"text-xs",children:t.ppr_perf||"â"})},{key:"pph_perf",label:"Hospitalization",on:!1,render:t=>e.jsx("span",{className:"text-xs",children:t.pph_perf||"â"})},{key:"county",label:"County",on:!1,render:t=>t.county||"â"},{key:"telephone_number",label:"Phone",on:!1,render:t=>e.jsx("span",{className:"whitespace-nowrap",children:t.telephone_number||"â"})},{key:"cr_net_patient_revenue",label:"Net revenue",on:!1,render:t=>t.cr_net_patient_revenue!=null?e.jsx("span",{className:"tabular-nums whitespace-nowrap",children:t.cr_net_patient_revenue>=1e6?`$${Math.round(t.cr_net_patient_revenue/1e6).toLocaleString()}M`:`$${Math.round(t.cr_net_patient_revenue/1e3).toLocaleString()}k`}):"â"},{key:"cr_total_margin_pct",label:"Total margin",on:!1,render:t=>t.cr_total_margin_pct!=null?e.jsxs("span",{className:"tabular-nums",style:{color:t.cr_total_margin_pct<0?"#dc2626":"#059669"},children:[t.cr_total_margin_pct.toFixed(1),"%"]}):"â"},{key:"cr_cost_per_visit",label:"Cost/visit",on:!1,render:t=>t.cr_cost_per_visit!=null?e.jsxs("span",{className:"tabular-nums",children:["$",Math.round(t.cr_cost_per_visit).toLocaleString()]}):"â"},{key:"cr_total_visits",label:"Annual visits",on:!1,render:t=>t.cr_total_visits!=null?e.jsx("span",{className:"tabular-nums",children:t.cr_total_visits.toLocaleString()}):"â"},{key:"cr_unduplicated_census",label:"Patients",on:!1,render:t=>t.cr_unduplicated_census!=null?e.jsx("span",{className:"tabular-nums",children:t.cr_unduplicated_census.toLocaleString()}):"â"}],mt=[{code:"AL",name:"Alabama",bbox:[30.18,-88.47,35.01,-84.89]},{code:"AK",name:"Alaska",bbox:[54.7,-179.15,71.39,-130]},{code:"AZ",name:"Arizona",bbox:[31.33,-114.82,37,-109.05]},{code:"AR",name:"Arkansas",bbox:[33,-94.62,36.5,-89.64]},{code:"CA",name:"California",bbox:[32.53,-124.42,42.01,-114.13]},{code:"CO",name:"Colorado",bbox:[36.99,-109.06,41,-102.05]},{code:"CT",name:"Connecticut",bbox:[40.95,-73.73,42.05,-71.79]},{code:"DE",name:"Delaware",bbox:[38.45,-75.79,39.84,-75.05]},{code:"DC",name:"District of Columbia",bbox:[38.79,-77.12,38.99,-76.91]},{code:"FL",name:"Florida",bbox:[24.52,-87.63,31,-80.03]},{code:"GA",name:"Georgia",bbox:[30.36,-85.61,35,-80.84]},{code:"HI",name:"Hawaii",bbox:[18.91,-160.24,22.24,-154.81]},{code:"ID",name:"Idaho",bbox:[42,-117.24,49,-111.05]},{code:"IL",name:"Illinois",bbox:[36.97,-91.51,42.51,-87.02]},{code:"IN",name:"Indiana",bbox:[37.77,-88.1,41.76,-84.79]},{code:"IA",name:"Iowa",bbox:[40.38,-96.64,43.5,-90.14]},{code:"KS",name:"Kansas",bbox:[37,-102.05,40,-94.59]},{code:"KY",name:"Kentucky",bbox:[36.5,-89.57,39.15,-81.96]},{code:"LA",name:"Louisiana",bbox:[28.93,-94.04,33.02,-88.82]},{code:"ME",name:"Maine",bbox:[43.06,-71.08,47.46,-66.95]},{code:"MD",name:"Maryland",bbox:[37.91,-79.48,39.72,-75.04]},{code:"MA",name:"Massachusetts",bbox:[41.24,-73.51,42.89,-69.93]},{code:"MI",name:"Michigan",bbox:[41.7,-90.42,48.31,-82.41]},{code:"MN",name:"Minnesota",bbox:[43.5,-97.24,49.38,-89.49]},{code:"MS",name:"Mississippi",bbox:[30.17,-91.66,34.99,-88.1]},{code:"MO",name:"Missouri",bbox:[35.99,-95.77,40.61,-89.1]},{code:"MT",name:"Montana",bbox:[44.36,-116.05,49,-104.04]},{code:"NE",name:"Nebraska",bbox:[39.99,-104.05,43,-95.31]},{code:"NV",name:"Nevada",bbox:[35,-120.01,42,-114.04]},{code:"NH",name:"New Hampshire",bbox:[42.7,-72.56,45.31,-70.61]},{code:"NJ",name:"New Jersey",bbox:[38.93,-75.56,41.36,-73.89]},{code:"NM",name:"New Mexico",bbox:[31.33,-109.05,37,-103]},{code:"NY",name:"New York",bbox:[40.5,-79.76,45.02,-71.86]},{code:"NC",name:"North Carolina",bbox:[33.84,-84.32,36.59,-75.46]},{code:"ND",name:"North Dakota",bbox:[45.94,-104.05,49,-96.55]},{code:"OH",name:"Ohio",bbox:[38.4,-84.82,41.98,-80.52]},{code:"OK",name:"Oklahoma",bbox:[33.62,-103,37,-94.43]},{code:"OR",name:"Oregon",bbox:[41.99,-124.55,46.29,-116.46]},{code:"PA",name:"Pennsylvania",bbox:[39.72,-80.52,42.27,-74.69]},{code:"PR",name:"Puerto Rico",bbox:[17.88,-67.95,18.52,-65.22]},{code:"RI",name:"Rhode Island",bbox:[41.15,-71.86,42.02,-71.12]},{code:"SC",name:"South Carolina",bbox:[32.03,-83.35,35.22,-78.54]},{code:"SD",name:"South Dakota",bbox:[42.48,-104.06,45.94,-96.44]},{code:"TN",name:"Tennessee",bbox:[34.98,-90.31,36.68,-81.65]},{code:"TX",name:"Texas",bbox:[25.84,-106.65,36.5,-93.51]}
5,{code:"UT",name:"Utah",bbox:[37,-114.05,42,-109.04]},{code:"VT",name:"Vermont",bbox:[42.73,-73.44,45.02,-71.46]},{code:"VA",name:"Virginia",bbox:[36.54,-83.68,39.47,-75.24]},{code:"WA",name:"Washington",bbox:[45.54,-124.85,49,-116.92]},{code:"WV",name:"West Virginia",bbox:[37.2,-82.65,40.64,-77.72]},{code:"WI",name:"Wisconsin",bbox:[42.49,-92.89,47.08,-86.81]},{code:"WY",name:"Wyoming",bbox:[40.99,-111.06,45.01,-104.05]}];function bn(t,n){switch(t){case"min_overall_rating":return`Overall ⥠${n}â
`;case"max_overall_rating":return`Overall ⤠${n}â
`;case"min_health_rating":return`Health ⥠${n}â
`;case"max_health_rating":return`Health ⤠${n}â
`;case"min_staffing_rating":return`Staffing ⥠${n}â
`;case"max_staffing_rating":return`Staffing ⤠${n}â
`;case"min_qm_rating":return`QM ⥠${n}â
`;case"max_qm_rating":return`QM ⤠${n}â
`;case"min_longstay_qm_rating":return`LS QM ⥠${n}â
`;case"max_longstay_qm_rating":return`LS QM ⤠${n}â
`;case"min_shortstay_qm_rating":return`SS QM ⥠${n}â
`;case"max_shortstay_qm_rating":return`SS QM ⤠${n}â
`;case"min_chain_avg_rating":return`Chain avg ⥠${n}â
`;case"max_chain_avg_rating":return`Chain avg ⤠${n}â
`;case"sff_status":return"Special Focus";case"abuse_icon":return"Abuse icon";case"min_beds":return`Beds ⥠${n}`;case"max_beds":return`Beds ⤠${n}`;case"min_adc":return`ADC ⥠${n}`;case"max_adc":return`ADC ⤠${n}`;case"min_occupancy_pct":return`Occ ⥠${n}%`;case"max_occupancy_pct":return`Occ ⤠${n}%`;case"min_rn_turnover_pct":return`RN turn ⥠${n}%`;case"max_rn_turnover_pct":return`RN turn ⤠${n}%`;case"min_total_turnover_pct":return`Total turn ⥠${n}%`;case"max_total_turnover_pct":return`Total turn ⤠${n}%`;case"min_admin_turnover":return`Admins left ⥠${n}`;case"max_admin_turnover":return`Admins left ⤠${n}`;case"min_total_hprd":return`Total HPRD ⥠${n}`;case"max_total_hprd":return`Total HPRD ⤠${n}`;case"min_rn_hprd":return`RN HPRD ⥠${n}`;case"max_rn_hprd":return`RN HPRD ⤠${n}`;case"min_lpn_hprd":return`LPN HPRD ⥠${n}`;case"max_lpn_hprd":return`LPN HPRD ⤠${n}`;case"min_cna_hprd":return`CNA HPRD ⥠${n}`;case"max_cna_hprd":return`CNA HPRD ⤠${n}`;case"min_weekend_rn_hprd":return`Weekend RN HPRD ⥠${n}`;case"max_weekend_rn_hprd":return`Weekend RN HPRD ⤠${n}`;case"hospital_based":return"Hospital-based";case"ccrc":return"CCRC";case"government_owned":return"Government-owned";case"nonprofit":return"Non-profit";case"forprofit":return"For-profit";case"has_council":return"Has council";case"recent_ownership_change":return"Sold in last 12mo";case"in_chain":return n?"In a chain":"Independent";case"states":return`States: ${Array.isArray(n)?n.join(","):n}`;case"city_contains":return`City: ${n}`;case"zip_starts":return`ZIP: ${n}â¦`;case"chain_contains":return`Chain: ${n}`;default:return`${t}=${n}`}}function fn(t){const[n,l]=d.useState([]),[i,o]=d.useState(!1),m=d.useRef(null);return d.useEffect(()=>{if(!t||t.length<2){l([]);return}return clearTimeout(m.current),m.current=setTimeout(async()=>{o(!0);try{const j=await Wt({q:t,page_size:15});l(j.results||[])}catch{l([])}o(!1)},250),()=>clearTimeout(m.current)},[t]),{results:n,loading:i}}function Ln(){const t=Dt(),[n]=Pt(),[l,i]=d.useState("city"),[o,m]=d.useState(""),[j,N]=d.useState(""),[P,f]=d.useState(""),[A,$]=d.useState(""),[a,M]=d.useState(15),[p,L]=d.useState(null),[Y,b]=d.useState(!1),E=d.useRef(null),[k,S]=d.useState(""),[V,Q]=d.useState([]),[U,te]=d.useState(!1),[G,_]=d.useState(null),[y,x]=d.useState(!1),z=d.useRef(null),R=d.useRef(null),{results:h,loading:q}=fn(j);d.useEffect(()=>{const s=n.get("ccn");s&&!p&&(f(s),$(s),L({ccn:s,radius:a}))},[]),d.useEffect(()=>{const s=g=>{E.current&&!E.current.contains(g.target)&&b(!1),z.current&&!z.current.contains(g.target)&&x(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[]),d.useEffect(()=>{if(l!=="city"||!k||k.length<3){Q([]);return}return clearTimeout(R.current),R.current=setTimeout(async()=>{te(!0);try{const s=`https://nominatim.openstreetmap.org/search?format=json&countrycodes=us&limit=8&q=${encodeURIComponent(k)}`,u=await(await fetch(s,{headers:{Accept:"application/json"}})).json();Q(u.map(w=>({lat:parseFloat(w.lat),lon:parseFloat(w.lon),label:w.display_name})))}catch{Q([])}te(!1)},350),()=>clearTimeout(R.current)},[k,l]);const[X,I]=d.useState(!0),[K,je]=d.useState(!1),[Ne,de]=d.useState(!1),[Ze,_e]=d.useState(!0),[De,r]=d.useState(!0),{sortCol:c,sortDir:C,toggleSort:T}=Tt("insight_score","desc"),[v,O]=d.useState("snf"),[H,W]=d.useState(()=>ze.filter(s=>s.on).map(s=>s.key)),[D,J]=d.useState(()=>Re.filter(s=>s.on).map(s=>s.key)),[be,pe]=d.useState(!1),[ne,ie]=d.useState(!1),[xe,se]=d.useState(!1),[we,Pe]=d.useState(null),[Te,Se]=d.useState("insight"),[re,ue]=d.useState("uniform"),[Qe,Oe]=d.useState(!1),[Ue,Ie]=d.useState({}),[Je,He]=d.useState(!1),[yt,Xe]=d.useState(!1),[fe,et]=d.useState({}),[le,qe]=d.useState({}),[vt,kt]=d.useState(!1),[tt,jt]=d.useState(!1),Be=d.useMemo(()=>p?p.bbox?{north:p.north,south:p.south,east:p.east,west:p.west}:p.ccn?{ccn:p.ccn,radius_miles:p.radius}:{lat:p.lat,lon:p.lon,radius_miles:p.radius}:null,[p]),{data:B,isLoading:nt,isError:Nt,error:wt}=Ye({queryKey:["market",p,le],queryFn:()=>Yt({...Be,...le}),enabled:!!p,retry:(s,g)=>!g?.upgrade&&s<2,placeholderData:it}),{data:$e}=Ye({queryKey:["market-markers",p,le],queryFn:()=>Gt({...Be,...le,limit:15e3}),enabled:!!p,staleTime:6e4,placeholderData:it});function st(s,g){et(u=>{const w={...u};return g==null||g===""||g===!1?delete w[s]:w[s]=g,w})}function St(){qe(fe)}function rt(){et({}),qe({})}const $t=d.useMemo(()=>{const s=Object.keys(fe),g=Object.keys(le);if(s.length!==g.length)return!0;for(const u of s)if(fe[u]!==le[u])return!0;return!1},[fe,le]);function Ct(s){f(s.ccn),$(`${s.provider_name} â ${s.citytown}, ${s.state} (${s.ccn})`),N(""),b(!1),L({ccn:s.ccn,radius:a})}function Mt(s){_(s),S(""),x(!1),L({lat:s.lat,lon:s.lon,radius:a,label:s.label})}function Lt(s){if(s.preventDefault(),l==="city"){if(!G)return;L({lat:G.lat,lon:G.lon,radius:a,label:G.label})}else if(l==="state"){const g=mt.find(Ft=>Ft.code===o);if(!g)return;const[u,w,ae,Ce]=g.bbox;L({bbox:!0,south:u,west:w,north:ae,east:Ce,label:g.name,stateCode:g.code})}else{if(!P)return;L({ccn:P,radius:a})}}const at=d.useCallback(s=>{L({bbox:!0,...s}),Oe(!1),He(!1),Ie({})},[]);d.useEffect(()=>{He(!1),Ie({})},[p]);const ce=d.useMemo(()=>
5{if(!B?.results)return[];const s=B.results.map(u=>({...u})),g=s.filter(u=>u.market_rank!=null).length;return s.forEach(u=>{u._totalRanked=g}),s},[B?.results]);d.useEffect(()=>{if(Je||!ce.length)return;He(!0);const s=ce.map(g=>g.ccn).join(",");Ot({ccns:s}).then(g=>{if(!g?.facilities)return;const u={};g.facilities.forEach(w=>{u[w.ccn]={nursing_agency_pct:w.nursing_agency_pct,admin_tenure_days:w.admin_tenure_days,don_tenure_days:w.don_tenure_days,operating_margin_pct:w.operating_margin_pct,net_revenue_ppd:w.net_revenue_ppd,cost_per_day:w.cost_per_day,dso_days:w.dso_days}}),Ie(u)}).catch(()=>{})},[Je,ce]);const ge=d.useMemo(()=>{if(!ce.length)return[];const s=[...ce];return s.sort((g,u)=>{let w=g[c],ae=u[c];if(["insight_score","market_score","market_rank","distance_miles","number_of_certified_beds","average_number_of_residents_per_day","occupancy_pct","overall_rating","health_inspection_rating","staffing_rating","qm_rating","total_nurse_hprd","rn_hprd","nursing_turnover","case_mix_index"].includes(c)){const Ce=C==="asc"?1/0:-1/0;return w=w!=null?Number(w):Ce,ae=ae!=null?Number(ae):Ce,C==="asc"?w-ae:ae-w}return C==="asc"?String(w??"").localeCompare(String(ae??"")):String(ae??"").localeCompare(String(w??""))}),s},[ce,c,C]),zt=({col:s})=>c!==s?null:C==="asc"?e.jsx(Bt,{size:12}):e.jsx(Ge,{size:12}),Rt=()=>{if(!ge.length)return;const s=["CCN","Facility","City","State","Miles","Score","Overall","Health","Staffing","Beds","Chain","Ownership"],g=ge.map(u=>[u.ccn,`"${(u.provider_name||"").replace(/"/g,'""')}"`,u.citytown,u.state,u.distance_miles?.toFixed(1),u.market_score??"",u.overall_rating,u.health_inspection_rating,u.staffing_rating,u.number_of_certified_beds,`"${(u.chain_name||"").replace(/"/g,'""')}"`,`"${(u.ownership_type||"").replace(/"/g,'""')}"`].join(","));Vt(`market_${p?.ccn||p?.label?.split(",")[0]?.replace(/\s+/g,"_")||"analysis"}_${a}mi.csv`,s.join(",")+` 6`+g.join(` 7`))};return e.jsx("div",{className:"min-h-screen bg-slate-50",children:e.jsxs("div",{className:"px-4 md:px-6 py-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-xl font-bold text-slate-800 flex items-center gap-2",children:["Market Analysis ",e.jsx(Ke,{text:"Explore the competitive landscape around any SNF or geographic area. View all facilities within a configurable radius, color-coded by star rating, staffing, quality, or other metrics. Compare occupancy, rates, and outcomes to identify market positioning opportunities and competitive threats.",size:13,position:"below"})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-0.5",children:[e.jsx("p",{className:"text-slate-500 text-xs",children:"View all facilities within a radius of any SNF or location"}),B?.cms_snapshot_date&&e.jsx(It,{label:"CMS data as of",date:B.cms_snapshot_date})]})]}),B&&p&&e.jsxs("button",{onClick:()=>{const s=new URLSearchParams;p?.ccn&&s.set("ccn",p.ccn),p?.lat&&s.set("lat",p.lat),p?.lon&&s.set("lon",p.lon),p?.radius&&s.set("radius",p.radius),p?.bbox&&(s.set("north",p.north),s.set("south",p.south),s.set("east",p.east),s.set("west",p.west)),(p?.label||A)&&s.set("label",p?.label||A),window.open(`/market/report?${s.toString()}`,"_blank")},className:"flex items-center gap-2 bg-slate-100 hover:bg-slate-200 text-slate-700 px-4 py-2 rounded-lg text-sm font-medium transition-colors",children:[e.jsx(Ht,{size:15})," Market Report"]})]}),e.jsxs("div",{className:"flex gap-3 mb-6 flex-wrap",children:[e.jsxs("div",{className:"flex rounded-lg border border-slate-300 overflow-hidden text-sm",children:[e.jsxs("button",{type:"button",onClick:()=>{i("facility"),_(null),S("")},className:`px-3 py-2 font-medium transition-colors ${l==="facility"?"bg-sky-600 text-white":"bg-white text-slate-600 hover:bg-slate-50"}`,children:[e.jsx(lt,{size:13,className:"inline -mt-0.5 mr-1"}),"Facility"]}),e.jsxs("button",{type:"button",onClick:()=>{i("city"),f(""),$(""),N(""),m("")},className:`px-3 py-2 font-medium transition-colors ${l==="city"?"bg-sky-600 text-white":"bg-white text-slate-600 hover:bg-slate-50"}`,children:[e.jsx(Ve,{size:13,className:"inline -mt-0.5 mr-1"}),"City / Area"]}),e.jsxs("button",{type:"button",onClick:()=>{i("state"),f(""),$(""),N(""),_(null),S("")},className:`px-3 py-2 font-medium transition-colors ${l==="state"?"bg-sky-600 text-white":"bg-white text-slate-600 hover:bg-slate-50"}`,children:[e.jsx(lt,{size:13,className:"inline -mt-0.5 mr-1"}),"State"]})]}),e.jsxs("form",{onSubmit:Lt,className:"flex flex-1 gap-3 flex-wrap min-w-0",children:[l==="facility"&&e.jsxs("div",{className:"relative flex-1 min-w-64",ref:E,children:[e.jsx(Ve,{size:15,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 pointer-events-none"}),P&&!Y?e.jsx("div",{onClick:()=>{b(!0),N("")},className:"w-full pl-9 pr-8 py-2 border border-slate-300 rounded-lg text-sm cursor-text bg-white truncate",title:A,children:A}):e.jsx("input",{value:j,onChange:s=>{N(s.target.value),b(!0)},onFocus:()=>b(!0),placeholder:"Search by facility name, city, county, or CCN...",className:"w-full pl-9 pr-3 py-2 border border-slate-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-sky-500",autoFocus:Y&&!P}),P&&!Y&&e.jsx("button",{type:"button",onClick:()=>{f(""),$(""),N(""),b(!0)},className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600",children:e.jsx(Fe,{size:14})}),Y&&j.length>=2&&e.jsx("div",{className:"absolute top-full left-0 right-0 mt-1 bg-white border border-slate-200 rounded-lg shadow-lg max-h-64 overflow-y-auto",style:{zIndex:1100},children:q?e.jsxs("div",{className:"px-4 py-3 text-sm text-slate-400 flex items-center gap-2",children:[e.jsx(We,{size:14,className:"animate-spin"})," Searching..."]}):h.length>0?h.map(s=>e.jsxs("button",{type:"button",onClick:()=>Ct(s),className:"w-full text-left px-4 py-2.5 hover:bg-sky-50 transition-colors border-b border-slate-50 last:border-0",children:[e.jsx("p",{className:"text-sm font-medium text-slate-800",children:s.provider_name}),e.jsxs("p",{className:"text-xs text-slate-500",children:[s.citytown,", ",s.state," ",s.zip_code,e.jsxs("span",{className:"ml-2 text-slate-400",children:["CCN: ",s.ccn]}),s.overall_rating&&e.jsxs("span",{className:"ml-2",children:[s.overall_rating," stars"]})]})]},s.ccn)):e.jsx("div",{className:"px-4 py-3 text-sm text-slate-400",children:"No facilities found"})})]}),l==="city"&&e.jsxs("div",{className:"relative flex-1 min-w-64",ref:z,children:[e.jsx(Ve,{size:15,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400 pointer-events-none"}),G&&!y?e.jsx("div",{onClick:()=>{x(!0),S("")},className:"w-full pl-9 pr-8 py-2 border border-slate-300 rounded-lg text-sm cursor-text bg-white truncate",title:G.label,children:G.label}):e.jsx("input",{value:k,onChange:s=>{S(s.target.value),x(!0)},onFocus:()=>x(!0),placeholder:"Search by city, zip code, or address (e.g., Lexington KY)...",className:"w-full pl-9 pr-3 py-2 border border-slate-300 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-sky-500",autoFocus:y&&!G}),G&&!y&&e.jsx("button",{type:"button",onClick:()=>{_(null),S(""),x(!0)},className:"absolute right-3 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600",children:e.jsx(Fe,{size:14})}),y&&k.length>=3&&e.jsx("div",{className:"absolute top-full left-0 right-0 mt-1 bg-white border border-slate-200 rounded-lg shadow-lg max-h-64 overflow-y-auto",style:{zIndex:1100},children:U?e.jsxs("div",{className:"px-4 py-3 text-sm text-slate-400 flex items-center gap-2",children:[e.jsx(We,{size:14,className:"animate-spin"})," Searching..."]}):V.length>0?V.map((s,g)=>e.jsx("button",{type:"button",onClick:()=>Mt(s),className:"w-full text-left px-4 py-2.5 hover:bg-sky-50 transition-colors border-b border-slate-50 last:border-0",children:e.jsx("p",{className:"text-sm font-medium text-slate-800",children:s.label})},g)):e.jsx("div",{className:"px-4 py-3 text-sm text-slate-400",children:"No locations foun
7d"})})]}),l==="state"&&e.jsxs("select",{value:o,onChange:s=>m(s.target.value),className:"flex-1 min-w-48 border border-slate-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-sky-500 bg-white",children:[e.jsx("option",{value:"",children:"Select a stateâ¦"}),mt.map(s=>e.jsxs("option",{value:s.code,children:[s.name," (",s.code,")"]},s.code))]}),l!=="state"&&e.jsx("select",{value:a,onChange:s=>M(Number(s.target.value)),className:"border border-slate-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-sky-500",children:[5,10,15,25,50].map(s=>e.jsxs("option",{value:s,children:[s," miles"]},s))}),e.jsx("button",{type:"submit",disabled:l==="facility"?!P:l==="city"?!G:!o,className:"bg-sky-600 hover:bg-sky-700 disabled:bg-slate-300 text-white px-5 py-2 rounded-lg text-sm font-medium transition-colors",children:"Analyze Market"})]})]}),nt&&e.jsxs("div",{className:"flex items-center gap-2 text-slate-400 py-12 justify-center",children:[e.jsx(We,{size:18,className:"animate-spin"})," Loading market data..."]}),Nt&&e.jsx(Kt,{error:wt}),!B&&!nt&&e.jsx(mn,{drawMode:Qe,setDrawMode:Oe,onBboxSelect:at}),B&&e.jsxs("div",{className:"space-y-4",children:[Object.keys(le).length>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"text-[11px] font-medium text-slate-500 mr-1",children:"Active:"}),Object.entries(le).map(([s,g])=>e.jsxs("button",{type:"button",onClick:()=>{st(s,null),qe(u=>{const w={...u};return delete w[s],w})},className:"inline-flex items-center gap-1 text-[11px] bg-sky-50 text-sky-700 border border-sky-200 px-2 py-0.5 rounded-full hover:bg-sky-100 transition-colors",title:"Remove filter",children:[bn(s,g),e.jsx(Fe,{size:11})]},s)),e.jsx("button",{type:"button",onClick:rt,className:"text-[11px] text-slate-500 hover:text-slate-700 ml-1",children:"Clear all"})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm",children:[e.jsxs("button",{type:"button",onClick:()=>jt(s=>!s),className:"w-full flex items-center justify-between px-4 py-2.5 hover:bg-slate-50 transition-colors",children:[e.jsxs("span",{className:"text-sm font-semibold text-slate-700",children:["Market Stats",e.jsxs("span",{className:"ml-2 text-xs font-normal text-slate-500",children:[B.total_facilities," facilities",$e?.markers?.length>B.total_facilities&&e.jsxs(e.Fragment,{children:[" · ",$e.markers.length.toLocaleString()," on map"]})]})]}),e.jsx(Ge,{size:16,className:`text-slate-400 transition-transform ${tt?"rotate-180":""}`})]}),tt&&e.jsx("div",{className:"border-t border-slate-100 p-4",children:e.jsx(_n,{data:B,staffingMap:Ue,rankedResults:ce})})]}),e.jsxs("div",{className:"flex gap-4 items-start",children:[e.jsx(nn,{open:vt,onToggle:()=>kt(s=>!s),pending:fe,active:le,onChange:st,onApply:St,onClear:rt,dirty:$t,geoParams:Be}),e.jsxs("div",{className:"flex-1 min-w-0 space-y-4",children:[$e?.limit_hit&&e.jsx("div",{className:"bg-amber-50 border border-amber-200 rounded-lg px-4 py-2.5 text-xs text-amber-700",children:"Showing the first 15,000 facilities. Apply more filters or narrow the geographic scope to see all matches."}),e.jsx(ln,{data:B,rankedResults:ce,liteMarkers:$e?.markers,submitted:p,selectedLabel:A||p?.label||"",showSNFs:X,setShowSNFs:I,showHospitals:K,setShowHospitals:je,showHomeHealth:Ne,setShowHomeHealth:de,showRadius:Ze,setShowRadius:_e,clusterMarkers:De,setClusterMarkers:r,mapFullscreen:xe,setMapFullscreen:se,highlightCcn:we,colorMode:Te,setColorMode:Se,sizeBy:re,setSizeBy:ue,staffingMap:Ue,drawMode:Qe,setDrawMode:Oe,onBboxSelect:at})]})]}),e.jsxs("div",{className:"bg-white rounded-xl border border-slate-200 shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-slate-200",children:[e.jsxs("div",{className:"flex gap-1",children:[e.jsxs("button",{onClick:()=>O("snf"),className:`px-4 py-1.5 text-sm font-medium rounded-lg transition-colors ${v==="snf"?"bg-sky-100 text-sky-700":"text-slate-500 hover:text-slate-700"}`,children:["SNFs (",B.total_facilities,")"]}),e.jsxs("button",{onClick:()=>O("hospitals"),className:`px-4 py-1.5 text-sm font-medium rounded-lg transition-colors ${v==="hospitals"?"bg-sky-100 text-sky-700":"text-slate-500 hover:text-slate-700"}`,children:["Hospitals (",B.hospitals?.length||0,")"]}),e.jsxs("button",{onClick:()=>O("home_health"),className:`px-4 py-1.5 text-sm font-medium rounded-lg transition-colors ${v==="home_health"?"bg-sky-100 text-sky-700":"text-slate-500 hover:text-slate-700"}`,children:["Home Health (",B.home_health?.length||0,")"]}),B.ma_top_plans?.length>0&&e.jsxs("button",{onClick:()=>O("plans"),className:`px-4 py-1.5 text-sm font-medium rounded-lg transition-colors ${v==="plans"?"bg-sky-100 text-sky-700":"text-slate-500 hover:text-slate-700"}`,children:["MA Plans (",B.ma_top_plans.length,")"]})]}),v==="snf"&&e.jsxs("button",{onClick:Rt,className:"flex items-center gap-1 text-xs text-slate-500 hover:text-sky-600 transition-colors",children:[e.jsx(qt,{size:13})," CSV"]})]}),v==="snf"&&e.jsxs("div",{children:[e.jsx("div",{className:"px-4 py-2 border-b border-slate-100 flex items-center justify-end",children:e.jsxs("div",{className:"relative",children:[e.jsxs("button",{onClick:()=>ie(s=>!s),className:"flex items-center gap-1 text-xs text-slate-500 hover:text-slate-700 border border-slate-200 rounded-lg px-2 py-1",children:[e.jsx(ct,{size:12})," Columns"]}),ne&&e.jsx("div",{className:"absolute right-0 top-full mt-1 bg-white border border-slate-200 rounded-lg shadow-lg z-30 p-2 w-48 max-h-64 overflow-y-auto",children:ze.filter(s=>!s.fixed).map(s=>e.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 text-xs text-slate-600 hover:bg-slate-50 rounded cursor-pointer",children:[e.jsx("input",{type:"checkbox",className:"accent-sky-500",checked:H.includes(s.key),onChange:g=>W(u=>g.target.checked?[...u,s.key]:u.filter(w=>w!==s.key))}),s.label]},s.key))})]})}),e.jsx("div",{className:"overflow-x-auto max-h-[500px] overflow-y-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 border-b border-slate-200 sticky top-0",children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",className:"px-2 py-2 w-8"}),ze.filter(s=>H.includes(s.key)).map(s=>e.jsx("th",{scope:"col",onClick:()=>T(s.key),className:"text-left px-3 py-2 text-xs font-semibold text-slate-500 uppercase tracking-wide cursor-pointer hover:text-sky-600 select-none whitespace-nowrap",children:e.jsxs("span",{className:"flex items-center gap-1",children:[s.label," ",e.jsx(zt,{col:s.key})]})},s.key))]})}),e.jsx("tbody",{className:"divide-y divide-slate-100",children:ge.map(s=>{const g=s.ccn===(we||B.center_ccn);return e.jsxs("tr",{onClick:u=>{ot(ge.map(ae=>ae.ccn));const w=`/facility/${s.ccn}?from=market${p.ccn?`&market_ccn=${p.ccn}`:""}&radius=${p.radius}`;u.ctrlKey||u.metaKey||u.shiftKey?window.open(w,"_blank"):t(w)},onAuxClick:u=>{u.button===1&&(ot(ge.map(w=>w.ccn)),window.open(`/facility/${s.ccn}?from=market${p.ccn?`&market_ccn=${p.ccn}`:""}&radius=${p.radius}`,"_blank"))}
7,className:`cursor-pointer transition-colors ${g?"bg-red-50/60 border-l-4 border-l-red-400":"hover:bg-sky-50"}`,children:[e.jsx("td",{className:"px-2 py-2",children:e.jsx("button",{title:"Highlight on map",onClick:u=>{u.stopPropagation(),Pe(s.ccn)},className:`p-0.5 rounded transition-colors ${g?"text-red-500":"text-slate-300 hover:text-slate-600"}`,children:e.jsx(en,{size:14})})}),ze.filter(u=>H.includes(u.key)).map(u=>e.jsx("td",{className:"px-3 py-2 text-slate-600",children:u.render?u.render(s):s[u.key]??"â"},u.key))]},s.ccn)})})]})})]}),v==="hospitals"&&e.jsx("div",{className:"overflow-x-auto max-h-[500px] overflow-y-auto",children:B.hospitals?.length>0?e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 border-b border-slate-200 sticky top-0",children:e.jsx("tr",{children:["Hospital","City","Type","Ownership","Emergency","Rating","Beds","Occupancy","Distance"].map(s=>e.jsx("th",{scope:"col",className:"text-left px-3 py-2 text-xs font-semibold text-slate-500 uppercase tracking-wide",children:s},s))})}),e.jsx("tbody",{className:"divide-y divide-slate-100",children:B.hospitals.map((s,g)=>e.jsxs("tr",{className:"hover:bg-sky-50 transition-colors",children:[e.jsxs("td",{className:"px-3 py-2",children:[s.cr_fy_year?e.jsx("a",{href:`/hospital-cost-reports?ccn=${s.facility_id}`,target:"_blank",rel:"noopener noreferrer",className:"font-medium text-sky-700 hover:underline",title:"Open the hospital cost report (new tab)",children:s.facility_name}):e.jsx("p",{className:"font-medium text-slate-800",children:s.facility_name}),e.jsx("p",{className:"text-xs text-slate-400",children:s.facility_id})]}),e.jsx("td",{className:"px-3 py-2 text-slate-600",children:s.citytown}),e.jsx("td",{className:"px-3 py-2 text-xs text-slate-600",children:s.hospital_type}),e.jsx("td",{className:"px-3 py-2 text-xs text-slate-500",children:s.hospital_ownership}),e.jsx("td",{className:"px-3 py-2",children:s.emergency_services==="Yes"?e.jsx("span",{className:"text-xs bg-green-100 text-green-700 px-2 py-0.5 rounded-full",children:"Yes"}):e.jsx("span",{className:"text-xs text-slate-400",children:"No"})}),e.jsx("td",{className:"px-3 py-2",children:e.jsx(ke,{rating:s.hospital_overall_rating})}),e.jsx("td",{className:"px-3 py-2 text-slate-600 whitespace-nowrap",children:s.cr_staffed_beds!=null?s.cr_staffed_beds.toLocaleString():"â"}),e.jsx("td",{className:"px-3 py-2 text-slate-600 whitespace-nowrap",children:s.cr_occupancy_pct!=null?e.jsxs("span",{children:[s.cr_occupancy_pct.toFixed(1),"%",s.cr_fy_year?e.jsxs("span",{className:"text-xs text-slate-400",children:[" FY",s.cr_fy_year]}):null]}):"â"}),e.jsx("td",{className:"px-3 py-2 text-slate-600",children:s.distance_miles!=null?s.distance_miles+" mi":"â"})]},g))})]}):e.jsx("p",{className:"text-center text-slate-400 py-8 text-sm",children:"No hospitals found in this area"})}),v==="home_health"&&e.jsxs("div",{children:[e.jsx("div",{className:"px-4 py-2 border-b border-slate-100 flex items-center justify-end",children:e.jsxs("div",{className:"relative",children:[e.jsxs("button",{onClick:()=>pe(s=>!s),className:"flex items-center gap-1 text-xs text-slate-500 hover:text-slate-700 border border-slate-200 rounded-lg px-2 py-1",children:[e.jsx(ct,{size:12})," Columns"]}),be&&e.jsx("div",{className:"absolute right-0 top-full mt-1 bg-white border border-slate-200 rounded-lg shadow-lg z-30 p-2 w-56 max-h-64 overflow-y-auto",children:Re.filter(s=>!s.fixed).map(s=>e.jsxs("label",{className:"flex items-center gap-2 px-2 py-1 text-xs text-slate-600 hover:bg-slate-50 rounded cursor-pointer",children:[e.jsx("input",{type:"checkbox",className:"accent-sky-500",checked:D.includes(s.key),onChange:g=>J(u=>g.target.checked?[...u,s.key]:u.filter(w=>w!==s.key))}),s.label]},s.key))})]})}),e.jsx("div",{className:"overflow-x-auto max-h-[500px] overflow-y-auto",children:B.home_health?.length>0?e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 border-b border-slate-200 sticky top-0",children:e.jsx("tr",{children:Re.filter(s=>D.includes(s.key)).map(s=>e.jsx("th",{scope:"col",className:"text-left px-3 py-2 text-xs font-semibold text-slate-500 uppercase tracking-wide whitespace-nowrap",children:s.label},s.key))})}),e.jsx("tbody",{className:"divide-y divide-slate-100",children:B.home_health.map((s,g)=>e.jsx("tr",{className:"hover:bg-sky-50 transition-colors",children:Re.filter(u=>
7D.includes(u.key)).map(u=>e.jsx("td",{className:"px-3 py-2 text-slate-600",children:u.render?u.render(s):s[u.key]??"â"},u.key))},g))})]}):e.jsx("p",{className:"text-center text-slate-400 py-8 text-sm",children:"No home health agencies found in this area"})})]}),v==="plans"&&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",children:e.jsx("tr",{children:["Plan","Parent Org","Contract","Type","Enrolled"].map(s=>e.jsx("th",{scope:"col",className:"text-left px-3 py-2 text-xs font-semibold text-slate-500 uppercase tracking-wide",children:s},s))})}),e.jsx("tbody",{className:"divide-y divide-slate-100",children:B.ma_top_plans.map((s,g)=>{const u=s.parent_organization;return e.jsxs("tr",{onClick:()=>u&&t(`/ma?org=${encodeURIComponent(u)}`),title:u?`Open ${u} in the Medicare Advantage Plan Explorer`:void 0,className:`transition-colors ${u?"hover:bg-sky-50 cursor-pointer":""}`,children:[e.jsx("td",{className:`px-3 py-2 font-medium ${u?"text-sky-700":"text-slate-800"}`,children:s.organization_marketing_name||s.organization_type||"â"}),e.jsx("td",{className:"px-3 py-2 text-slate-600 text-xs",children:s.parent_organization||"â"}),e.jsx("td",{className:"px-3 py-2 font-mono text-slate-500 text-xs",children:s.contract_id}),e.jsx("td",{className:"px-3 py-2 text-slate-500 text-xs",children:s.plan_type||s.organization_type||"â"}),e.jsx("td",{className:"px-3 py-2 font-semibold text-slate-700",children:s.enrolled?.toLocaleString()||"â"})]},g)})})]})})]})]}),e.jsx(Zt,{onRequestClick:()=>Xe(!0),context:"market_map"}),e.jsx(Qt,{isOpen:yt,onClose:()=>Xe(!1),pageContext:"market_map"})]})})}export{Ln 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.