1import{r as f,j as e}from"./vendor-chartjs-DAQApR3A.js";import{E as w,P as S,a as R,U as E}from"./elitesCategories-CNBcEial.js";import{T as C,a as k}from"./Tabs-D3-uvlTq.js";import{u as T}from"./usePageTitle-zLDojgPu.js";import{g as A,h as _}from"./legislatorImage-BGycKJx-.js";import{L}from"./index-VXtZNIH-.js";import"./vendor-recharts-KyLwo51t.js";import"./vendor-maps-DjSiDsVE.js";function I(b){const o=[];let p=null,i=0;b.forEach((r,d)=>{if(r==null){o.push({rank:null,tie:!1});return}let x;p!==null&&r===p?x=i:(x=d+1,p=r,i=x),o.push({rank:x,tie:!1})});const l={};for(const r of o)r.rank!==null&&(l[r.rank]=(l[r.rank]||0)+1);for(const r of o)r.rank!==null&&l[r.rank]>1&&(r.tie=!0);return o}const M="/data/elite/rankings.json";let j=null;function P(){const[b,o]=f.useState(j),[p,i]=f.useState(!j),[l,r]=f.useState(null);return f.useEffect(()=>{if(j)return;let d=!1;async function x(){try{const t=await fetch(M);if(!t.ok)throw new Error(`HTTP ${t.status}`);const a=await t.json(),m=h=>h.map(n=>{const y=n.type||"",g=y==="Representative"?"House":y==="Senator"?"Senate":y;return{source_id:n.source_id,name:n.name||"",party:n.party||"",state:n.state||"",chamber:g,image_url:n.image_url,scores:n.scores||{},n:n.n}}),u={national:m(a.national||[]),state:m(a.state||[]),governor:m(a.governor||[])};j=u,d||(o(u),i(!1))}catch(t){d||(r(t instanceof Error?t.message:"Failed to load rankings"),i(!1))}}return x(),()=>{d=!0}},[]),{data:b,loading:p,error:l}}function O({legislators:b,category:o,partyFilter:p,chamberFilter:i,stateFilter:l}){const r=w[o],d=f.useMemo(()=>{let t=b;return p&&(t=t.filter(a=>a.party===p)),i&&(t=t.filter(a=>a.chamber===i)),l&&(t=t.filter(a=>a.state===l)),[...t].sort((a,m)=>{const u=a.scores[o],h=m.scores[o],n=u==null,y=h==null;return n&&y?0:n?1:y?-1:h-u})},[b,o,p,i,l]),x=f.useMemo(()=>I(d.map(t=>{const a=t.scores[o];return a==null?null:Math.round(a)})),[d,o]);return d.length===0?e.jsx("div",{className:"text-center py-12",style:{color:"var(--text-muted)"},children:"No legislators match the current filters."}):e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-xs mb-2",style:{color:"var(--text-muted)"},children:["Ranked by the share of communications in this category, adjusted for sample size (empirical-Bayes shrinkage) so legislators with few statements aren't ranked on noise. ",e.jsx("span",{className:"font-medium",children:"n"})," = classified statements."]}),e.jsx("div",{className:"rounded-xl overflow-hidden",style:{background:"var(--bg-tertiary)",border:"1px solid var(--border)"},children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{style:{background:"var(--bg-secondary)"},children:[e.jsx("th",{className:"py-2.5 px-4 text-left text-xs font-bold uppercase tracking-wide w-12",style:{color:"var(--text-muted)"},children:"#"}),e.jsx("th",{className:"py-2.5 px-4 text-left text-xs font-bold uppercase tracking-wide",style:{color:"var(--text-muted)"},children:"Legislator"}),e.jsx("th",{className:"py-2.5 px-4 text-left text-xs font-bold uppercase tracking-wide hidden md:table-cell",style:{color:"var(--text-muted)"},children:"Party"}),e.jsx("th",{className:"py-2.5 px-4 text-left text-xs font-bold uppercase tracking-wide hidden md:table-cell",style:{color:"var(--text-muted)"},children:"State"}),e.jsx("th",{className:"py-2.5 px-4 text-left text-xs font-bold uppercase tracking-wide hidden lg:table-cell",style:{color:"var(--text-muted)"},children:"Chamber"}),e.jsx("th",{className:"py-2.5 px-4 text-right text-xs font-bold uppercase tracking-wide",style:{color:r.color},children:r.label})]})}),e.jsx("tbody",{children:d.map((t,a)=>{const m=t.scores[o],u=m==null,h=Math.round(m||0),{rank:n,tie:y}=x[a],g=t.party||"Independent",s=S[g]||S.Independent,c=A(t.image_url);return e.jsxs("tr",{className:"transition-colors",style:{borderBottom:"1px solid var(--border)"},onMouseOver:v=>v.currentTarget.style.background="var(--bg-secondary)",onMouseOut:v=>v.currentTarget.style.background="transparent",children:[e.jsx("td",{className:"py-2.5 px-4",children:e.jsxs("span",{className:"text-sm font-bold tabular-nums",style:{color:n!==null&&n<=3?r.color:"var(--text-muted)"},children:[n===null?"-":n,y&&e.jsxs("span",{className:"font-normal",style:{color:"var(--text-muted)"},children:[" ","(tie)"]})]})}),e.jsx("td",{className:"py-2.5 px-4",children:e.jsxs(L,{to:`/elites/profile/${t.source_id}`,className:"flex items-center gap-2.5",style:{textDecoration:"none"},children:[c?e.jsx("img",{src:c,alt:"",className:"w-8 h-8 rounded-full object-cover flex-shrink-0",style:{border:`2px solid ${s}`},onError:_}):null,e.jsx("div",{className:`w-8 h-8 rounded-full flex items-center justify-center text-white text-xs font-bold flex-shrink-0 ${c?"hidden":""}`,style:{background:s},children:(t.name||"?").split(" ").pop()?.charAt(0)||"?"}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-sm",style:{color:"var(--text-primary)"},children:t.name||"Unknown"}),t.n!=null&&e.jsxs("span",{className:"text-xs block",style:{color:"var(--text-muted)"}
1,children:[t.n.toLocaleString()," statements"]}),e.jsxs("span",{className:"md:hidden text-xs block",style:{color:"var(--text-muted)"},children:[e.jsx("span",{style:{color:s},children:g.charAt(0)})," · ",t.state]})]})]})}),e.jsx("td",{className:"py-2.5 px-4 hidden md:table-cell",children:e.jsx("span",{className:"text-sm font-semibold",style:{color:s},children:g})}),e.jsx("td",{className:"py-2.5 px-4 hidden md:table-cell text-sm",style:{color:"var(--text-secondary)"},children:t.state}),e.jsx("td",{className:"py-2.5 px-4 hidden lg:table-cell text-sm",style:{color:"var(--text-secondary)"},children:t.chamber}),e.jsx("td",{className:"py-2.5 px-4 text-right",children:u?e.jsx("span",{className:"text-sm font-mono tabular-nums font-semibold",style:{color:"var(--text-muted)"},title:"No classified rhetoric yet",children:"-"}):e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx("div",{className:"w-16 h-[4px] rounded-full overflow-hidden hidden sm:block",style:{background:"var(--border)"},children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.min(h,100)}%`,background:r.color}})}),e.jsxs("span",{className:"text-sm font-mono tabular-nums font-semibold",style:{color:r.color},children:[h,"%"]})]})})]},t.source_id)})})]})})]})}function N({level:b}){const{data:o,loading:p,error:i}=P(),l=o?.[b]||[],[r,d]=f.useState(R[0]),[x,t]=f.useState(""),[a,m]=f.useState(""),[u,h]=f.useState(""),n=b==="national"?["House","Senate"]:b==="governor"?[]:["Lower","Upper","Legislature"],y=f.useMemo(()=>[...new Set(l.map(c=>c.state))].sort(),[l]);if(p)return e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"animate-spin rounded-full h-10 w-10 border-b-2 border-blue-600 mx-auto mb-3"}),e.jsxs("p",{className:"text-sm",style:{color:"var(--text-muted)"},children:["Loading ",l.length>0?`${l.length} legislators...`:"rankings..."]})]})});if(i)return e.jsx("div",{className:"text-center py-12 text-red-600",children:e.jsxs("p",{children:["Error loading rankings: ",i]})});const g=w[r];return e.jsxs("div",{children:[e.jsx("div",{className:"flex flex-wrap gap-0 mb-1",style:{borderBottom:"2px solid var(--border)"},children:R.map(s=>{const c=w[s],v=s===r;return e.jsxs("button",{onClick:()=>d(s),className:"px-3.5 py-2 text-sm font-semibold whitespace-nowrap transition-colors relative",style:{color:v?c.color:"var(--text-muted)",background:"transparent",border:"none",cursor:"pointer",marginBottom:"-2px"},children:[c.label,v&&e.jsx("span",{className:"absolute bottom-0 left-0 right-0 h-[2px]",style:{background:c.color}})]},s)})}),e.jsx("div",{className:"px-3.5 py-2 text-sm italic mb-4",style:{color:"var(--text-muted)",background:"var(--bg-secondary)",borderBottom:"1px solid var(--border)"},children:g.description}),e.jsxs("div",{className:"flex flex-wrap gap-3 mb-4",children:[e.jsxs("select",{value:x,onChange:s=>t(s.target.value),className:"px-3 py-1.5 rounded-lg text-sm",style:{background:"var(--bg-secondary)",border:"1px solid var(--border)",color:"var(--text-primary)"},children:[e.jsx("option",{value:"",children:"All Parties"}),e.jsx("option",{value:"Democrat",children:"Democrat"}),e.jsx("option",{value:"Republican",children:"Republican"}),e.jsx("option",{value:"Independent",children:"Independent"})]}),n.length>0&&e.jsxs("select",{value:a,onChange:s=>m(s.target.value),className:"px-3 py-1.5 rounded-lg text-sm",style:{background:"var(--bg-secondary)",border:"1px solid var(--border)",color:"var(--text-primary)"},children:[e.jsx("option",{value:"",children:"All Chambers"}),n.map(s=>e.jsx("option",{value:s,children:s},s))]}),e.jsxs("select",{value:u,onChange:s=>h(s.target.value),className:"px-3 py-1.5 rounded-lg text-sm",style:{background:"var(--bg-secondary)",border:"1px solid var(--border)",color:"var(--text-primary)"},children:[e.jsx("option",{value:"",children:"All States"}),y.map(s=>{const c=E.find(v=>v.name===s);return e.jsx("option",{value:s,children:c?`${c.name} (${c.code})`:s},s)})]}),(x||a||u)&&e.jsx("button",{onClick:()=>{t(""),m(""),h("")},className:"px-3 py-1.5 rounded-lg text-sm transition-colors hover:bg-red-50 hover:text-red-600",style:{background:"var(--bg-secondary)",border:"1px solid var(--border)",color:"var(--text-secondary)"},children:"Clear"}),e.jsxs("span",{className:"text-sm py-1.5",style:{color:"var(--text-muted)"},children:[l.length," legislators"]})]}),e.jsx(O,{legislators:l,category:r,partyFilter:x,chamberFilter:a,stateFilter:u})]})}const $=[{key:"national",label:"National (Congress)",color:"#2563eb"}
1,{key:"state",label:"State Legislators",color:"#059669"},{key:"governor",label:"Governors",color:"#7c3aed"}];function z(){return T("Rhetoric Rankings"),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h1",{className:"font-bold mb-2",style:{color:"var(--text-primary)",fontSize:"1.5rem"},children:"Rhetoric Rankings"}),e.jsx("p",{style:{color:"var(--text-secondary)",lineHeight:"1.6"},children:"All legislators ranked by the percentage of their public communications classified in each rhetoric category."})]}),e.jsxs(C,{tabs:$,urlKey:"scope",children:[e.jsx(k,{children:e.jsx(N,{level:"national"})}),e.jsx(k,{children:e.jsx(N,{level:"state"})}),e.jsx(k,{children:e.jsx(N,{level:"governor"})})]})]})}export{z as ElitesRankings,O as RankingsTable,$ as SCOPE_TABS,P as useRankingsData};
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.