1import{r as l,b as d,j as e,aE as S,l as c,m as o,c as m,ap as v,$ as A,M as w,N as L,a5 as p,aV as C,L as T,B as $}from"./index-frHu0H6c.js";import{S as k}from"./seo-D93LAcXi.js";import{S as h,a as u,b as j,c as N,d as x}from"./select-DIShZ0zZ.js";import{F as K}from"./flask-conical-041k8_KZ.js";import"./chevron-up-Buc3iaCF.js";const M=["AL","AK","AZ","AR","CA","CO","CT","DE","FL","GA","HI","ID","IL","IN","IA","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH","NJ","NM","NY","NC","ND","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VT","VA","WA","WV","WI","WY","DC"],I=s=>(s||0)>=1e6?`$${(s/1e6).toFixed(1)}M`:(s||0)>=1e3?`$${(s/1e3).toFixed(0)}K`:`$${Math.round(s||0)}`;function B(){const[s,n]=l.useState([]),[a,y]=l.useState("__all__"),{data:i}=d({queryKey:["/api/user"]});l.useEffect(()=>{s.length===0&&Array.isArray(i?.territoryStates)&&i.territoryStates.length&&n(i.territoryStates.filter(t=>/^[A-Z]{2}$/.test(t)).slice(0,15))},[i]);const{data:f}=d({queryKey:[`/api/territory/specialties?state=${s[0]??""}`],enabled:s.length>0}),g=l.useMemo(()=>{const t=new URLSearchParams({states:s.join(",")});return a!=="__all__"&&t.set("specialty",a),t.toString()},[s,a]),{data:r,isLoading:b}=d({queryKey:[`/api/kol/leaderboard?${g}`],enabled:s.length>0});return e.jsxs("div",{className:"container mx-auto max-w-5xl px-4 py-8",children:[e.jsx(k,{title:"Top KOLs in Territory | Nopp",description:"The highest-scoring key opinion leaders in your territory â industry payments, clinical trials, NIH grants and publications, one composite score."}),e.jsxs("div",{className:"flex items-center gap-3 mb-1",children:[e.jsx(S,{className:"h-6 w-6 text-amber-400"}),e.jsx("h1",{className:"text-2xl font-bold","data-testid":"heading-kol-leaderboard",children:"Top KOLs in Territory"})]}),e.jsx("p",{className:"text-sm text-muted-foreground mb-6",children:"Composite KOL score blends industry payments, clinical-trial leadership, NIH grants and medical publications."}),e.jsx(c,{className:"mb-6",children:e.jsxs(o,{className:"pt-6 flex flex-wrap items-end gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"Add state"}),e.jsxs(h,{value:"",onValueChange:t=>{t&&!s.includes(t)&&n([...s,t])},children:[e.jsx(u,{className:"w-[130px]","data-testid":"select-add-state",children:e.jsx(j,{placeholder:"State"})}),e.jsx(N,{children:M.filter(t=>!s.includes(t)).map(t=>e.jsx(x,{value:t,children:t},t))})]})]}),e.jsx("div",{className:"flex flex-wrap gap-1",children:s.map(t=>e.jsxs(m,{variant:"secondary",className:"gap-1",children:[t,e.jsx("button",{onClick:()=>n(s.filter(_=>_!==t)),"data-testid":`remove-state-${t}`,children:e.jsx(v,{className:"h-3 w-3"})})]},t))}),e.jsxs("div",{className:"ml-auto",children:[e.jsx("label",{className:"text-xs text-muted-foreground",children:"Specialty"}),e.jsxs(h,{value:a,onValueChange:y,children:[e.jsx(u,{className:"w-[220px]","data-testid":"select-specialty",children:e.jsx(j,{})}),e.jsxs(N,{children:[e.jsx(x,{value:"__all__",children:"All specialties"}),(f?.specialties??[]).map(t=>e.jsx(x,{value:t,children:t},t))]})]})]})]})}),s.length===0&&e.jsx(c,{children:e.jsx(o,{className:"py-10 text-center text-muted-foreground",children:"Add at least one state (your saved territory pre-fills automatically)."})}),b&&e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground py-8 justify-center",children:[e.jsx(A,{className:"h-5 w-5 animate-spin"})," Ranking KOLsâ¦"]}),r&&e.jsxs(c,{children:[e.jsx(w,{className:"pb-2",children:e.jsxs(L,{className:"text-base",children:[r.total_in_territory.toLocaleString()," scored providers in ",s.join(", "),a!=="__all__"?` · ${a}`:""]})}),e.jsxs(o,{children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b text-muted-foreground",children:[e.jsx("th",{className:"text-left py-2 px-2 font-medium",children:"#"}),e.jsx("th",{className:"text-left py-2 px-2 font-medium",children:"Provider"}),e.jsx("th",{className:"text-left py-2 px-2 font-medium",children:"Specialty"}),e.jsx("th",{className:"text-left py-2 px-2 font-medium",children:"Location"}),e.jsx("th",{className:"text-right py-2 px-2 font-medium",children:"KOL score"}),e.jsx("th",{className:"text-right py-2 px-2 font-medium",children:"Industry $"}),e.jsx("th",{className:"text-right py-2 px-2 font-medium",children:"Trials"}),e.jsx("th",{className:"text-right py-2 px-2 font-medium",children:"Pubs"})]})}),e.jsxs("tbody",{children:[r.leaders.map(t=>e.jsxs("tr",{className:"border-b border-border/50 hover:bg-accent/30",children:[e.jsx("td",{className:"py-2 px-2 font-mono text-muted-foreground",children:t.rank}),e.jsx("td",{className:"py-2 px-2",children:e.jsxs(p,{href:`/provider/${t.npi}`,className:"text-cyan-400 hover:underline","data-testid":`link-kol-${t.npi}
1`,children:[[t.first_name,t.last_name].filter(Boolean).join(" ")||t.npi,t.credential?e.jsx("span",{className:"text-muted-foreground text-xs ml-1",children:t.credential}):null]})}),e.jsx("td",{className:"py-2 px-2 text-muted-foreground",children:t.specialty_name||"â"}),e.jsx("td",{className:"py-2 px-2 text-muted-foreground",children:[t.city,t.state].filter(Boolean).join(", ")}),e.jsx("td",{className:"py-2 px-2 text-right",children:e.jsx(m,{variant:"outline",className:"text-amber-400 border-amber-400/40 font-mono",children:Number(t.composite_score).toFixed(0)})}),e.jsx("td",{className:"py-2 px-2 text-right font-mono",children:I(Number(t.payments_total_usd))}),e.jsx("td",{className:"py-2 px-2 text-right",children:t.trial_pi_count>0?e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(K,{className:"h-3 w-3 text-violet-400"}),t.trial_pi_count]}):"â"}),e.jsx("td",{className:"py-2 px-2 text-right",children:(t.pub_works_count??0)>0?e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(C,{className:"h-3 w-3 text-emerald-400"}),(t.pub_works_count??0).toLocaleString()]}):"â"})]},t.npi)),r.leaders.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:8,className:"py-8 text-center text-muted-foreground",children:"No scored providers in this territory yet."})})]})]})}),r.capped&&e.jsxs("div",{className:"mt-4 rounded-md border border-amber-500/40 bg-amber-500/5 p-4 text-center",children:[e.jsx(T,{className:"h-4 w-4 inline mr-1 text-amber-400"}),e.jsx("span",{className:"text-sm",children:"Free preview shows the top 10. "}),e.jsx(p,{href:"/hcp-pro",children:e.jsx($,{size:"sm",variant:"outline",className:"ml-2","data-testid":"button-upgrade",children:"Upgrade to see the top 100"})})]})]})]})]})}export{B 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.