1import{r as h,b as u,j as e,ae as w,F as k,L as f,dl as _,X as S,dm as L,dn as F,dp as M}from"./index-Df108JlE.js";import{u as A}from"./useModalA11y-B5_bs4oH.js";const O={home_office:"Home office",management:"Management",admin_support:"Admin support",real_estate:"Real estate",therapy:"Therapy",pharmacy:"Pharmacy",purchasing:"Purchasing",other:"Other"},j={home_office:"bg-indigo-50 text-indigo-700 border-indigo-200",management:"bg-sky-50 text-sky-700 border-sky-200",admin_support:"bg-cyan-50 text-cyan-700 border-cyan-200",real_estate:"bg-amber-50 text-amber-700 border-amber-200",therapy:"bg-slate-50 text-slate-600 border-slate-200",pharmacy:"bg-slate-50 text-slate-600 border-slate-200",purchasing:"bg-slate-50 text-slate-600 border-slate-200",other:"bg-slate-50 text-slate-500 border-slate-200"};function q({ccn:c,onClose:o}){const{data:l,isLoading:x}=u({queryKey:["lineage-facility",c],queryFn:()=>L(c),enabled:!!c}),i={};for(const t of l?.rows||[])(i[t.fy_year]??=[]).push(t);const d=Object.keys(i).map(Number).sort((t,a)=>t-a),r=A(o);return e.jsx("div",{className:"fixed inset-0 z-50 flex justify-end bg-slate-900/30",onClick:o,children:e.jsxs("div",{ref:r,role:"dialog","aria-modal":"true","aria-labelledby":"lineage-drawer-title",className:"w-full max-w-2xl h-full overflow-y-auto bg-white shadow-xl",onClick:t=>t.stopPropagation(),children:[e.jsxs("div",{className:"sticky top-0 flex items-start justify-between gap-3 border-b border-slate-200 bg-white px-5 py-4",children:[e.jsxs("div",{children:[e.jsx("div",{id:"lineage-drawer-title",className:"text-sm font-semibold text-slate-800",children:l?.name||c}),e.jsxs("div",{className:"text-xs text-slate-500",children:["CCN ",c,l?.city?` · ${l.city}`:"",l?.state?`, ${l.state}`:"",l?.cms_chain?e.jsxs(e.Fragment,{children:[" · CMS chain: ",e.jsx("span",{className:"font-medium text-slate-700",children:l.cms_chain})]}):""]})]}),e.jsx("button",{onClick:o,"aria-label":"Close",className:"text-slate-400 hover:text-slate-700",children:e.jsx(S,{size:18})})]}),e.jsx("div",{className:"p-5",children:x?e.jsx(f,{className:"animate-spin text-slate-400"}):d.length===0?e.jsx("p",{className:"text-sm text-slate-400",children:"No A-8-1 related-org records for this facility."}):e.jsx("div",{className:"space-y-3",children:d.map(t=>e.jsxs("div",{className:"rounded-lg border border-slate-200",children:[e.jsxs("div",{className:"border-b border-slate-100 bg-slate-50 px-3 py-1.5 text-xs font-semibold text-slate-600",children:["FY",t]}),e.jsx("div",{className:"divide-y divide-slate-50",children:i[t].sort((a,n)=>a.role_bucket.localeCompare(n.role_bucket)).map((a,n)=>e.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 text-xs",children:[e.jsx("span",{className:`inline-block rounded border px-1.5 py-0.5 text-[10px] font-medium ${j[a.role_bucket]||j.other}`,children:O[a.role_bucket]||a.role_bucket}),e.jsx("span",{className:"font-mono text-slate-800",children:a.org}),a.anchor&&e.jsx("span",{className:"ml-auto text-[10px] text-indigo-500",title:"Multi-facility chain entity",children:"chain anchor"})]},n))})]},t))})})]})})}function R({facilities:c,onPick:o}){if(!c.length)return null;const l=r=>{const t=new Map;for(const[a,n]of r)a&&(t.has(a)||t.set(a,new Set),t.get(a).add(n));return[...t.entries()].map(([a,n])=>[a,n.size]).sort((a,n)=>n[1]-a[1])},x=l(c.flatMap(r=>(r.entities||[]).map(t=>[t.org,r.ccn]))),i=l(c.map(r=>[r.cms_chain,r.ccn])),d=({label:r,items:t})=>e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"mr-1 w-28 flex-shrink-0 text-[10px] font-semibold uppercase tracking-wide text-slate-400",children:r}),t.slice(0,14).map(([a,n])=>e.jsxs("button",{onClick:()=>o(a),className:"rounded-md border border-slate-200 bg-white px-2 py-0.5 text-[11px] text-slate-700 hover:border-sky-300 hover:bg-sky-50",children:[a," ",e.jsx("span",{className:"text-slate-400",children:n})]},a)),t.length>14&&e.jsxs("span",{className:"text-[10px] text-slate-400",children:["+",t.length-14," more"]})]});return e.jsxs("div",{className:"mb-3 space-y-2 rounded-lg border border-slate-200 bg-slate-50/60 p-3",children:[e.jsx(d,{label:"Came from (A-8-1)",items:x}),e.jsx(d,{label:"Today (CMS chain)",items:i})]})}function P(){const[c,o]=h.useState(""),[l,x]=h.useState("chain"),[i,d]=h.useState(""),[r,t]=h.useState(null),{data:a}=u({queryKey:["lineage-anchors"],queryFn:F}),{data:n,isLoading:N}=u({queryKey:["lineage-search",i],queryFn:()=>M(i),enabled:i.length>=2}),v=()=>{const s=c.trim();s&&(l==="ccn"?t(s.toUpperCase()):d(s))},p=s=>{x("chain"),o(s),d(s.trim())};return e.jsxs("div",{className:"mx-auto max-w-6xl px-4 py-6",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-2",children:[e.jsx(w,{size:18,className:"text-slate-500"}),e.jsx("h1",{className:"text-lg font-semibold text-slate-800",children:"Chain & Operator Lineage"}),e.jsx("span",{className:"rounded bg-slate-100 px-1.5 py-0.5 text-[10px] font-medium text-slate-500",children:"internal · cost-report A-8-1"})]}),e.jsx("p",{className:"mb-4 text-xs text-slate-500",children:"Pre-CMS chain history reconstructed from cost-report related-org filings (2011â2024). Search a chain/management company; spans show the years the facility named that entity, and the CMS column shows today's owner â a divergence is usually an acquisition."}),e.jsxs("form",{onSubmit:s=>{s.preventDefault(),v()},className:"mb-4 flex gap-2",children:[e.jsx("div",{className:"flex rounded-lg border border-slate-300 p-0.5",children:[["chain","Chain"],["ccn","CCN"]].map(([s,b])=>e.jsx("button",{type:"button",onClick:()=>x(s),className:`rounded-md px-3 py-1 text-xs font-medium transition-colors ${l===s?"bg-slate-800 text-white":"text-slate-500 hover:text-slate-700"}`,children:b},s))}),e.jsxs("div",{className:"relative flex-1",children:[e.jsx(k,{size:15,className:"absolute left-3 top-1/2 -translate-y-1/2 text-slate-400"}),e.jsx("input",{value:c,onChange:s=>o(s.target.value),placeholder:l==="ccn"?"Enter a CCN, e.g. 105267":"Chain / management co â e.g. Gulf Coast, Signature, Ensignâ¦",className:"w-full rounded-lg border border-slate-300 py-2 pl-9 pr-3 text-sm focus:outline-none focus:ring-2 focus:ring-sky-500"})]}),e.jsx("button",{type:"submit",className:"rounded-lg bg-slate-800 px-4 text-sm font-medium text-white hover:bg-slate-700",children:l==="ccn"?"Open":"Search"})]}),!i&&a?.anchors&&e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-xs font-semibold uppercase tracking-wide text-slate-500",children:"Largest chain anchors â click to search"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:a.anchors.map(s=>e.jsxs("button",{onClick:()=>p(s.org),className:"rounded-md border border-slate-200 bg-white px-2.5 py-1.5 text-xs text-slate-700 hover:border-sky-300 hover:bg-sky-50",children:[s.org," ",e.jsxs("span",{className:"text-slate-400",children:["· ",s.facilities," · ",s.first_year,"â",s.last_year]})]},s.org))})]}),i&&(N?e.jsx(f,{className:"animate-spin text-slate-400"}):e.jsxs(e.Fragment,{children:[e.jsx(R,{facilities:n?.facilities||[],onPick:p}),e.jsxs("div",{className:"overflow-x-auto rounded-lg border border-slate-200",children:[e.jsxs("div",{className:"border-b border-slate-100 bg-slate-50 px-3 py-2 text-xs text-slate-600",children:[n?.count||0," facilities matching â",i,"â"]}
1),e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"bg-slate-50 text-left text-slate-500",children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",className:"px-3 py-2 font-semibold",children:"CCN"}),e.jsx("th",{scope:"col",className:"px-3 py-2 font-semibold",children:"Facility"}),e.jsx("th",{scope:"col",className:"px-3 py-2 font-semibold",children:"City"}),e.jsx("th",{scope:"col",className:"px-3 py-2 font-semibold",children:"St"}),e.jsx("th",{scope:"col",className:"px-3 py-2 font-semibold",children:"Operator lineage (A-8-1, by year)"}),e.jsx("th",{scope:"col",className:"px-3 py-2 font-semibold",children:"CMS chain today"})]})}),e.jsx("tbody",{className:"divide-y divide-slate-50",children:(n?.facilities||[]).map((s,b)=>{const g=s.cms_chain&&!s.cms_chain.toUpperCase().includes(i.toUpperCase().split(" ")[0]),C=s.entities||[];return e.jsxs("tr",{className:"align-top hover:bg-slate-50",children:[e.jsx("td",{className:"px-3 py-1.5",children:e.jsx("button",{onClick:()=>t(s.ccn),className:"font-mono text-sky-700 hover:underline",children:s.ccn})}),e.jsx("td",{className:"px-3 py-1.5 text-slate-700",children:s.name||"â"}),e.jsx("td",{className:"px-3 py-1.5 text-slate-500",children:s.city||"â"}),e.jsx("td",{className:"px-3 py-1.5 text-slate-500",children:s.state||""}),e.jsx("td",{className:"px-3 py-1.5",children:e.jsx("span",{className:"flex flex-wrap items-center gap-x-1 gap-y-0.5",children:C.map((m,y)=>e.jsxs("span",{className:"whitespace-nowrap",children:[y>0&&e.jsx("span",{className:"text-slate-300",children:"â "}),e.jsx("button",{onClick:()=>p(m.org),className:"font-medium text-slate-700 hover:text-sky-600",children:m.org}),e.jsxs("span",{className:"ml-0.5 text-slate-400",children:["â",String(m.lo).slice(2),m.hi!==m.lo?`ââ${String(m.hi).slice(2)}`:""]})]},y))})}),e.jsx("td",{className:"px-3 py-1.5",children:s.cms_chain?e.jsxs("span",{className:g?"inline-flex items-center gap-1 font-medium text-amber-700":"text-slate-600",children:[g&&e.jsx(_,{size:11}),s.cms_chain]}):e.jsx("span",{className:"text-slate-300",children:"â"})})]},b)})})]})]})]})),r&&e.jsx(q,{ccn:r,onClose:()=>t(null)})]})}export{P 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.