import{r as d,j as n}from"./index-Dbk1Plmn.js";import{e as f,g,b as y}from"./agent_badge-BZd6ZAh5.js";function p(l){if(!l||typeof l!="object")return null;const t=l;return t.agent_attribution&&typeof t.agent_attribution=="object"&&!Array.isArray(t.agent_attribution)?t.agent_attribution:t.provenance&&typeof t.provenance=="object"&&!Array.isArray(t.provenance)?t.provenance:null}function v(l){const[t,c]=d.useState({kind:"all"}),u=d.useMemo(()=>{const o=new Map;for(const i of l??[]){const e=f(p(i)),r=g(e);if(!r)continue;const a=y(e),s=o.get(r);s?s.count+=1:o.set(r,{label:a,count:1})}return[...o.entries()].map(([i,e])=>({key:i,label:e.label,count:e.count})).sort((i,e)=>e.count-i.count)},[l]);function b(o){return t.kind==="all"?o:o.filter(i=>{const e=f(p(i));return t.kind==="tier"?((e==null?void 0:e.attribution_tier)??"anonymous")===t.tier:g(e)===t.key})}return{filter:t,setFilter:c,filterRows:b,AgentFilterControl:({className:o})=>{const i=t.kind==="all"?"all":t.kind==="tier"?`tier:${t.tier}`:`agent:${t.key}`;return n.jsxs("div",{className:"flex flex-col gap-1.5 "+(o??""),children:[n.jsx("label",{htmlFor:"agent-filter",className:"text-xs font-medium text-muted-foreground",children:"Agent"}),n.jsxs("select",{id:"agent-filter",value:i,onChange:e=>{const r=e.target.value;if(r==="all")c({kind:"all"});else if(r.startsWith("tier:"))c({kind:"tier",tier:r.slice(5)});else if(r.startsWith("agent:")){const a=r.slice(6),s=u.find(x=>x.key===a);c({kind:"agent",key:a,label:(s==null?void 0:s.label)??a})}},className:"h-8 rounded-md border border-input bg-background px-2 text-xs",children:[n.jsx("option",{value:"all",children:"All agents"}),n.jsxs("optgroup",{label:"By trust tier",children:[n.jsx("option",{value:"tier:hardware",children:"◆ Hardware-verified"}),n.jsx("option",{value:"tier:software",children:"◇ Software-verified"}),n.jsx("option",{value:"tier:unverified_client",children:"● Self-reported"}),n.jsx("option",{value:"tier:anonymous",children:"○ Anonymous"})]}),u.length>0&&n.jsx("optgroup",{label:"By agent (this page)",children:u.map(e=>n.jsxs("option",{value:`agent:${e.key}`,children:[e.label," (",e.count,")"]},e.key))})]})]})}}}export{v as u};
