diff --git "a/assets/PaperDetailView-xIdW2JSy.js" "b/assets/PaperDetailView-xIdW2JSy.js" new file mode 100644--- /dev/null +++ "b/assets/PaperDetailView-xIdW2JSy.js" @@ -0,0 +1,38 @@ +import{f as Ve,g as Er,r as i,j as e,P as Pt,h as se,k as ks,l as lt,m as xe,n as Sr,o as _s,C as he,p as ae,q as je,s as ye,X as ws,t as De,v as Pr,w as Ns,x as Rr,y as Ir,z as Ar,A as Fr,B as $r,D as Le,R as Tr,E as ve,F as Cs,G as Es,H as Lr,I as Mr,J as Dr,K as Ur,M as qr,N as Br,O as Or,Q as Hr,S as ls,T as Kr,U as zr,V as Qr,W as Vr,e as ct,Y as Rt,b as ot,Z as Ss,c as Ps,d as Gr,_ as Wr,a as Jr,$ as Xr,L as ue,a0 as Yr,a1 as Zr,a2 as ea,a3 as ta,a4 as sa,a5 as ra,a6 as aa}from"./index-CSNOTM3s.js";import{u as le}from"./useQuery-DCf2mroJ.js";import{I as te,S as na,a as ia,T as oa,M as la}from"./components-PxXQJAWo.js";import{C as ca,E as da}from"./ExternalSourceEvalBadge-CuljE-w8.js";import{L as st,a as ua}from"./LatexTitle-D0X1MVE6.js";import{c as ma}from"./transform-BGwKHn4w.js";import{f as pa,D as ha}from"./latexPlainText-ChVkH0gY.js";import{a as fa}from"./usePapers-CFugWskp.js";import{S as Ke}from"./skeleton-DIecj65I.js";import{A as ga,a as xa}from"./alert-DuO9Nm7q.js";import{B as K}from"./button-KGqIZs29.js";import{u as va}from"./index-CAtHIP-4.js";import{I as oe}from"./textarea-BajbF2-p.js";import{D as ke,a as _e,b as we,c as Ne,d as Ce,e as Ee,R as ba,P as ja,O as ya,C as ka}from"./dialog-CQwQlPi_.js";import{u as Se}from"./useMutation-D90cYkan.js";import{S as It,P as At,a as _a}from"./SignInToEditDialog-qIIvqqtG.js";import{L as ce}from"./loader-circle-BCRahFjZ.js";import{B as Rs,D as wa,c as Na,g as Ca,s as Ea,a as Sa,b as Pa,d as Ra,i as Ia,e as Aa}from"./codexAddEvals-DqYnwrnj.js";import{G as cs}from"./github-x66pH1Ze.js";import{M as Fa,r as $a}from"./index-CVIt_dyy.js";import"./hover-card-D24Q2Pl3.js";import"./katex.min-BSBacQyE.js";import"./useInfiniteQuery-_jD1bF9N.js";/** + * @license lucide-react v0.462.0 - ISC + * + * This source code is licensed under the ISC license. + * See the LICENSE file in the root directory of this source tree. + */const Ta=Ve("ChevronsUpDown",[["path",{d:"m7 15 5 5 5-5",key:"1hf1tw"}],["path",{d:"m7 9 5-5 5 5",key:"sgt6xg"}]]);/** + * @license lucide-react v0.462.0 - ISC + * + * This source code is licensed under the ISC license. + * See the LICENSE file in the root directory of this source tree. + */const ds=Ve("Globe",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]]);/** + * @license lucide-react v0.462.0 - ISC + * + * This source code is licensed under the ISC license. + * See the LICENSE file in the root directory of this source tree. + */const Qe=Ve("Search",[["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}],["path",{d:"m21 21-4.3-4.3",key:"1qie3q"}]]);/** + * @license lucide-react v0.462.0 - ISC + * + * This source code is licensed under the ISC license. + * See the LICENSE file in the root directory of this source tree. + */const Is=Ve("Star",[["path",{d:"M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z",key:"r04s7s"}]]);/** + * @license lucide-react v0.462.0 - ISC + * + * This source code is licensed under the ISC license. + * See the LICENSE file in the root directory of this source tree. + */const Ft=Ve("Trash2",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]]);function La(t){return(t??[]).filter(s=>!!(s.dataset_slug&&s.task_slug))}function Ma(t,s,a="https://paperswithcode.co"){return s.map(c=>{const n=encodeURIComponent(c.evaluation_id),o=`${a}/api/v1/papers/${encodeURIComponent(t)}/leaderboard-badge.svg?eval=${n}&live=1`,l=new URLSearchParams({task:c.task_slug,eval:c.evaluation_id}),m=`${a}/benchmark/${encodeURIComponent(c.dataset_slug)}?${l.toString()}`;return`[![${`Papers with Code: ${c.best_rank===1?"SOTA":`#${c.best_rank}`} on ${c.dataset_name}`}](${o})](${m})`}).join(` +`)}function Da(t,s=!0){return le({queryKey:["evaluations","paper",t],queryFn:()=>{if(!t)throw new Error("Paper ID is required");return Er(t)},enabled:s&&!!t,staleTime:0,refetchOnMount:"always"})}const As=t=>t.replace(/v\d+$/,""),Ua={models:"https://huggingface.co/",datasets:"https://huggingface.co/datasets/",spaces:"https://huggingface.co/spaces/"},xt=(t,s)=>{const a=(t[s]||[]).length;return a<100?{count:a,isLimited:!1}:{count:a,isLimited:!0}},vt=(t,s)=>{const a=t[s];return Array.isArray(a)?a.map(c=>{if(typeof c=="string")return c;if(c&&typeof c=="object"){const n=c;return n.id||n.repoId||null}return null}).filter(c=>!!c).map(c=>`${Ua[s]}${c}`):[]},qa=async t=>{try{return(await fetch(`https://huggingface.co/api/papers/${As(t)}`)).ok}catch{return!1}},Ba=async t=>{const s=As(t),[a,c]=await Promise.all([fetch(`https://huggingface.co/api/arxiv/${s}/repos`).then(async m=>m.ok?m.json():(console.warn(`Failed to fetch repos for arXiv:${s}, status: ${m.status}`),null)).catch(m=>(console.warn(`Failed to fetch repos for arXiv:${s}:`,m),null)),qa(s)]);if(!a)return{models:0,datasets:0,spaces:0,modelUrls:[],datasetUrls:[],spaceUrls:[],isLimited:!1,paperExists:c};const n=xt(a,"models"),o=xt(a,"datasets"),l=xt(a,"spaces");return{models:n.count,datasets:o.count,spaces:l.count,modelUrls:vt(a,"models"),datasetUrls:vt(a,"datasets"),spaceUrls:vt(a,"spaces"),isLimited:n.isLimited||o.isLimited||l.isLimited,paperExists:c}},Oa=t=>le({queryKey:["huggingface-repos",t],queryFn:()=>Ba(t),enabled:!!t,staleTime:10*60*1e3,retry:1});function Ha(){const[t,s]=i.useState(!1),[a,c]=i.useState(!1),[n,o]=i.useState(!1),[l,m]=i.useState(!1),[r,h]=i.useState(!1),[y,k]=i.useState(!1);return{isEditingTasks:t,openTasksDialog:()=>s(!0),closeTasksDialog:()=>s(!1),setIsEditingTasks:s,isEditingMethods:a,openMethodsDialog:()=>c(!0),closeMethodsDialog:()=>c(!1),setIsEditingMethods:c,isEditingRepositories:n,openRepositoriesDialog:()=>o(!0),closeRepositoriesDialog:()=>o(!1),setIsEditingRepositories:o,isEditingProjectPages:l,openProjectPagesDialog:()=>m(!0),closeProjectPagesDialog:()=>m(!1),setIsEditingProjectPages:m,isEditingEvaluations:r,openEvaluationsDialog:()=>h(!0),closeEvaluationsDialog:()=>h(!1),setIsEditingEvaluations:h,isEditingSourceUrl:y,openSourceUrlDialog:()=>k(!0),closeSourceUrlDialog:()=>k(!1),setIsEditingSourceUrl:k}}var dt="Checkbox",[Ka]=_s(dt),[za,$t]=Ka(dt);function Qa(t){const{__scopeCheckbox:s,checked:a,children:c,defaultChecked:n,disabled:o,form:l,name:m,onCheckedChange:r,required:h,value:y="on",internal_do_not_use_render:k}=t,[P,E]=ks({prop:a,defaultProp:n??!1,onChange:r,caller:dt}),[v,$]=i.useState(null),[U,T]=i.useState(null),L=i.useRef(!1),q=v?!!l||!!v.closest("form"):!0,D={checked:P,disabled:o,setChecked:E,control:v,setControl:$,name:m,form:l,value:y,hasConsumerStoppedPropagationRef:L,required:h,defaultChecked:me(n)?!1:n,isFormControl:q,bubbleInput:U,setBubbleInput:T};return e.jsx(za,{scope:s,...D,children:Va(k)?k(D):c})}var Fs="CheckboxTrigger",$s=i.forwardRef(({__scopeCheckbox:t,onKeyDown:s,onClick:a,...c},n)=>{const{control:o,value:l,disabled:m,checked:r,required:h,setControl:y,setChecked:k,hasConsumerStoppedPropagationRef:P,isFormControl:E,bubbleInput:v}=$t(Fs,t),$=lt(n,y),U=i.useRef(r);return i.useEffect(()=>{const T=o==null?void 0:o.form;if(T){const L=()=>k(U.current);return T.addEventListener("reset",L),()=>T.removeEventListener("reset",L)}},[o,k]),e.jsx(se.button,{type:"button",role:"checkbox","aria-checked":me(r)?"mixed":r,"aria-required":h,"data-state":Us(r),"data-disabled":m?"":void 0,disabled:m,value:l,...c,ref:$,onKeyDown:xe(s,T=>{T.key==="Enter"&&T.preventDefault()}),onClick:xe(a,T=>{k(L=>me(L)?!0:!L),v&&E&&(P.current=T.isPropagationStopped(),P.current||T.stopPropagation())})})});$s.displayName=Fs;var Tt=i.forwardRef((t,s)=>{const{__scopeCheckbox:a,name:c,checked:n,defaultChecked:o,required:l,disabled:m,value:r,onCheckedChange:h,form:y,...k}=t;return e.jsx(Qa,{__scopeCheckbox:a,checked:n,defaultChecked:o,disabled:m,required:l,onCheckedChange:h,name:c,form:y,value:r,internal_do_not_use_render:({isFormControl:P})=>e.jsxs(e.Fragment,{children:[e.jsx($s,{...k,ref:s,__scopeCheckbox:a}),P&&e.jsx(Ds,{__scopeCheckbox:a})]})})});Tt.displayName=dt;var Ts="CheckboxIndicator",Ls=i.forwardRef((t,s)=>{const{__scopeCheckbox:a,forceMount:c,...n}=t,o=$t(Ts,a);return e.jsx(Pt,{present:c||me(o.checked)||o.checked===!0,children:e.jsx(se.span,{"data-state":Us(o.checked),"data-disabled":o.disabled?"":void 0,...n,ref:s,style:{pointerEvents:"none",...t.style}})})});Ls.displayName=Ts;var Ms="CheckboxBubbleInput",Ds=i.forwardRef(({__scopeCheckbox:t,...s},a)=>{const{control:c,hasConsumerStoppedPropagationRef:n,checked:o,defaultChecked:l,required:m,disabled:r,name:h,value:y,form:k,bubbleInput:P,setBubbleInput:E}=$t(Ms,t),v=lt(a,E),$=va(o),U=Sr(c);i.useEffect(()=>{const L=P;if(!L)return;const q=window.HTMLInputElement.prototype,C=Object.getOwnPropertyDescriptor(q,"checked").set,f=!n.current;if($!==o&&C){const x=new Event("click",{bubbles:f});L.indeterminate=me(o),C.call(L,me(o)?!1:o),L.dispatchEvent(x)}},[P,$,o,n]);const T=i.useRef(me(o)?!1:o);return e.jsx(se.input,{type:"checkbox","aria-hidden":!0,defaultChecked:l??T.current,required:m,disabled:r,name:h,value:y,form:k,...s,tabIndex:-1,ref:v,style:{...s.style,...U,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});Ds.displayName=Ms;function Va(t){return typeof t=="function"}function me(t){return t==="indeterminate"}function Us(t){return me(t)?"indeterminate":t?"checked":"unchecked"}const Lt=i.forwardRef(({className:t,style:s,...a},c)=>e.jsx(Tt,{ref:c,className:ae("peer h-4 w-4 shrink-0 rounded-sm ring-offset-background data-[state=checked]:!bg-black data-[state=checked]:!text-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",t),style:{border:"1px solid #000",...s},...a,children:e.jsx(Ls,{className:ae("flex items-center justify-center text-current"),children:e.jsx(he,{className:"h-4 w-4"})})}));Lt.displayName=Tt.displayName;function Ga(t,s,a){if(!t)return t;const c=n=>n.paper_id!==s||n.paper_title===a?n:{...n,paper_title:a};if(Array.isArray(t)){const n=t.map(c);return n.some((l,m)=>l!==t[m])?n:t}if(Array.isArray(t.results)){const n=t.results.map(c);return n.some((l,m)=>l!==t.results[m])?{...t,results:n}:t}return t}function Ge(t,s,a){new Set([...a,s.id,s.arxiv_id].filter(l=>!!l)).forEach(l=>{t.setQueryData(["paper",l],s),t.setQueryData(["paper-arxiv",l],s)}),t.invalidateQueries({queryKey:["papers"],refetchType:"none"}),t.invalidateQueries({queryKey:["papers-infinite"],refetchType:"none"}),t.invalidateQueries({queryKey:["task-papers-infinite"],refetchType:"none"});const n=String(s.id),o=l=>Ga(l,n,s.title);t.setQueriesData({queryKey:["evaluations"]},o),t.setQueriesData({queryKey:["dataset-evals"]},o),t.invalidateQueries({queryKey:["evaluations"],refetchType:"none"}),t.invalidateQueries({queryKey:["dataset-evals"],refetchType:"none"})}function Ue({isAuthor:t=!1}){return e.jsxs("div",{className:"rounded-md border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-900 dark:border-amber-900 dark:bg-amber-950/40 dark:text-amber-100",children:[e.jsx("p",{className:"font-medium",children:"Your changes will be reviewed by an admin."}),e.jsx("p",{className:"mt-1 leading-snug",children:t?"We can see this paper is yours. While we're in early access an admin still reviews each edit; this will become automatic for authors soon.":"Submissions are queued for review and don't change the paper page until an admin approves them."})]})}const Wa=250,Ja=100;function Xa({open:t,onOpenChange:s,paperId:a,arxivId:c,initialTaskIds:n,initialTasks:o,onSuccess:l,submitMode:m="direct",isAuthor:r=!1}){const[h,y]=i.useState(n),[k,P]=i.useState(!1),[E,v]=i.useState(""),[$,U]=i.useState(""),[T,L]=i.useState(new Map),q=je(),{toast:D}=ye(),C=i.useRef(!1);i.useEffect(()=>{if(!t){C.current=!1;return}if(C.current)return;C.current=!0,y(n),v(""),U("");const b=new Map;(o||[]).forEach(R=>{const F=parseInt(R.id);Number.isNaN(F)||b.set(F,R)}),L(b)},[t,n,o]),i.useEffect(()=>{const b=window.setTimeout(()=>{U(E.trim())},Wa);return()=>window.clearTimeout(b)},[E]);const{data:f,isFetching:x}=le({queryKey:["tasks-search",$],queryFn:()=>Ns({page_size:Ja,visible_only:!0,...$?{q:$}:{}}),enabled:t});i.useEffect(()=>{var b;(b=f==null?void 0:f.results)!=null&&b.length&&L(R=>{const F=new Map(R);return f.results.forEach(A=>{const I=parseInt(A.id);Number.isNaN(I)||F.set(I,A)}),F})},[f]);const M=i.useMemo(()=>{const b=(f==null?void 0:f.results)||[],R=new Set,F=[];return h.forEach(A=>{if(R.has(A))return;const I=T.get(A);I&&(F.push(I),R.add(A))}),b.forEach(A=>{const I=parseInt(A.id);Number.isNaN(I)||R.has(I)||(F.push(A),R.add(I))}),F},[f,h,T]),B=Se({mutationFn:async({paperId:b,taskIds:R})=>m==="pending"?(await De({paper_id:parseInt(b),edit_type:"tasks",proposed_payload:{task_ids:R}}),null):Pr(b,R),onMutate:async({taskIds:b})=>{if(m==="pending")return{snapshots:[]};const R=b.map(I=>T.get(I)).filter(I=>!!I).map(I=>({id:I.id,name:I.name,slug:I.slug})).sort((I,Y)=>I.name.localeCompare(Y.name)),F=Array.from(new Set([a,c].filter(I=>!!I)));await Promise.all(F.flatMap(I=>[q.cancelQueries({queryKey:["paper",I]}),q.cancelQueries({queryKey:["paper-arxiv",I]})]));const A=[];return F.forEach(I=>{["paper","paper-arxiv"].forEach(Y=>{const j=[Y,I],_=q.getQueryData(j);A.push({key:j,data:_}),_&&q.setQueryData(j,{..._,tasks:R})})}),D({title:"Tasks updated",description:`Saved ${b.length} task${b.length===1?"":"s"} for this paper.`}),l==null||l(),s(!1),{snapshots:A}},onSuccess:b=>{if(m==="pending"){D({title:"Edit submitted for review",description:"Thanks! An admin will review your proposed task changes shortly."}),l==null||l(),s(!1);return}b&&Ge(q,b,[a,c])},onError:(b,R,F)=>{var Y,j;(Y=F==null?void 0:F.snapshots)==null||Y.forEach(({key:_,data:u})=>{q.setQueryData(_,u)});const A=b;let I=A.message||(m==="pending"?"Failed to submit your edit. Please try again.":"Failed to update paper tasks.");if(A.response)try{const _=JSON.parse(A.response);typeof(_==null?void 0:_.detail)=="string"?I=_.detail:Array.isArray(_==null?void 0:_.detail)&&((j=_.detail[0])!=null&&j.msg)&&(I=_.detail[0].msg)}catch{I=A.response}D({title:m==="pending"?"Could not submit edit":"Could not save tasks",description:I,variant:"destructive"})}}),O=()=>{B.mutate({paperId:a,taskIds:h})},z=i.useMemo(()=>{if(h.length!==n.length)return!0;const b=new Set(n);return h.some(R=>!b.has(R))},[h,n]),V=(b,R)=>{y(F=>R?F.includes(b)?F:[...F,b]:F.filter(A=>A!==b))},ee=()=>v("");return e.jsxs(ke,{open:t,onOpenChange:s,children:[e.jsxs(_e,{className:"max-w-2xl max-h-[600px]",children:[e.jsxs(we,{children:[e.jsx(Ne,{children:"Edit Paper Tasks"}),e.jsx(Ce,{children:"Select the tasks that this paper addresses. You can select multiple tasks."})]}),m==="pending"&&e.jsx(Ue,{isAuthor:r}),e.jsxs("div",{className:"relative mb-4",children:[e.jsx(Qe,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(oe,{type:"text",placeholder:"Search tasks...",value:E,onChange:b=>v(b.target.value),className:"pl-9 pr-9"}),E&&e.jsx("button",{type:"button",onClick:ee,className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-muted-foreground hover:text-foreground","aria-label":"Clear search",children:e.jsx(ws,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"py-4 overflow-y-auto max-h-[400px]",children:M.length>0?e.jsx("div",{className:"space-y-2",children:M.map(b=>{const R=parseInt(b.id),F=h.includes(R);return e.jsxs("div",{className:"flex items-center space-x-2 p-2 hover:bg-muted/50 rounded-md",children:[e.jsx(Lt,{id:`task-${b.id}`,checked:F,onCheckedChange:A=>V(R,A===!0),className:"!border !border-black data-[state=checked]:!bg-black data-[state=checked]:!text-white"}),e.jsxs("label",{htmlFor:`task-${b.id}`,className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 cursor-pointer flex-1",children:[b.name,b.description&&e.jsxs("span",{className:"block text-xs text-muted-foreground font-normal mt-1",children:[b.description.substring(0,100),b.description.length>100?"...":""]})]})]},b.id)})}):x?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(ce,{className:"w-8 h-8 mx-auto mb-2 animate-spin"}),e.jsx("p",{children:"Loading tasks..."})]}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(Qe,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:$?`No tasks found matching "${$}"`:"No tasks available"})]})}),e.jsxs(Ee,{children:[e.jsx(K,{variant:"ghost",className:"sm:mr-auto",onClick:()=>P(!0),children:"Suggest a new task"}),e.jsx(K,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(K,{onClick:O,disabled:B.isPending||!z,children:B.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"w-4 h-4 mr-2 animate-spin"}),m==="pending"?"Submitting...":"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(he,{className:"w-4 h-4 mr-2"}),m==="pending"?"Submit for review":"Save Changes"]})})]})]}),e.jsx(It,{open:k,onOpenChange:P,paperId:a,kind:"task"})]})}const Ya=250,Za=100;function en({open:t,onOpenChange:s,paperId:a,arxivId:c,initialMethodIds:n,initialMethods:o,onSuccess:l,submitMode:m="direct",isAuthor:r=!1}){const[h,y]=i.useState(n),[k,P]=i.useState(!1),[E,v]=i.useState(""),[$,U]=i.useState(""),[T,L]=i.useState(new Map),q=je(),{toast:D}=ye(),C=i.useRef(!1);i.useEffect(()=>{if(!t){C.current=!1;return}if(C.current)return;C.current=!0,y(n),v(""),U("");const b=new Map;(o||[]).forEach(R=>{const F=parseInt(R.id);Number.isNaN(F)||b.set(F,R)}),L(b)},[t,n,o]),i.useEffect(()=>{const b=window.setTimeout(()=>{U(E.trim())},Ya);return()=>window.clearTimeout(b)},[E]);const{data:f,isFetching:x}=le({queryKey:["methods-search",$],queryFn:()=>Ir({page_size:Za,...$?{q:$}:{}}),enabled:t});i.useEffect(()=>{var b;(b=f==null?void 0:f.results)!=null&&b.length&&L(R=>{const F=new Map(R);return f.results.forEach(A=>{const I=parseInt(A.id);Number.isNaN(I)||F.set(I,A)}),F})},[f]);const M=i.useMemo(()=>{const b=(f==null?void 0:f.results)||[],R=new Set,F=[];return h.forEach(A=>{if(R.has(A))return;const I=T.get(A);I&&(F.push(I),R.add(A))}),b.forEach(A=>{const I=parseInt(A.id);Number.isNaN(I)||R.has(I)||(F.push(A),R.add(I))}),F},[f,h,T]),B=Se({mutationFn:async({paperId:b,methodIds:R})=>m==="pending"?(await De({paper_id:parseInt(b),edit_type:"methods",proposed_payload:{method_ids:R}}),null):Rr(b,R),onSuccess:b=>{if(m==="pending"){D({title:"Edit submitted for review",description:"Thanks! An admin will review your proposed method changes shortly."}),l==null||l(),s(!1);return}b&&Ge(q,b,[a,c]),D({title:"Methods updated",description:`Saved ${h.length} method${h.length===1?"":"s"} for this paper.`}),l==null||l(),s(!1)},onError:b=>{var A;const R=b;let F=R.message||(m==="pending"?"Failed to submit your edit. Please try again.":"Failed to update paper methods.");if(R.response)try{const I=JSON.parse(R.response);typeof(I==null?void 0:I.detail)=="string"?F=I.detail:Array.isArray(I==null?void 0:I.detail)&&((A=I.detail[0])!=null&&A.msg)&&(F=I.detail[0].msg)}catch{F=R.response}D({title:m==="pending"?"Could not submit edit":"Could not save methods",description:F,variant:"destructive"})}}),O=()=>{B.mutate({paperId:a,methodIds:h})},z=i.useMemo(()=>{if(h.length!==n.length)return!0;const b=new Set(n);return h.some(R=>!b.has(R))},[h,n]),V=(b,R)=>{y(F=>R?F.includes(b)?F:[...F,b]:F.filter(A=>A!==b))},ee=()=>v("");return e.jsxs(ke,{open:t,onOpenChange:s,children:[e.jsxs(_e,{className:"max-w-2xl max-h-[600px]",children:[e.jsxs(we,{children:[e.jsx(Ne,{children:"Edit Paper Methods"}),e.jsx(Ce,{children:"Select the methods and techniques used in this paper. You can select multiple methods."})]}),m==="pending"&&e.jsx(Ue,{isAuthor:r}),e.jsxs("div",{className:"relative mb-4",children:[e.jsx(Qe,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(oe,{type:"text",placeholder:"Search methods...",value:E,onChange:b=>v(b.target.value),className:"pl-9 pr-9"}),E&&e.jsx("button",{type:"button",onClick:ee,className:"absolute right-2 top-1/2 -translate-y-1/2 p-1 text-muted-foreground hover:text-foreground","aria-label":"Clear search",children:e.jsx(ws,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"py-4 overflow-y-auto max-h-[400px]",children:M.length>0?e.jsx("div",{className:"space-y-2",children:M.map(b=>{const R=parseInt(b.id),F=h.includes(R);return e.jsxs("div",{className:"flex items-center space-x-2 p-2 hover:bg-muted/50 rounded-md",children:[e.jsx(Lt,{id:`method-${b.id}`,checked:F,onCheckedChange:A=>V(R,A===!0),className:"!border !border-black data-[state=checked]:!bg-black data-[state=checked]:!text-white"}),e.jsxs("label",{htmlFor:`method-${b.id}`,className:"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 cursor-pointer flex-1",children:[b.name,b.full_name&&b.full_name!==b.name&&e.jsx("span",{className:"block text-xs text-muted-foreground font-normal",children:b.full_name}),b.description&&e.jsxs("span",{className:"block text-xs text-muted-foreground font-normal mt-1",children:[b.description.substring(0,100),b.description.length>100?"...":""]})]})]},b.id)})}):x?e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(ce,{className:"w-8 h-8 mx-auto mb-2 animate-spin"}),e.jsx("p",{children:"Loading methods..."})]}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(Qe,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{children:$?`No methods found matching "${$}"`:"No methods available"})]})}),e.jsxs(Ee,{children:[e.jsx(K,{variant:"ghost",className:"sm:mr-auto",onClick:()=>P(!0),children:"Suggest a new method"}),e.jsx(K,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(K,{onClick:O,disabled:B.isPending||!z,children:B.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"w-4 h-4 mr-2 animate-spin"}),m==="pending"?"Submitting...":"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(he,{className:"w-4 h-4 mr-2"}),m==="pending"?"Submit for review":"Save Changes"]})})]})]}),e.jsx(It,{open:k,onOpenChange:P,paperId:a,kind:"method"})]})}function ze(t){const s=t.trim();if(!s)return null;let a=s;!a.startsWith("http://")&&!a.startsWith("https://")&&(a=`https://${a}`);try{const c=new URL(a);if(c.hostname.toLowerCase()!=="github.com")return null;const n=c.pathname.split("/").filter(Boolean);if(n.length<2)return null;const o=n[0].toLowerCase();let l=n[1].toLowerCase();return l.endsWith(".git")&&(l=l.slice(0,-4)),`https://github.com/${o}/${l}`}catch{return null}}function us(t,s){const a=ze(t),c=ze(s);return a&&c?a===c:t.trim()===s.trim()}function tn({open:t,onOpenChange:s,paperId:a,arxivId:c,initialRepositories:n,onSuccess:o,submitMode:l="direct",isAuthor:m=!1}){const[r,h]=i.useState(n),[y,k]=i.useState(""),P=je(),{toast:E}=ye(),v=i.useRef(!1);i.useEffect(()=>{if(!t){v.current=!1;return}v.current||(v.current=!0,h(n),k(""))},[t,n]);const $=Se({mutationFn:async({paperId:x,repositories:M})=>l==="pending"?(await De({paper_id:parseInt(x),edit_type:"repositories",proposed_payload:{repositories:M}}),null):Ar(x,M),onSuccess:x=>{if(l==="pending"){E({title:"Edit submitted for review",description:"Thanks! An admin will review your proposed repository changes shortly."}),o==null||o(),s(!1),k("");return}x&&Ge(P,x,[a,c]),o==null||o(),s(!1),k("")},onError:x=>{var O;const M=x;let B=M.message||(l==="pending"?"Failed to submit your edit. Please try again.":"Failed to update paper repositories.");if(M.response)try{const z=JSON.parse(M.response);typeof(z==null?void 0:z.detail)=="string"?B=z.detail:Array.isArray(z==null?void 0:z.detail)&&((O=z.detail[0])!=null&&O.msg)&&(B=z.detail[0].msg)}catch{B=M.response}E({title:l==="pending"?"Could not submit edit":"Could not save repositories",description:B,variant:"destructive"})}}),U=x=>{const M=[];for(const B of x){const O=M.find(z=>us(z.url,B.url));if(O)O.is_official=O.is_official||B.is_official;else{const z=ze(B.url);M.push({url:z??B.url.trim(),is_official:B.is_official})}}return M},T=()=>{const x=y.trim(),M=x?[...r,{url:x,is_official:!1}]:r;return x&&r.some(B=>us(B.url,x))?(alert("This repository URL is already added"),null):U(M)},L=()=>{const x=T();x!==null&&x.length!==r.length&&(h(x),k(""))},q=x=>{h(r.filter(M=>M.url!==x))},D=x=>{h(r.map(M=>M.url===x?{...M,is_official:!M.is_official}:M))},C=()=>{const x=T();x!==null&&$.mutate({paperId:a,repositories:x})},f=i.useMemo(()=>{const x=y.trim(),M=x?[...r,{url:x,is_official:!1}]:r;if(M.length!==n.length)return!0;const B=U(n),O=U(M);if(O.length!==B.length)return!0;const z=new Map(B.map(V=>[ze(V.url)??V.url.trim(),!!V.is_official]));return O.some(V=>{const ee=ze(V.url)??V.url.trim(),b=z.get(ee);return b===void 0||b!==!!V.is_official})},[r,y,n]);return e.jsx(ke,{open:t,onOpenChange:s,children:e.jsxs(_e,{className:"max-w-2xl max-h-[600px]",children:[e.jsxs(we,{children:[e.jsx(Ne,{children:"Edit Paper Repositories"}),e.jsx(Ce,{children:"Add or remove GitHub repository URLs associated with this paper. Mark repositories as official if they are created by the paper authors."})]}),l==="pending"&&e.jsx(Ue,{isAuthor:m}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Add Repository URL"}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(oe,{type:"url",placeholder:"https://github.com/owner/repo",value:y,onChange:x=>k(x.target.value),onKeyPress:x=>{x.key==="Enter"&&(x.preventDefault(),L())},className:"flex-1"}),e.jsxs(K,{onClick:L,size:"sm",disabled:!y.trim(),children:[e.jsx(At,{className:"w-4 h-4 mr-1"}),"Add"]})]})]}),e.jsx("div",{className:"py-4 overflow-y-auto max-h-[350px]",children:r.length>0?e.jsx("div",{className:"space-y-2",children:r.map((x,M)=>e.jsxs("div",{className:"flex items-center space-x-2 p-3 bg-muted/30 rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsx(cs,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("span",{className:"text-sm font-medium text-paper-blue truncate",children:x.url}),x.is_official&&e.jsx(Rs,{variant:"secondary",className:"text-xs",children:"Official"})]})}),e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsxs(K,{variant:x.is_official?"default":"outline",size:"sm",onClick:()=>D(x.url),className:"h-8 px-2 text-xs",title:x.is_official?"Click to unmark as official (created by paper authors)":"Click to mark as official (created by paper authors)",children:[e.jsx(Is,{className:`w-3.5 h-3.5 mr-1 ${x.is_official?"fill-current":""}`}),x.is_official?"Official":"Mark official"]}),e.jsx(K,{variant:"ghost",size:"sm",onClick:()=>q(x.url),className:"h-8 px-2 text-destructive hover:text-destructive",title:"Remove repository",children:e.jsx(Ft,{className:"w-4 h-4"})})]})]},M))}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(cs,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No repositories added yet"}),e.jsx("p",{className:"text-xs mt-1",children:"Add a repository URL above to get started"})]})}),e.jsxs(Ee,{children:[e.jsx(K,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(K,{onClick:C,disabled:$.isPending||!f,children:$.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"w-4 h-4 mr-2 animate-spin"}),l==="pending"?"Submitting...":"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(he,{className:"w-4 h-4 mr-2"}),l==="pending"?"Submit for review":"Save Changes"]})})]})]})})}function sn({open:t,onOpenChange:s,paperId:a,arxivId:c,initialProjectPages:n,onSuccess:o,submitMode:l="direct",isAuthor:m=!1}){const[r,h]=i.useState(n),[y,k]=i.useState(""),P=je(),{toast:E}=ye(),v=i.useRef(!1);i.useEffect(()=>{if(!t){v.current=!1;return}v.current||(v.current=!0,h(n),k(""))},[t,n]);const $=Se({mutationFn:async({paperId:f,projectPages:x})=>l==="pending"?(await De({paper_id:parseInt(f),edit_type:"project_pages",proposed_payload:{project_pages:x}}),null):Fr(f,x),onSuccess:f=>{if(l==="pending"){E({title:"Edit submitted for review",description:"Thanks! An admin will review your proposed project page changes shortly."}),o==null||o(),s(!1),k("");return}f&&Ge(P,f,[a,c]),o==null||o(),s(!1),k("")},onError:f=>{var B;const x=f;let M=x.message||(l==="pending"?"Failed to submit your edit. Please try again.":"Failed to update project pages.");if(x.response)try{const O=JSON.parse(x.response);typeof(O==null?void 0:O.detail)=="string"?M=O.detail:Array.isArray(O==null?void 0:O.detail)&&((B=O.detail[0])!=null&&B.msg)&&(M=O.detail[0].msg)}catch{M=x.response}E({title:l==="pending"?"Could not submit edit":"Could not save project pages",description:M,variant:"destructive"})}}),U=()=>{const f=y.trim();return f?r.some(x=>x.url===f)?(alert("This project page URL is already added"),null):[...r,{url:f,is_official:!1}]:r},T=()=>{const f=U();f!==null&&f.length!==r.length&&(h(f),k(""))},L=f=>{h(r.filter(x=>x.url!==f))},q=f=>{h(r.map(x=>x.url===f?{...x,is_official:!x.is_official}:x))},D=()=>{const f=U();f!==null&&$.mutate({paperId:a,projectPages:f})},C=i.useMemo(()=>{const f=y.trim(),x=f?[...r,{url:f,is_official:!1}]:r;if(x.length!==n.length)return!0;const M=new Map(n.map(B=>[B.url.trim(),!!B.is_official]));return x.some(B=>{const O=M.get(B.url.trim());return O===void 0||O!==!!B.is_official})},[r,y,n]);return e.jsx(ke,{open:t,onOpenChange:s,children:e.jsxs(_e,{className:"max-w-2xl max-h-[600px]",children:[e.jsxs(we,{children:[e.jsx(Ne,{children:"Edit Paper Project Pages"}),e.jsx(Ce,{children:"Add or remove project page URLs (e.g. authors' demo or landing pages) associated with this paper. Mark pages as official if they are created by the paper authors."})]}),l==="pending"&&e.jsx(Ue,{isAuthor:m}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Add Project Page URL"}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(oe,{type:"url",placeholder:"https://example.com/project",value:y,onChange:f=>k(f.target.value),onKeyPress:f=>{f.key==="Enter"&&(f.preventDefault(),T())},className:"flex-1"}),e.jsxs(K,{onClick:T,size:"sm",disabled:!y.trim(),children:[e.jsx(At,{className:"w-4 h-4 mr-1"}),"Add"]})]})]}),e.jsx("div",{className:"py-4 overflow-y-auto max-h-[350px]",children:r.length>0?e.jsx("div",{className:"space-y-2",children:r.map((f,x)=>e.jsxs("div",{className:"flex items-center space-x-2 p-3 bg-muted/30 rounded-lg hover:bg-muted/50 transition-colors",children:[e.jsx(ds,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("span",{className:"text-sm font-medium text-paper-blue truncate",children:f.url}),f.is_official&&e.jsx(Rs,{variant:"secondary",className:"text-xs",children:"Official"})]})}),e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsxs(K,{variant:f.is_official?"default":"outline",size:"sm",onClick:()=>q(f.url),className:"h-8 px-2 text-xs",title:f.is_official?"Click to unmark as official (created by paper authors)":"Click to mark as official (created by paper authors)",children:[e.jsx(Is,{className:`w-3.5 h-3.5 mr-1 ${f.is_official?"fill-current":""}`}),f.is_official?"Official":"Mark official"]}),e.jsx(K,{variant:"ghost",size:"sm",onClick:()=>L(f.url),className:"h-8 px-2 text-destructive hover:text-destructive",title:"Remove project page",children:e.jsx(Ft,{className:"w-4 h-4"})})]})]},x))}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(ds,{className:"w-8 h-8 mx-auto mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No project pages added yet"}),e.jsx("p",{className:"text-xs mt-1",children:"Add a project page URL above to get started"})]})}),e.jsxs(Ee,{children:[e.jsx(K,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(K,{onClick:D,disabled:$.isPending||!C,children:$.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"w-4 h-4 mr-2 animate-spin"}),l==="pending"?"Submitting...":"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(he,{className:"w-4 h-4 mr-2"}),l==="pending"?"Submit for review":"Save Changes"]})})]})]})})}function rn({open:t,onOpenChange:s,paperId:a,arxivId:c,initialUrl:n,onSuccess:o,submitMode:l="direct",isAuthor:m=!1}){const[r,h]=i.useState(n),y=je(),{toast:k}=ye(),P=i.useRef(!1);i.useEffect(()=>{if(!t){P.current=!1;return}P.current||(P.current=!0,h(n))},[t,n]);const E=Se({mutationFn:async({paperId:L,sourceUrl:q})=>l==="pending"?(await De({paper_id:parseInt(L),edit_type:"source_url",proposed_payload:{source_url:q}}),null):$r(L,q),onSuccess:L=>{if(l==="pending"){k({title:"Edit submitted for review",description:"Thanks! An admin will review your proposed source URL change shortly."}),o==null||o(),s(!1);return}L&&Ge(y,L,[a,c]),o==null||o(),s(!1)},onError:L=>{var C;const q=L;let D=q.message||(l==="pending"?"Failed to submit your edit. Please try again.":"Failed to update source URL.");if(q.response)try{const f=JSON.parse(q.response);typeof(f==null?void 0:f.detail)=="string"?D=f.detail:Array.isArray(f==null?void 0:f.detail)&&((C=f.detail[0])!=null&&C.msg)&&(D=f.detail[0].msg)}catch{D=q.response}k({title:l==="pending"?"Could not submit edit":"Could not save source URL",description:D,variant:"destructive"})}}),v=r.trim(),$=/^https?:\/\//i.test(v),U=v!==(n||"").trim(),T=()=>{$&&E.mutate({paperId:a,sourceUrl:v})};return e.jsx(ke,{open:t,onOpenChange:s,children:e.jsxs(_e,{className:"max-w-2xl",children:[e.jsxs(we,{children:[e.jsx(Ne,{children:"Edit Source URL"}),e.jsxs(Ce,{children:["Update the canonical URL for this external paper. This is the page the ",'"Source page"'," button links to. ArXiv papers cannot edit this field."]})]}),l==="pending"&&e.jsx(Ue,{isAuthor:m}),e.jsxs("div",{className:"space-y-2 py-2",children:[e.jsx("label",{className:"text-sm font-medium",children:"Source URL"}),e.jsx(oe,{type:"url",placeholder:"https://example.com/paper",value:r,onChange:L=>h(L.target.value),onKeyPress:L=>{L.key==="Enter"&&$&&U&&(L.preventDefault(),T())}}),!$&&v.length>0&&e.jsx("p",{className:"text-xs text-destructive",children:"URL must start with http:// or https://"})]}),e.jsxs(Ee,{children:[e.jsx(K,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(K,{onClick:T,disabled:E.isPending||!$||!U,children:E.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"w-4 h-4 mr-2 animate-spin"}),l==="pending"?"Submitting...":"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(he,{className:"w-4 h-4 mr-2"}),l==="pending"?"Submit for review":"Save Changes"]})})]})]})})}function an(t){const s=nn(t),a=i.forwardRef((c,n)=>{const{children:o,...l}=c,m=i.Children.toArray(o),r=m.find(ln);if(r){const h=r.props.children,y=m.map(k=>k===r?i.Children.count(h)>1?i.Children.only(null):i.isValidElement(h)?h.props.children:null:k);return e.jsx(s,{...l,ref:n,children:i.isValidElement(h)?i.cloneElement(h,void 0,y):null})}return e.jsx(s,{...l,ref:n,children:o})});return a.displayName=`${t}.Slot`,a}function nn(t){const s=i.forwardRef((a,c)=>{const{children:n,...o}=a;if(i.isValidElement(n)){const l=dn(n),m=cn(o,n.props);return n.type!==i.Fragment&&(m.ref=c?Le(c,l):l),i.cloneElement(n,m)}return i.Children.count(n)>1?i.Children.only(null):null});return s.displayName=`${t}.SlotClone`,s}var on=Symbol("radix.slottable");function ln(t){return i.isValidElement(t)&&typeof t.type=="function"&&"__radixId"in t.type&&t.type.__radixId===on}function cn(t,s){const a={...s};for(const c in s){const n=t[c],o=s[c];/^on[A-Z]/.test(c)?n&&o?a[c]=(...m)=>{const r=o(...m);return n(...m),r}:n&&(a[c]=n):c==="style"?a[c]={...n,...o}:c==="className"&&(a[c]=[n,o].filter(Boolean).join(" "))}return{...t,...a}}function dn(t){var c,n;let s=(c=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:c.get,a=s&&"isReactWarning"in s&&s.isReactWarning;return a?t.ref:(s=(n=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:n.get,a=s&&"isReactWarning"in s&&s.isReactWarning,a?t.props.ref:t.props.ref||t.ref)}var ut="Popover",[qs]=_s(ut,[Es]),We=Es(),[un,fe]=qs(ut),Bs=t=>{const{__scopePopover:s,children:a,open:c,defaultOpen:n,onOpenChange:o,modal:l=!1}=t,m=We(s),r=i.useRef(null),[h,y]=i.useState(!1),[k,P]=ks({prop:c,defaultProp:n??!1,onChange:o,caller:ut});return e.jsx(Tr,{...m,children:e.jsx(un,{scope:s,contentId:ve(),triggerRef:r,open:k,onOpenChange:P,onOpenToggle:i.useCallback(()=>P(E=>!E),[P]),hasCustomAnchor:h,onCustomAnchorAdd:i.useCallback(()=>y(!0),[]),onCustomAnchorRemove:i.useCallback(()=>y(!1),[]),modal:l,children:a})})};Bs.displayName=ut;var Os="PopoverAnchor",mn=i.forwardRef((t,s)=>{const{__scopePopover:a,...c}=t,n=fe(Os,a),o=We(a),{onCustomAnchorAdd:l,onCustomAnchorRemove:m}=n;return i.useEffect(()=>(l(),()=>m()),[l,m]),e.jsx(Cs,{...o,...c,ref:s})});mn.displayName=Os;var Hs="PopoverTrigger",Ks=i.forwardRef((t,s)=>{const{__scopePopover:a,...c}=t,n=fe(Hs,a),o=We(a),l=lt(s,n.triggerRef),m=e.jsx(se.button,{type:"button","aria-haspopup":"dialog","aria-expanded":n.open,"aria-controls":n.contentId,"data-state":Ws(n.open),...c,ref:l,onClick:xe(t.onClick,n.onOpenToggle)});return n.hasCustomAnchor?m:e.jsx(Cs,{asChild:!0,...o,children:m})});Ks.displayName=Hs;var Mt="PopoverPortal",[pn,hn]=qs(Mt,{forceMount:void 0}),zs=t=>{const{__scopePopover:s,forceMount:a,children:c,container:n}=t,o=fe(Mt,s);return e.jsx(pn,{scope:s,forceMount:a,children:e.jsx(Pt,{present:a||o.open,children:e.jsx(Lr,{asChild:!0,container:n,children:c})})})};zs.displayName=Mt;var Me="PopoverContent",Qs=i.forwardRef((t,s)=>{const a=hn(Me,t.__scopePopover),{forceMount:c=a.forceMount,...n}=t,o=fe(Me,t.__scopePopover);return e.jsx(Pt,{present:c||o.open,children:o.modal?e.jsx(gn,{...n,ref:s}):e.jsx(xn,{...n,ref:s})})});Qs.displayName=Me;var fn=an("PopoverContent.RemoveScroll"),gn=i.forwardRef((t,s)=>{const a=fe(Me,t.__scopePopover),c=i.useRef(null),n=lt(s,c),o=i.useRef(!1);return i.useEffect(()=>{const l=c.current;if(l)return Mr(l)},[]),e.jsx(Dr,{as:fn,allowPinchZoom:!0,children:e.jsx(Vs,{...t,ref:n,trapFocus:a.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:xe(t.onCloseAutoFocus,l=>{var m;l.preventDefault(),o.current||(m=a.triggerRef.current)==null||m.focus()}),onPointerDownOutside:xe(t.onPointerDownOutside,l=>{const m=l.detail.originalEvent,r=m.button===0&&m.ctrlKey===!0,h=m.button===2||r;o.current=h},{checkForDefaultPrevented:!1}),onFocusOutside:xe(t.onFocusOutside,l=>l.preventDefault(),{checkForDefaultPrevented:!1})})})}),xn=i.forwardRef((t,s)=>{const a=fe(Me,t.__scopePopover),c=i.useRef(!1),n=i.useRef(!1);return e.jsx(Vs,{...t,ref:s,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{var l,m;(l=t.onCloseAutoFocus)==null||l.call(t,o),o.defaultPrevented||(c.current||(m=a.triggerRef.current)==null||m.focus(),o.preventDefault()),c.current=!1,n.current=!1},onInteractOutside:o=>{var r,h;(r=t.onInteractOutside)==null||r.call(t,o),o.defaultPrevented||(c.current=!0,o.detail.originalEvent.type==="pointerdown"&&(n.current=!0));const l=o.target;((h=a.triggerRef.current)==null?void 0:h.contains(l))&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&n.current&&o.preventDefault()}})}),Vs=i.forwardRef((t,s)=>{const{__scopePopover:a,trapFocus:c,onOpenAutoFocus:n,onCloseAutoFocus:o,disableOutsidePointerEvents:l,onEscapeKeyDown:m,onPointerDownOutside:r,onFocusOutside:h,onInteractOutside:y,...k}=t,P=fe(Me,a),E=We(a);return Ur(),e.jsx(qr,{asChild:!0,loop:!0,trapped:c,onMountAutoFocus:n,onUnmountAutoFocus:o,children:e.jsx(Br,{asChild:!0,disableOutsidePointerEvents:l,onInteractOutside:y,onEscapeKeyDown:m,onPointerDownOutside:r,onFocusOutside:h,onDismiss:()=>P.onOpenChange(!1),children:e.jsx(Or,{"data-state":Ws(P.open),role:"dialog",id:P.contentId,...E,...k,ref:s,style:{...k.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),Gs="PopoverClose",vn=i.forwardRef((t,s)=>{const{__scopePopover:a,...c}=t,n=fe(Gs,a);return e.jsx(se.button,{type:"button",...c,ref:s,onClick:xe(t.onClick,()=>n.onOpenChange(!1))})});vn.displayName=Gs;var bn="PopoverArrow",jn=i.forwardRef((t,s)=>{const{__scopePopover:a,...c}=t,n=We(a);return e.jsx(Hr,{...n,...c,ref:s})});jn.displayName=bn;function Ws(t){return t?"open":"closed"}var yn=Bs,kn=Ks,_n=zs,Js=Qs;const wn=yn,Nn=kn,Xs=i.forwardRef(({className:t,align:s="center",sideOffset:a=4,...c},n)=>e.jsx(_n,{children:e.jsx(Js,{ref:n,align:s,sideOffset:a,className:ae("z-50 w-72 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",t),...c})}));Xs.displayName=Js.displayName;var ms=1,Cn=.9,En=.8,Sn=.17,bt=.1,jt=.999,Pn=.9999,Rn=.99,In=/[\\\/_+.#"@\[\(\{&]/,An=/[\\\/_+.#"@\[\(\{&]/g,Fn=/[\s-]/,Ys=/[\s-]/g;function Et(t,s,a,c,n,o,l){if(o===s.length)return n===t.length?ms:Rn;var m=`${n},${o}`;if(l[m]!==void 0)return l[m];for(var r=c.charAt(o),h=a.indexOf(r,n),y=0,k,P,E,v;h>=0;)k=Et(t,s,a,c,h+1,o+1,l),k>y&&(h===n?k*=ms:In.test(t.charAt(h-1))?(k*=En,E=t.slice(n,h-1).match(An),E&&n>0&&(k*=Math.pow(jt,E.length))):Fn.test(t.charAt(h-1))?(k*=Cn,v=t.slice(n,h-1).match(Ys),v&&n>0&&(k*=Math.pow(jt,v.length))):(k*=Sn,n>0&&(k*=Math.pow(jt,h-n))),t.charAt(h)!==s.charAt(o)&&(k*=Pn)),(kk&&(k=P*bt)),k>y&&(y=k),h=a.indexOf(r,h+1);return l[m]=y,y}function ps(t){return t.toLowerCase().replace(Ys," ")}function $n(t,s,a){return t=a&&a.length>0?`${t+" "+a.join(" ")}`:t,Et(t,s,ps(t),ps(s),0,0,{})}var Oe='[cmdk-group=""]',yt='[cmdk-group-items=""]',Tn='[cmdk-group-heading=""]',Zs='[cmdk-item=""]',hs=`${Zs}:not([aria-disabled="true"])`,St="cmdk-item-select",Fe="data-value",Ln=(t,s,a)=>$n(t,s,a),er=i.createContext(void 0),Je=()=>i.useContext(er),tr=i.createContext(void 0),Dt=()=>i.useContext(tr),sr=i.createContext(void 0),rr=i.forwardRef((t,s)=>{let a=$e(()=>{var u,p;return{search:"",value:(p=(u=t.value)!=null?u:t.defaultValue)!=null?p:"",selectedItemId:void 0,filtered:{count:0,items:new Map,groups:new Set}}}),c=$e(()=>new Set),n=$e(()=>new Map),o=$e(()=>new Map),l=$e(()=>new Set),m=ar(t),{label:r,children:h,value:y,onValueChange:k,filter:P,shouldFilter:E,loop:v,disablePointerSelection:$=!1,vimBindings:U=!0,...T}=t,L=ve(),q=ve(),D=ve(),C=i.useRef(null),f=Vn();be(()=>{if(y!==void 0){let u=y.trim();a.current.value=u,x.emit()}},[y]),be(()=>{f(6,ee)},[]);let x=i.useMemo(()=>({subscribe:u=>(l.current.add(u),()=>l.current.delete(u)),snapshot:()=>a.current,setState:(u,p,g)=>{var w,S,H,G;if(!Object.is(a.current[u],p)){if(a.current[u]=p,u==="search")V(),O(),f(1,z);else if(u==="value"){if(document.activeElement.hasAttribute("cmdk-input")||document.activeElement.hasAttribute("cmdk-root")){let W=document.getElementById(D);W?W.focus():(w=document.getElementById(L))==null||w.focus()}if(f(7,()=>{var W;a.current.selectedItemId=(W=b())==null?void 0:W.id,x.emit()}),g||f(5,ee),((S=m.current)==null?void 0:S.value)!==void 0){let W=p??"";(G=(H=m.current).onValueChange)==null||G.call(H,W);return}}x.emit()}},emit:()=>{l.current.forEach(u=>u())}}),[]),M=i.useMemo(()=>({value:(u,p,g)=>{var w;p!==((w=o.current.get(u))==null?void 0:w.value)&&(o.current.set(u,{value:p,keywords:g}),a.current.filtered.items.set(u,B(p,g)),f(2,()=>{O(),x.emit()}))},item:(u,p)=>(c.current.add(u),p&&(n.current.has(p)?n.current.get(p).add(u):n.current.set(p,new Set([u]))),f(3,()=>{V(),O(),a.current.value||z(),x.emit()}),()=>{o.current.delete(u),c.current.delete(u),a.current.filtered.items.delete(u);let g=b();f(4,()=>{V(),(g==null?void 0:g.getAttribute("id"))===u&&z(),x.emit()})}),group:u=>(n.current.has(u)||n.current.set(u,new Set),()=>{o.current.delete(u),n.current.delete(u)}),filter:()=>m.current.shouldFilter,label:r||t["aria-label"],getDisablePointerSelection:()=>m.current.disablePointerSelection,listId:L,inputId:D,labelId:q,listInnerRef:C}),[]);function B(u,p){var g,w;let S=(w=(g=m.current)==null?void 0:g.filter)!=null?w:Ln;return u?S(u,a.current.search,p):0}function O(){if(!a.current.search||m.current.shouldFilter===!1)return;let u=a.current.filtered.items,p=[];a.current.filtered.groups.forEach(w=>{let S=n.current.get(w),H=0;S.forEach(G=>{let W=u.get(G);H=Math.max(W,H)}),p.push([w,H])});let g=C.current;R().sort((w,S)=>{var H,G;let W=w.getAttribute("id"),de=S.getAttribute("id");return((H=u.get(de))!=null?H:0)-((G=u.get(W))!=null?G:0)}).forEach(w=>{let S=w.closest(yt);S?S.appendChild(w.parentElement===S?w:w.closest(`${yt} > *`)):g.appendChild(w.parentElement===g?w:w.closest(`${yt} > *`))}),p.sort((w,S)=>S[1]-w[1]).forEach(w=>{var S;let H=(S=C.current)==null?void 0:S.querySelector(`${Oe}[${Fe}="${encodeURIComponent(w[0])}"]`);H==null||H.parentElement.appendChild(H)})}function z(){let u=R().find(g=>g.getAttribute("aria-disabled")!=="true"),p=u==null?void 0:u.getAttribute(Fe);x.setState("value",p||void 0)}function V(){var u,p,g,w;if(!a.current.search||m.current.shouldFilter===!1){a.current.filtered.count=c.current.size;return}a.current.filtered.groups=new Set;let S=0;for(let H of c.current){let G=(p=(u=o.current.get(H))==null?void 0:u.value)!=null?p:"",W=(w=(g=o.current.get(H))==null?void 0:g.keywords)!=null?w:[],de=B(G,W);a.current.filtered.items.set(H,de),de>0&&S++}for(let[H,G]of n.current)for(let W of G)if(a.current.filtered.items.get(W)>0){a.current.filtered.groups.add(H);break}a.current.filtered.count=S}function ee(){var u,p,g;let w=b();w&&(((u=w.parentElement)==null?void 0:u.firstChild)===w&&((g=(p=w.closest(Oe))==null?void 0:p.querySelector(Tn))==null||g.scrollIntoView({block:"nearest"})),w.scrollIntoView({block:"nearest"}))}function b(){var u;return(u=C.current)==null?void 0:u.querySelector(`${Zs}[aria-selected="true"]`)}function R(){var u;return Array.from(((u=C.current)==null?void 0:u.querySelectorAll(hs))||[])}function F(u){let p=R()[u];p&&x.setState("value",p.getAttribute(Fe))}function A(u){var p;let g=b(),w=R(),S=w.findIndex(G=>G===g),H=w[S+u];(p=m.current)!=null&&p.loop&&(H=S+u<0?w[w.length-1]:S+u===w.length?w[0]:w[S+u]),H&&x.setState("value",H.getAttribute(Fe))}function I(u){let p=b(),g=p==null?void 0:p.closest(Oe),w;for(;g&&!w;)g=u>0?zn(g,Oe):Qn(g,Oe),w=g==null?void 0:g.querySelector(hs);w?x.setState("value",w.getAttribute(Fe)):A(u)}let Y=()=>F(R().length-1),j=u=>{u.preventDefault(),u.metaKey?Y():u.altKey?I(1):A(1)},_=u=>{u.preventDefault(),u.metaKey?F(0):u.altKey?I(-1):A(-1)};return i.createElement(se.div,{ref:s,tabIndex:-1,...T,"cmdk-root":"",onKeyDown:u=>{var p;(p=T.onKeyDown)==null||p.call(T,u);let g=u.nativeEvent.isComposing||u.keyCode===229;if(!(u.defaultPrevented||g))switch(u.key){case"n":case"j":{U&&u.ctrlKey&&j(u);break}case"ArrowDown":{j(u);break}case"p":case"k":{U&&u.ctrlKey&&_(u);break}case"ArrowUp":{_(u);break}case"Home":{u.preventDefault(),F(0);break}case"End":{u.preventDefault(),Y();break}case"Enter":{u.preventDefault();let w=b();if(w){let S=new Event(St);w.dispatchEvent(S)}}}}},i.createElement("label",{"cmdk-label":"",htmlFor:M.inputId,id:M.labelId,style:Wn},r),mt(t,u=>i.createElement(tr.Provider,{value:x},i.createElement(er.Provider,{value:M},u))))}),Mn=i.forwardRef((t,s)=>{var a,c;let n=ve(),o=i.useRef(null),l=i.useContext(sr),m=Je(),r=ar(t),h=(c=(a=r.current)==null?void 0:a.forceMount)!=null?c:l==null?void 0:l.forceMount;be(()=>{if(!h)return m.item(n,l==null?void 0:l.id)},[h]);let y=nr(n,o,[t.value,t.children,o],t.keywords),k=Dt(),P=pe(f=>f.value&&f.value===y.current),E=pe(f=>h||m.filter()===!1?!0:f.search?f.filtered.items.get(n)>0:!0);i.useEffect(()=>{let f=o.current;if(!(!f||t.disabled))return f.addEventListener(St,v),()=>f.removeEventListener(St,v)},[E,t.onSelect,t.disabled]);function v(){var f,x;$(),(x=(f=r.current).onSelect)==null||x.call(f,y.current)}function $(){k.setState("value",y.current,!0)}if(!E)return null;let{disabled:U,value:T,onSelect:L,forceMount:q,keywords:D,...C}=t;return i.createElement(se.div,{ref:Le(o,s),...C,id:n,"cmdk-item":"",role:"option","aria-disabled":!!U,"aria-selected":!!P,"data-disabled":!!U,"data-selected":!!P,onPointerMove:U||m.getDisablePointerSelection()?void 0:$,onClick:U?void 0:v},t.children)}),Dn=i.forwardRef((t,s)=>{let{heading:a,children:c,forceMount:n,...o}=t,l=ve(),m=i.useRef(null),r=i.useRef(null),h=ve(),y=Je(),k=pe(E=>n||y.filter()===!1?!0:E.search?E.filtered.groups.has(l):!0);be(()=>y.group(l),[]),nr(l,m,[t.value,t.heading,r]);let P=i.useMemo(()=>({id:l,forceMount:n}),[n]);return i.createElement(se.div,{ref:Le(m,s),...o,"cmdk-group":"",role:"presentation",hidden:k?void 0:!0},a&&i.createElement("div",{ref:r,"cmdk-group-heading":"","aria-hidden":!0,id:h},a),mt(t,E=>i.createElement("div",{"cmdk-group-items":"",role:"group","aria-labelledby":a?h:void 0},i.createElement(sr.Provider,{value:P},E))))}),Un=i.forwardRef((t,s)=>{let{alwaysRender:a,...c}=t,n=i.useRef(null),o=pe(l=>!l.search);return!a&&!o?null:i.createElement(se.div,{ref:Le(n,s),...c,"cmdk-separator":"",role:"separator"})}),qn=i.forwardRef((t,s)=>{let{onValueChange:a,...c}=t,n=t.value!=null,o=Dt(),l=pe(h=>h.search),m=pe(h=>h.selectedItemId),r=Je();return i.useEffect(()=>{t.value!=null&&o.setState("search",t.value)},[t.value]),i.createElement(se.input,{ref:s,...c,"cmdk-input":"",autoComplete:"off",autoCorrect:"off",spellCheck:!1,"aria-autocomplete":"list",role:"combobox","aria-expanded":!0,"aria-controls":r.listId,"aria-labelledby":r.labelId,"aria-activedescendant":m,id:r.inputId,type:"text",value:n?t.value:l,onChange:h=>{n||o.setState("search",h.target.value),a==null||a(h.target.value)}})}),Bn=i.forwardRef((t,s)=>{let{children:a,label:c="Suggestions",...n}=t,o=i.useRef(null),l=i.useRef(null),m=pe(h=>h.selectedItemId),r=Je();return i.useEffect(()=>{if(l.current&&o.current){let h=l.current,y=o.current,k,P=new ResizeObserver(()=>{k=requestAnimationFrame(()=>{let E=h.offsetHeight;y.style.setProperty("--cmdk-list-height",E.toFixed(1)+"px")})});return P.observe(h),()=>{cancelAnimationFrame(k),P.unobserve(h)}}},[]),i.createElement(se.div,{ref:Le(o,s),...n,"cmdk-list":"",role:"listbox",tabIndex:-1,"aria-activedescendant":m,"aria-label":c,id:r.listId},mt(t,h=>i.createElement("div",{ref:Le(l,r.listInnerRef),"cmdk-list-sizer":""},h)))}),On=i.forwardRef((t,s)=>{let{open:a,onOpenChange:c,overlayClassName:n,contentClassName:o,container:l,...m}=t;return i.createElement(ba,{open:a,onOpenChange:c},i.createElement(ja,{container:l},i.createElement(ya,{"cmdk-overlay":"",className:n}),i.createElement(ka,{"aria-label":t.label,"cmdk-dialog":"",className:o},i.createElement(rr,{ref:s,...m}))))}),Hn=i.forwardRef((t,s)=>pe(a=>a.filtered.count===0)?i.createElement(se.div,{ref:s,...t,"cmdk-empty":"",role:"presentation"}):null),Kn=i.forwardRef((t,s)=>{let{progress:a,children:c,label:n="Loading...",...o}=t;return i.createElement(se.div,{ref:s,...o,"cmdk-loading":"",role:"progressbar","aria-valuenow":a,"aria-valuemin":0,"aria-valuemax":100,"aria-label":n},mt(t,l=>i.createElement("div",{"aria-hidden":!0},l)))}),Z=Object.assign(rr,{List:Bn,Item:Mn,Input:qn,Group:Dn,Separator:Un,Dialog:On,Empty:Hn,Loading:Kn});function zn(t,s){let a=t.nextElementSibling;for(;a;){if(a.matches(s))return a;a=a.nextElementSibling}}function Qn(t,s){let a=t.previousElementSibling;for(;a;){if(a.matches(s))return a;a=a.previousElementSibling}}function ar(t){let s=i.useRef(t);return be(()=>{s.current=t}),s}var be=typeof window>"u"?i.useEffect:i.useLayoutEffect;function $e(t){let s=i.useRef();return s.current===void 0&&(s.current=t()),s}function pe(t){let s=Dt(),a=()=>t(s.snapshot());return i.useSyncExternalStore(s.subscribe,a,a)}function nr(t,s,a,c=[]){let n=i.useRef(),o=Je();return be(()=>{var l;let m=(()=>{var h;for(let y of a){if(typeof y=="string")return y.trim();if(typeof y=="object"&&"current"in y)return y.current?(h=y.current.textContent)==null?void 0:h.trim():n.current}})(),r=c.map(h=>h.trim());o.value(t,m,r),(l=s.current)==null||l.setAttribute(Fe,m),n.current=m}),n}var Vn=()=>{let[t,s]=i.useState(),a=$e(()=>new Map);return be(()=>{a.current.forEach(c=>c()),a.current=new Map},[t]),(c,n)=>{a.current.set(c,n),s({})}};function Gn(t){let s=t.type;return typeof s=="function"?s(t.props):"render"in s?s.render(t.props):t}function mt({asChild:t,children:s},a){return t&&i.isValidElement(s)?i.cloneElement(Gn(s),{ref:s.ref},a(s.props.children)):a(s)}var Wn={position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",borderWidth:"0"};const ir=i.forwardRef(({className:t,...s},a)=>e.jsx(Z,{ref:a,className:ae("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",t),...s}));ir.displayName=Z.displayName;const or=i.forwardRef(({className:t,...s},a)=>e.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[e.jsx(Qe,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(Z.Input,{ref:a,className:ae("flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",t),...s})]}));or.displayName=Z.Input.displayName;const lr=i.forwardRef(({className:t,...s},a)=>e.jsx(Z.List,{ref:a,className:ae("max-h-[300px] overflow-y-auto overflow-x-hidden",t),...s}));lr.displayName=Z.List.displayName;const cr=i.forwardRef((t,s)=>e.jsx(Z.Empty,{ref:s,className:"py-6 text-center text-sm",...t}));cr.displayName=Z.Empty.displayName;const dr=i.forwardRef(({className:t,...s},a)=>e.jsx(Z.Group,{ref:a,className:ae("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",t),...s}));dr.displayName=Z.Group.displayName;const Jn=i.forwardRef(({className:t,...s},a)=>e.jsx(Z.Separator,{ref:a,className:ae("-mx-1 h-px bg-border",t),...s}));Jn.displayName=Z.Separator.displayName;const ur=i.forwardRef(({className:t,...s},a)=>e.jsx(Z.Item,{ref:a,className:ae("relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected='true']:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50",t),...s}));ur.displayName=Z.Item.displayName;const Xn=250;function fs({value:t,onChange:s,placeholder:a="Select...",searchPlaceholder:c="Search...",emptyMessage:n="No results found.",disabled:o=!1,selectedOption:l,queryKey:m,queryFn:r,enabled:h=!0,className:y}){const[k,P]=i.useState(!1),[E,v]=i.useState(""),[$,U]=i.useState("");i.useEffect(()=>{const C=window.setTimeout(()=>{U(E.trim())},Xn);return()=>window.clearTimeout(C)},[E]),i.useEffect(()=>{k||(v(""),U(""))},[k]);const{data:T=[],isFetching:L}=le({queryKey:[...m,$],queryFn:()=>r($),enabled:h&&k}),q=i.useMemo(()=>!t||T.some(C=>C.value===t)?T:(l==null?void 0:l.value)===t?[l,...T]:T,[T,l,t]),D=i.useMemo(()=>{if(!t)return a;const C=q.find(f=>f.value===t)??((l==null?void 0:l.value)===t?l:null);return(C==null?void 0:C.label)??a},[q,a,l,t]);return e.jsxs(wn,{open:k,onOpenChange:P,modal:!0,children:[e.jsx(Nn,{asChild:!0,children:e.jsxs(K,{type:"button",variant:"outline",role:"combobox","aria-expanded":k,disabled:o,className:ae("h-8 w-full justify-between px-2 text-sm font-normal",!t&&"text-muted-foreground",y),children:[e.jsx("span",{className:"truncate",children:D}),e.jsx(Ta,{className:"ml-1 h-3.5 w-3.5 shrink-0 opacity-50"})]})}),e.jsx(Xs,{className:"z-[60] w-[var(--radix-popover-trigger-width)] max-h-[var(--radix-popover-content-available-height)] overflow-hidden p-0",align:"start",collisionPadding:8,onWheel:C=>C.stopPropagation(),children:e.jsxs(ir,{shouldFilter:!1,className:"h-full",children:[e.jsx(or,{placeholder:c,value:E,onValueChange:v}),e.jsx(lr,{className:"max-h-[min(300px,calc(var(--radix-popover-content-available-height)-2.75rem))] min-h-0 overscroll-contain",children:L?e.jsxs("div",{className:"flex items-center justify-center py-6 text-sm text-muted-foreground",children:[e.jsx(ce,{className:"mr-2 h-4 w-4 animate-spin"}),"Loading..."]}):q.length===0?e.jsx(cr,{children:n}):e.jsx(dr,{children:q.map(C=>e.jsxs(ur,{value:C.value,onSelect:()=>{s(C.value),P(!1)},children:[e.jsx(he,{className:ae("mr-2 h-4 w-4",t===C.value?"opacity-100":"opacity-0")}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate",children:C.label}),C.description?e.jsx("div",{className:"truncate text-xs text-muted-foreground",children:C.description}):null]})]},C.value))})})]})})]})}const kt=100;function Yn(t){return(t??[]).some(s=>s.slug==="coding-agents"||s.name.trim().toLowerCase()==="coding agents")}function gs(t){const s=parseInt(t.task_id,10),a=parseInt(t.dataset_id,10);return!(!Number.isFinite(s)||!Number.isFinite(a)||!t.metric_name.trim()||!t.metric_value.trim())}function Zn(t){return t.map(s=>{const a=s.best_metric||Object.keys(s.metrics)[0],c=s.metrics[a];return{id:s.id,task_id:s.task_id,dataset_id:s.dataset_id,model_name:s.model_name||"",harness:s.harness||"",metric_name:a||"",metric_value:String(c||""),best_rank:s.best_rank?String(s.best_rank):"",num_parameters:s.num_parameters!=null?String(s.num_parameters):"",hf_model_url:s.hf_model_url||"",is_open:s.is_open!==!1,operation:"unchanged"}})}function ei(t){const s=new Map;return t.forEach(a=>{a.task_id&&a.task_name&&s.set(a.task_id,{id:a.task_id,name:a.task_name,slug:a.task_slug,level:0})}),s}function ti(t){const s=new Map;return t.forEach(a=>{a.dataset_id&&a.dataset_name&&s.set(a.dataset_id,{id:a.dataset_id,name:a.dataset_name,slug:a.dataset_slug})}),s}function xs(t,s){return`${t}:${s}`}function rt(t){const s=t.trim();if(s==="")return null;const a=Number(s);return!Number.isFinite(a)||a<0?null:Math.trunc(a)}function at(t){const s=t.trim();return s===""?null:s}function si({open:t,onOpenChange:s,paperId:a,arxivId:c,initialEvaluations:n,paperTasks:o,onSuccess:l,submitMode:m="direct",isAuthor:r=!1}){const h=Yn(o),[y,k]=i.useState([]),[P,E]=i.useState(null),[v,$]=i.useState(new Map),[U,T]=i.useState(new Map),L=je(),{toast:q}=ye(),D=i.useRef(!1),C=i.useRef(!1);i.useEffect(()=>{if(!t){D.current=!1,C.current=!1;return}D.current||C.current||n.length!==0&&(D.current=!0,k(Zn(n)),$(ei(n)),T(ti(n)))},[t,n]);const f=i.useMemo(()=>Array.from(new Set(y.map(j=>j.task_id).filter(j=>j&&j!==""))),[y]),x=i.useMemo(()=>{const j=new Set;return y.forEach(_=>{_.task_id&&_.dataset_id&&j.add(xs(_.task_id,_.dataset_id))}),Array.from(j)},[y]),M=le({queryKey:["datasets-by-tasks-for-eval-edit",f,t],queryFn:async()=>{const j={};return await Promise.all(f.map(async _=>{try{const u=await ls({task_id:parseInt(_),page_size:kt});j[_]=u.results}catch(u){console.error(`Error fetching datasets for task ${_}:`,u),j[_]=[]}})),j},enabled:t&&f.length>0});i.useEffect(()=>{M.data&&T(j=>{const _=new Map(j);return Object.values(M.data).forEach(u=>{u.forEach(p=>{_.set(p.id,p)})}),_})},[M.data]);const B=le({queryKey:["leaderboard-metrics-for-eval-edit",x,t],queryFn:async()=>{const j={};return await Promise.all(x.map(async _=>{const[u,p]=_.split(":");try{j[_]=await Vr(p,u)}catch(g){console.error(`Error fetching metrics for leaderboard ${_}:`,g),j[_]=[]}})),j},enabled:t&&x.length>0}),O=async j=>{const _=await Ns({page_size:kt,visible_only:!0,...j?{q:j}:{}});return $(u=>{const p=new Map(u);return _.results.forEach(g=>p.set(g.id,g)),p}),_.results.map(u=>{var p;return{value:u.id,label:u.name,description:(p=u.description)==null?void 0:p.slice(0,100)}})},z=j=>async _=>{const u=await ls({task_id:parseInt(j),page_size:kt,..._?{q:_}:{}});return T(p=>{const g=new Map(p);return u.results.forEach(w=>g.set(w.id,w)),g}),u.results.map(p=>({value:p.id,label:p.name,description:p.full_name}))},V=(j,_)=>{if(!j||!_)return!1;const u=U.get(_);return!!(u!=null&&u.supports_harness)},ee=(j,_,u)=>{var w;if(!j||!_)return[];const g=(((w=B.data)==null?void 0:w[xs(j,_)])||[]).map(S=>({value:S.metric_name,label:S.metric_name,description:S.metric_direction==="higher_is_better"?"Higher is better":"Lower is better"}));return u&&!g.some(S=>S.value===u)&&g.unshift({value:u,label:`${u} (legacy)`,description:void 0}),g},b=Se({mutationFn:async({paperId:j,evaluations:_})=>{if(m==="pending"){const p=[];for(const g of _){if(g.operation==="delete"&&g.id){p.push({op:"delete",evaluation_id:parseInt(g.id)});continue}const w=V(g.task_id,g.dataset_id);if(g.operation==="create"){if(!gs(g))continue;const S=rt(g.num_parameters),H={task_id:parseInt(g.task_id),dataset_id:parseInt(g.dataset_id),metrics:{[g.metric_name]:g.metric_value},best_metric:g.metric_name},G=at(g.hf_model_url);g.model_name&&(H.model_name=g.model_name),w&&g.harness&&(H.harness=g.harness),g.best_rank&&(H.best_rank=parseInt(g.best_rank)),S!=null&&(H.num_parameters=S),G!=null&&(H.hf_model_url=G),H.is_open=g.is_open,p.push({op:"create",data:H})}else if(g.operation==="update"&&g.id){const S={task_id:parseInt(g.task_id),dataset_id:parseInt(g.dataset_id),model_name:g.model_name||void 0,harness:w&&g.harness||null,metrics:{[g.metric_name]:g.metric_value},best_metric:g.metric_name,best_rank:g.best_rank?parseInt(g.best_rank):void 0,num_parameters:rt(g.num_parameters),hf_model_url:at(g.hf_model_url),is_open:g.is_open};p.push({op:"update",evaluation_id:parseInt(g.id),data:S})}}return p.length===0?{submitted:!1}:(await De({paper_id:parseInt(j),edit_type:"evaluations",proposed_payload:{operations:p}}),{submitted:!0})}let u=!1;for(const p of _)if(p.operation==="delete"&&p.id){u=!0;try{await Kr(p.id)}catch(g){if((typeof g=="object"&&g!==null&&"status"in g?g.status:void 0)!==404)throw g;console.log(`Evaluation ${p.id} already deleted or not found`)}}else if(p.operation==="create"){if(!gs(p))continue;u=!0;const g=V(p.task_id,p.dataset_id),w=rt(p.num_parameters);await zr({paper_id:parseInt(j),task_id:parseInt(p.task_id),dataset_id:parseInt(p.dataset_id),model_name:p.model_name||void 0,harness:g&&p.harness||void 0,metrics:{[p.metric_name]:p.metric_value},best_metric:p.metric_name,best_rank:p.best_rank?parseInt(p.best_rank):void 0,num_parameters:w??void 0,hf_model_url:at(p.hf_model_url)??void 0,is_open:p.is_open})}else if(p.operation==="update"&&p.id){u=!0;const g=V(p.task_id,p.dataset_id);await Qr(p.id,{task_id:parseInt(p.task_id),dataset_id:parseInt(p.dataset_id),model_name:p.model_name||void 0,harness:g&&p.harness||null,metrics:{[p.metric_name]:p.metric_value},best_metric:p.metric_name,best_rank:p.best_rank?parseInt(p.best_rank):void 0,num_parameters:rt(p.num_parameters),hf_model_url:at(p.hf_model_url),is_open:p.is_open})}return{submitted:u}},onSuccess:j=>{if(m==="pending"){j!=null&&j.submitted?q({title:"Edit submitted for review",description:"Thanks! An admin will review your proposed evaluation changes shortly."}):q({title:"No changes to submit",description:"Your evaluation list matches the existing data."}),l==null||l(),s(!1);return}L.invalidateQueries({queryKey:["paper-arxiv",c]}),L.invalidateQueries({queryKey:["evaluations","paper",a]}),l==null||l(),s(!1)},onError:j=>{var p;const _=j;let u=_.message||(m==="pending"?"Failed to submit your edit. Please try again.":"Failed to update evaluations.");if(_.response)try{const g=JSON.parse(_.response);typeof(g==null?void 0:g.detail)=="string"?u=g.detail:Array.isArray(g==null?void 0:g.detail)&&((p=g.detail[0])!=null&&p.msg)&&(u=g.detail[0].msg)}catch{u=_.response}q({title:m==="pending"?"Could not submit edit":"Could not save evaluations",description:u,variant:"destructive"})}}),R=()=>{C.current=!0,k([...y,{task_id:"",dataset_id:"",model_name:"",harness:"",metric_name:"",metric_value:"",best_rank:"",num_parameters:"",hf_model_url:"",is_open:!0,operation:"create"}])},F=j=>{C.current=!0,y[j].id?k(y.map((u,p)=>p===j?{...u,operation:"delete"}:u)):k(y.filter((u,p)=>p!==j))},A=(j,_,u)=>{C.current=!0,k(y.map((p,g)=>{if(g!==j)return p;const w={...p,[_]:u};return _==="task_id"&&(w.dataset_id="",w.metric_name="",w.harness=""),_==="dataset_id"&&(w.metric_name="",u&&!V(w.task_id,u)&&(w.harness="")),p.operation==="unchanged"&&(w.operation="update"),w}))},I=(j,_)=>{C.current=!0,k(y.map((u,p)=>{if(p!==j)return u;const g={...u,is_open:_};return u.operation==="unchanged"&&(g.operation="update"),g}))},Y=()=>{const j=y.filter(_=>_.operation!=="delete"||_.id);b.mutate({paperId:a,evaluations:j})};return e.jsxs(ke,{open:t,onOpenChange:s,children:[e.jsxs(_e,{className:"max-w-6xl max-h-[800px]",children:[e.jsxs(we,{children:[e.jsx(Ne,{children:"Edit Evaluation Results"}),e.jsx(Ce,{children:"Add, edit, or remove evaluation results for this paper. Each row represents a benchmark result."})]}),m==="pending"&&e.jsx(Ue,{isAuthor:r}),e.jsxs("div",{className:"py-4 overflow-y-auto max-h-[600px]",children:[y.filter(j=>j.operation!=="delete").length>0?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border",children:[e.jsx("th",{className:"text-left py-2 px-2 font-medium text-sm min-w-[180px]",children:"Task"}),e.jsx("th",{className:"text-left py-2 px-2 font-medium text-sm min-w-[180px]",children:"Dataset"}),e.jsx("th",{className:`text-left py-2 px-2 font-medium text-sm ${h?"min-w-[140px]":"min-w-[240px]"}`,children:"Model"}),h&&e.jsx("th",{className:"text-left py-2 px-2 font-medium text-sm min-w-[140px]",children:"Harness"}),e.jsx("th",{className:"text-left py-2 px-2 font-medium text-sm min-w-[140px]",children:"Metric"}),e.jsx("th",{className:"text-left py-2 px-2 font-medium text-sm",children:"Value"}),e.jsx("th",{className:"text-left py-2 px-2 font-medium text-sm",children:"Parameters"}),e.jsx("th",{className:"text-left py-2 px-2 font-medium text-sm min-w-[200px]",children:"HF model URL"}),e.jsx("th",{className:"text-left py-2 px-2 font-medium text-sm w-20",children:"Open source"}),e.jsx("th",{className:"text-left py-2 px-2 font-medium text-sm w-16",children:"Action"})]})}),e.jsx("tbody",{children:y.map((j,_)=>{if(j.operation==="delete")return null;const u=v.get(j.task_id),p=U.get(j.dataset_id),g=ee(j.task_id,j.dataset_id,j.metric_name),w=!!(j.task_id&&j.dataset_id)&&B.isFetching;return e.jsxs("tr",{className:"border-b border-border",children:[e.jsx("td",{className:"py-2 px-2",children:e.jsx(fs,{value:j.task_id,onChange:S=>A(_,"task_id",S),placeholder:"Select task",searchPlaceholder:"Search tasks...",emptyMessage:"No tasks found.",selectedOption:u?{value:u.id,label:u.name}:null,queryKey:["eval-edit-task-search"],queryFn:O,enabled:t})}),e.jsx("td",{className:"py-2 px-2",children:e.jsx(fs,{value:j.dataset_id,onChange:S=>A(_,"dataset_id",S),placeholder:j.task_id?"Select dataset":"Select task first",searchPlaceholder:"Search datasets...",emptyMessage:j.task_id?"No datasets found for this task.":"Select a task first.",disabled:!j.task_id,selectedOption:p?{value:p.id,label:p.name}:null,queryKey:["eval-edit-dataset-search",j.task_id],queryFn:z(j.task_id),enabled:t&&!!j.task_id})}),e.jsx("td",{className:"py-2 px-2",children:e.jsx(oe,{type:"text",className:"w-full text-sm",placeholder:"Model name",value:j.model_name,onChange:S=>A(_,"model_name",S.target.value)})}),h&&e.jsx("td",{className:"py-2 px-2",children:V(j.task_id,j.dataset_id)?e.jsx(oe,{type:"text",className:"w-full text-sm",placeholder:"Claude Code, Terminus, ...",value:j.harness,onChange:S=>A(_,"harness",S.target.value)}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"Not supported"})}),e.jsx("td",{className:"py-2 px-2",children:!j.task_id||!j.dataset_id?e.jsx("span",{className:"text-xs text-muted-foreground",children:"Select task + dataset"}):w?e.jsxs("span",{className:"inline-flex items-center text-xs text-muted-foreground",children:[e.jsx(ce,{className:"mr-1 h-3 w-3 animate-spin"}),"Loading metrics..."]}):g.length>0?e.jsxs("select",{className:"w-full rounded-md border border-border bg-background px-2 py-1 text-sm",value:j.metric_name,onChange:S=>A(_,"metric_name",S.target.value),children:[e.jsx("option",{value:"",children:"Select metric"}),g.map(S=>e.jsx("option",{value:S.value,children:S.label},S.value))]}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"No configured metrics"})}),e.jsx("td",{className:"py-2 px-2",children:e.jsx(oe,{type:"text",className:"w-full text-sm",placeholder:"44.9",value:j.metric_value,onChange:S=>A(_,"metric_value",S.target.value)})}),e.jsx("td",{className:"py-2 px-2",children:e.jsx(oe,{type:"number",min:0,step:1,className:"w-full text-sm",placeholder:"e.g. 7000000000",value:j.num_parameters,onChange:S=>A(_,"num_parameters",S.target.value),title:"Raw model parameter count (e.g. 7000000000 for a 7B model). Leave blank if unknown."})}),e.jsx("td",{className:"py-2 px-2",children:e.jsx(oe,{type:"url",className:"w-full text-sm",placeholder:"https://huggingface.co/org/model",value:j.hf_model_url,onChange:S=>A(_,"hf_model_url",S.target.value),title:"Hugging Face model page for this row (must start with https://huggingface.co/). Leave blank if none."})}),e.jsx("td",{className:"py-2 px-2 text-center",children:e.jsx("input",{type:"checkbox",className:"h-4 w-4 align-middle",checked:j.is_open,onChange:S=>I(_,S.target.checked),title:"Whether the evaluated model is open-source. Uncheck for closed-source models."})}),e.jsx("td",{className:"py-2 px-2",children:e.jsx(K,{variant:"ghost",size:"sm",onClick:()=>F(_),className:"h-8 w-8 p-0 text-destructive hover:text-destructive",title:"Delete row",children:e.jsx(Ft,{className:"w-4 h-4"})})})]},_)})})]})}):e.jsxs("div",{className:"text-center py-8 text-muted-foreground",children:[e.jsx(wa,{className:"w-12 h-12 mx-auto mb-3 opacity-30"}),e.jsx("p",{children:"No evaluation results yet"}),e.jsx("p",{className:"text-sm mt-2",children:'Click "Add Row" below to add a new evaluation'})]}),e.jsx("div",{className:"mt-4",children:e.jsxs(K,{variant:"outline",size:"sm",onClick:R,className:"flex items-center space-x-2",children:[e.jsx(At,{className:"w-4 h-4"}),e.jsx("span",{children:"Add Row"})]})})]}),e.jsxs(Ee,{children:[e.jsxs("div",{className:"flex flex-wrap gap-2 sm:mr-auto",children:[e.jsx(K,{variant:"ghost",onClick:()=>E("benchmark"),children:"Suggest a new benchmark"}),e.jsx(K,{variant:"ghost",onClick:()=>E("metric"),children:"Suggest a new metric"})]}),e.jsx(K,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(K,{onClick:Y,disabled:b.isPending,children:b.isPending?e.jsxs(e.Fragment,{children:[e.jsx(ce,{className:"w-4 h-4 mr-2 animate-spin"}),m==="pending"?"Submitting...":"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(he,{className:"w-4 h-4 mr-2"}),m==="pending"?"Submit for review":"Save Changes"]})})]})]}),e.jsx(It,{open:P!==null,onOpenChange:j=>{j||E(null)},paperId:a,kind:P??"benchmark"})]})}const Te=["my-bookmark-ids"];function ri(){var c,n;const{user:t}=ct(),s=le({queryKey:Te,queryFn:()=>ot.getMyBookmarkIds(),enabled:!!t,staleTime:60*1e3,refetchOnWindowFocus:!1}),a=Rt.useMemo(()=>{var o;return new Set(((o=s.data)==null?void 0:o.paper_ids)??[])},[(c=s.data)==null?void 0:c.paper_ids]);return{ids:((n=s.data)==null?void 0:n.paper_ids)??[],idSet:a,isLoading:s.isLoading,isError:s.isError}}function ai(){const{user:t}=ct(),s=je(),a=Se({mutationFn:async({paperId:n,isBookmarked:o})=>{o?await ot.removeBookmark(n):await ot.addBookmark(n)},onMutate:async({paperId:n,isBookmarked:o})=>{await s.cancelQueries({queryKey:Te});const l=s.getQueryData(Te),m=typeof n=="string"?Number(n):n,r=(l==null?void 0:l.paper_ids)??[],h=o?r.filter(y=>y!==m):[m,...r.filter(y=>y!==m)];return s.setQueryData(Te,{paper_ids:h}),{previous:l}},onError:(n,o,l)=>{l!=null&&l.previous&&s.setQueryData(Te,l.previous)},onSettled:()=>{s.invalidateQueries({queryKey:Te}),s.invalidateQueries({queryKey:["my-bookmarks"]})}});return{toggle:Rt.useCallback((n,o)=>{if(!t){if(Ss())return;const l=typeof window<"u"?window.location.pathname+window.location.search:"/";window.location.href=Ps(`/api/v1/auth/hf/login?return_to=${encodeURIComponent(l)}`);return}a.mutate({paperId:n,isBookmarked:o})},[a,t]),isPending:a.isPending}}const ni=({paperId:t})=>{const{user:s}=ct(),{idSet:a}=ri(),{toggle:c,isPending:n}=ai();if(Ss())return null;const o=Number(t),l=!!s&&a.has(o),m=()=>{Number.isFinite(o)&&c(o,l)},r=s&&l?"Saved":"Save",h=s?l?"Remove from saved papers":"Save this paper":"Sign in with Hugging Face to save this paper";return e.jsxs("button",{type:"button",className:`action-btn${l?" is-saved":""}`,onClick:m,disabled:n,"aria-pressed":l,"aria-label":h,title:h,children:[e.jsx(te,{name:"bookmark",size:12}),r]})};function nt({children:t,showEdit:s=!1,onEdit:a,editAriaLabel:c}){return s?e.jsxs("span",{className:"action-btn-composite",children:[t,e.jsx("button",{type:"button",className:"action-btn-segment action-btn-edit",onClick:a,"aria-label":c,children:"edit"})]}):t}const ii={"add-evals":{trigger:"add evals",running:"adding evals…",complete:"add evals ✓",title:"Add evaluations with Codex",description:t=>e.jsxs(e.Fragment,{children:["Codex will run the repository’s add-evals skill for “",t,"”. It will import only paper-native results onto existing, metric-compatible leaderboards. Accepted rows are written directly to the live database."]}),notice:"Comparator rows, unknown benchmarks, and unconfigured metrics will be skipped. Jobs run one at a time in submission order.",progress:"Codex is researching the paper and validating results against the configured leaderboards.",action:"Run add-evals",start:Ra,get:Pa,cancel:Sa},"enrich-paper":{trigger:"enrich paper",running:"enriching…",complete:"enriched ✓",title:"Enrich paper with Codex",description:t=>e.jsxs(e.Fragment,{children:["Codex will run the repository’s enrich-paper skill for “",t,"”. It will validate official code and project links, merge high-confidence taxonomy tags, and check the paper thumbnail. Accepted changes are written directly to the live database."]}),notice:"Uncertain URLs and missing taxonomy concepts will be reported rather than guessed. Jobs run one at a time in submission order.",progress:"Codex is validating artifacts, taxonomy tags, and thumbnail quality for this paper.",action:"Run enrich-paper",start:Ea,get:Ca,cancel:Na}};function oi({report:t}){return e.jsx("div",{className:"min-w-0 max-h-[50vh] overflow-y-auto overflow-x-hidden rounded-md border bg-muted/40 p-4 text-sm leading-relaxed",children:e.jsx(Fa,{remarkPlugins:[$a],components:{a:({children:s,...a})=>e.jsx("a",{...a,className:"break-all underline underline-offset-2",target:"_blank",rel:"noreferrer",children:s}),p:({children:s})=>e.jsx("p",{className:"mb-3 break-words last:mb-0",children:s}),ul:({children:s})=>e.jsx("ul",{className:"mb-3 list-disc space-y-1 pl-5 last:mb-0",children:s}),ol:({children:s})=>e.jsx("ol",{className:"mb-3 list-decimal space-y-1 pl-5 last:mb-0",children:s}),h1:({children:s})=>e.jsx("h3",{className:"mb-2 font-semibold",children:s}),h2:({children:s})=>e.jsx("h3",{className:"mb-2 font-semibold",children:s}),h3:({children:s})=>e.jsx("h3",{className:"mb-2 font-semibold",children:s}),code:({children:s})=>e.jsx("code",{className:"break-all rounded bg-background/80 px-1 py-0.5 font-mono text-xs",children:s}),pre:({children:s})=>e.jsx("pre",{className:"mb-3 max-w-full overflow-x-auto whitespace-pre-wrap break-words rounded bg-background/80 p-3 font-mono text-xs last:mb-0",children:s})},children:t})})}function mr({kind:t,paperId:s,paperTitle:a,triggerClassName:c,onComplete:n}){const o=ii[t],[l,m]=i.useState(!1),[r,h]=i.useState(null),[y,k]=i.useState(!1),[P,E]=i.useState(null),v=i.useRef(null),$=(r==null?void 0:r.status)==="queued"||(r==null?void 0:r.status)==="dispatching"||(r==null?void 0:r.status)==="running",U=r==null?void 0:r.id;i.useEffect(()=>{if(!$||!U)return;let D=!1;const C=window.setInterval(async()=>{try{const f=await o.get(U);D||(h(f),E(null))}catch(f){D||E(f instanceof Error?f.message:"Could not check job status.")}},2e3);return()=>{D=!0,window.clearInterval(C)}},[$,o,U]),i.useEffect(()=>{(r==null?void 0:r.status)!=="completed"||v.current===r.id||(v.current=r.id,n())},[r,n]);const T=async()=>{k(!0),E(null);try{h(await o.start(s))}catch(D){E(D instanceof Error?D.message:"Could not start Codex.")}finally{k(!1)}},L=()=>{h(null),E(null),v.current=null},q=async()=>{if(r){E(null);try{h(await o.cancel(r.id))}catch(D){E(D instanceof Error?D.message:"Could not cancel Codex.")}}};return e.jsxs(ke,{open:l,onOpenChange:m,children:[e.jsx("button",{type:"button",className:c,onClick:()=>m(!0),children:$?o.running:(r==null?void 0:r.status)==="completed"?o.complete:o.trigger}),e.jsxs(_e,{className:"max-h-[90vh] w-[calc(100vw-2rem)] min-w-0 max-w-2xl overflow-hidden",children:[e.jsxs(we,{className:"min-w-0",children:[e.jsx(Ne,{children:o.title}),e.jsx(Ce,{children:o.description(a)})]}),r?e.jsxs("div",{className:"min-w-0 space-y-3 overflow-hidden",children:[e.jsxs("div",{className:"font-mono text-xs uppercase tracking-wide text-muted-foreground",children:["Status: ",r.status]}),r.hf_job_url&&e.jsx("a",{className:"text-sm underline",href:r.hf_job_url,target:"_blank",rel:"noreferrer",children:"View Hugging Face Job"}),$&&e.jsxs("div",{className:"rounded-md border bg-muted/40 p-3 text-sm",children:[r.status==="queued"?"This job is queued and will start after the current Codex job finishes.":o.progress," ","This can take several minutes; you can close this window and return."]}),r.report&&e.jsx(oi,{report:r.report}),r.error&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive",children:r.error})]}):e.jsx("div",{className:"rounded-md border bg-muted/40 p-3 text-sm text-muted-foreground",children:o.notice}),P&&e.jsx("div",{className:"rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive",children:P}),e.jsxs(Ee,{children:[e.jsx(K,{variant:"outline",onClick:()=>m(!1),children:$?"Close":"Cancel"}),$&&e.jsx(K,{variant:"outline",onClick:()=>void q(),children:"Cancel job"}),!r&&e.jsx(K,{onClick:T,disabled:y,children:y?"Starting…":o.action}),r&&!$&&e.jsx(K,{variant:"outline",onClick:L,children:"Run again"})]})]})]})}function li(t){return e.jsx(mr,{...t,kind:"add-evals",triggerClassName:"edit-link"})}function ci(t){return e.jsx(mr,{...t,kind:"enrich-paper",triggerClassName:"action-btn"})}const di={tasks:"tasks",methods:"methods",results:"evaluation results",repositories:"GitHub repositories","project-pages":"project pages","source-url":"source URL"},it=360,_t=3,ui=3,mi=["tldr","abstract","tasks","methods","results"];function pi(t){if(!t)return{section:null,resultsTaskSlug:null};const[s,a]=t.split("?",2);if(!mi.includes(s))return{section:null,resultsTaskSlug:null};const c=s;return c!=="results"||!a?{section:c,resultsTaskSlug:null}:{section:c,resultsTaskSlug:new URLSearchParams(a).get("task")}}function vs(t){return`results-task-${t}`}function hi(t){return`#results?task=${encodeURIComponent(t)}`}function He({id:t,label:s,accent:a}){return e.jsxs("div",{className:"section-rule paper-section-anchor",id:t,children:[e.jsx("span",{children:e.jsx("a",{href:`#${t}`,className:"section-anchor-link",children:s})}),a]})}function bs(t){if(!t)return"—";try{return new Date(t).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})}catch{return"—"}}function js(t){return t>=1e3?`${(t/1e3).toFixed(1)}k`:String(t)}function ys(t,s){try{const a=new URL(t),n=a.pathname.replace(/\/$/,"").split("/").filter(Boolean).at(-1);return n?n.replace(/[-_]+/g," "):a.hostname.replace(/^www\./,"")}catch{return s}}const Bi=()=>{var Zt,es,ts,ss,rs,as,ns,is,os;const{arxivId:t}=Gr(),s=t?Wr(t):"",a=Jr(),{toast:c}=ye(),{user:n}=ct(),o=(n==null?void 0:n.is_admin)??!1,l=!!n,m=!0,{data:r,isLoading:h,error:y,refetch:k}=fa(s||"",!!s),[P,E]=i.useState(!1);i.useEffect(()=>{if(!t||t===s)return;const d=window.location.search+window.location.hash;a(`/paper/${s}${d}`,{replace:!0})},[s,a,t]),i.useEffect(()=>{if(r!=null&&r.title)return document.title=pa(r.title),()=>{document.title=ha}},[r==null?void 0:r.title]),i.useEffect(()=>{if(E(!1),!(r!=null&&r.id))return;const d=window.setTimeout(()=>E(!0),0);return()=>window.clearTimeout(d)},[r==null?void 0:r.id]);const{data:v,isLoading:$}=Oa(P?r==null?void 0:r.arxiv_id:void 0),{data:U,isLoading:T,refetch:L}=Da(r==null?void 0:r.id,P&&!!(r!=null&&r.id)),{preferences:q}=Xr(),D=i.useMemo(()=>!U||!q.hide_closed_source_evals?U:U.filter(d=>d.is_open!==!1),[U,q.hide_closed_source_evals]),C=i.useMemo(()=>({models:(r==null?void 0:r.hf_models)??[],datasets:(r==null?void 0:r.hf_datasets)??[],spaces:(r==null?void 0:r.hf_spaces)??[]}),[r==null?void 0:r.hf_models,r==null?void 0:r.hf_datasets,r==null?void 0:r.hf_spaces]),f=i.useMemo(()=>{const d=(N,Q,J)=>{const ie=new Set,X=[];for(const re of[...N,...Q??[]])if(!ie.has(re)&&(ie.add(re),X.push({href:re,label:ys(re,J)}),X.length>=ui))break;return X};return{models:d(C.models,v==null?void 0:v.modelUrls,"Model"),datasets:d(C.datasets,v==null?void 0:v.datasetUrls,"Dataset"),spaces:d(C.spaces,v==null?void 0:v.spaceUrls,"Space")}},[C.models,C.datasets,C.spaces,v==null?void 0:v.modelUrls,v==null?void 0:v.datasetUrls,v==null?void 0:v.spaceUrls]),x=i.useMemo(()=>{if(!D)return[];const d=new Map;for(const N of D){const Q=N.task_id,J=d.get(Q);J?J.rows.push(N):d.set(Q,{taskId:Q,taskName:N.task_name||"—",taskSlug:N.task_slug,rows:[N]})}return Array.from(d.values())},[D]),M=i.useMemo(()=>x.map(d=>d.taskSlug??"").join("|"),[x]),B=le({queryKey:["paper-versions",r==null?void 0:r.arxiv_id],queryFn:async()=>{const d=r.arxiv_id.replace(/v\d+$/,""),N=await fetch(Ps(`/api/v1/papers/arxiv/${d}/versions`));return N.ok?await N.json():[]},enabled:P&&!!(r!=null&&r.arxiv_id),staleTime:10*60*1e3}),O=le({queryKey:["related-papers",r==null?void 0:r.id],queryFn:()=>ot.getRelatedPapers(r.arxiv_id||r.id,4),enabled:P&&!!(r!=null&&r.id),staleTime:10*60*1e3}),[z,V]=i.useState(!1),[ee,b]=i.useState(!1),[R,F]=i.useState(!1),A=i.useRef(!1);i.useEffect(()=>{A.current=!1},[s]),i.useEffect(()=>{let d=0;const N=(J=!1,ie=!1)=>{const{section:X,resultsTaskSlug:re}=pi(window.location.hash.slice(1));if(!X||!r||X==="tldr"&&!r.tldr||X==="results"&&(!P||T)||!J&&A.current)return;let Ae=null;if(X==="results"&&re){if(Ae=document.getElementById(vs(re)),!Ae){if(x.find(Cr=>Cr.taskSlug===re))return;Ae=document.getElementById("results")}}else Ae=document.getElementById(X);if(!Ae)return;const Nr=Ae;d=window.requestAnimationFrame(()=>{A.current=!0,Nr.scrollIntoView({block:"start",behavior:ie?"smooth":"auto"})})};N();const Q=()=>{A.current=!1,N(!0,!0)};return window.addEventListener("hashchange",Q),()=>{window.removeEventListener("hashchange",Q),d&&window.cancelAnimationFrame(d)}},[r,r==null?void 0:r.tldr,P,T,M,x]);const{isEditingTasks:I,setIsEditingTasks:Y,isEditingMethods:j,setIsEditingMethods:_,isEditingRepositories:u,setIsEditingRepositories:p,isEditingProjectPages:g,setIsEditingProjectPages:w,isEditingEvaluations:S,setIsEditingEvaluations:H,isEditingSourceUrl:G,setIsEditingSourceUrl:W}=Ha(),[de,Ut]=i.useState(null),Pe=i.useMemo(()=>{if(!n||!(r!=null&&r.author_links))return!1;const d=n.username.toLowerCase();return r.author_links.some(N=>!!N.hf_username&&N.hf_username.toLowerCase()===d)},[n,r==null?void 0:r.author_links]),Re=o?"direct":"pending",ne=d=>{if(!l){Ut(d);return}switch(d){case"tasks":Y(!0);return;case"methods":_(!0);return;case"results":H(!0);return;case"repositories":p(!0);return;case"project-pages":w(!0);return;case"source-url":W(!0);return}},[qt,pt]=i.useState("idle"),[Bt,Ot]=i.useState(null),[Ht,Kt]=i.useState(null),pr=async()=>{if(s){pt("indexing"),Ot(null),Kt(null);try{await aa(s),c({title:"Indexed",description:"Paper added to database."}),setTimeout(()=>k(),1200),pt("idle")}catch(d){const N=d;let Q=N.message||"Failed to index paper";if(N.response)try{Q=JSON.parse(N.response).detail||Q}catch{Q=N.response}Ot(Q),(N.status===429||N.status===503)&&Kt("Try again later after arXiv has lifted the temporary limit."),pt("idle")}}},{citationDisplay:hr,citationCopy:zt}=i.useMemo(()=>{if(!r)return{citationDisplay:"",citationCopy:""};const d=`${r.title.slice(0,60)}${r.title.length>60?"…":""}`,N=`${r.authors[0]||""}${r.authors.length>1?" et al.":""}`,Q=r.authors.join(" and "),J=(r.published||"").slice(0,4)||"—",ie=(X,re)=>r.arxiv_id?`@article{${r.arxiv_id.replace(".","")}, + title={{${X}}}, + author=${re}, + year={{${J}}}, + eprint={{${r.arxiv_id}}}, + archivePrefix={{arXiv}} +}`:`@misc{paper${r.id}, + title={{${X}}}, + author=${re}, + year={{${J}}}, + url={{${r.source_url||r.url_abs||""}}} +}`;return{citationDisplay:ie(d,`{{${N}}}`),citationCopy:ie(r.title,`{${Q}}`)}},[r]),Qt=i.useMemo(()=>La(r==null?void 0:r.leaderboard_ranks),[r==null?void 0:r.leaderboard_ranks]),[fr,Vt]=i.useState(!1),gr=async()=>{if(zt)try{await navigator.clipboard.writeText(zt),Vt(!0),c({title:"Citation copied",description:"BibTeX entry copied to clipboard."}),window.setTimeout(()=>Vt(!1),1500)}catch{c({title:"Copy failed",description:"Could not access the clipboard. Please copy manually.",variant:"destructive"})}},xr=async()=>{if(!r)return;const d=r.arxiv_id||r.id,N=Ma(d,Qt);if(N)try{await navigator.clipboard.writeText(N),c({title:"PwC badges copied",description:"Each badge links to its highlighted leaderboard row."})}catch{c({title:"Copy failed",description:"Could not access the clipboard. Please try again.",variant:"destructive"})}};if(h)return e.jsxs("div",{className:"page",children:[e.jsx(Ke,{className:"h-12 w-3/4 mb-4"}),e.jsx(Ke,{className:"h-6 w-1/3 mb-8"}),e.jsx(Ke,{className:"h-64 w-full"})]});if(y||!r)return e.jsxs("div",{className:"page",children:[e.jsxs("div",{className:"breadcrumb",children:[e.jsx(ue,{to:"/papers",children:"Papers"}),e.jsx("span",{className:"sep",children:"/"}),e.jsxs("span",{style:{color:"var(--ink)"},children:["arXiv:",s]})]}),e.jsx("h1",{className:"detail-title",children:"Paper not indexed yet"}),e.jsxs("p",{style:{fontFamily:"var(--serif)",color:"var(--ink-soft)",marginTop:16,maxWidth:640},children:["We don't have ",e.jsxs("span",{style:{fontFamily:"var(--mono)"},children:["arXiv:",s]})," in the database. You can index it from arXiv right now."]}),Bt&&e.jsx(ga,{variant:"destructive",className:"mt-4 max-w-xl",children:e.jsxs(xa,{children:[e.jsx("div",{children:Bt}),Ht&&e.jsx("div",{className:"mt-2",children:Ht})]})}),e.jsxs("div",{className:"action-row",children:[o&&e.jsxs("button",{className:"action-btn",onClick:pr,disabled:qt==="indexing",children:[e.jsx(te,{name:"sparkle",size:12}),qt==="indexing"?"Indexing…":"Index from arXiv"]}),e.jsx(K,{variant:"outline",onClick:()=>a("/papers"),children:"Browse Papers"})]})]});const Gt=B.data||[],qe=ma(r.repositories),ge=[...r.repositories??[]].sort((d,N)=>{const Q=d.is_official?1:0,J=N.is_official?1:0;return Q!==J?J-Q:(N.num_stars||0)-(d.num_stars||0)}),vr=R?ge:ge.slice(0,_t),ht=((Zt=r.arxiv_id)==null?void 0:Zt.replace(/v\d+$/,""))??null,ft=r.arxiv_id?{isLoading:$,paperHref:`https://huggingface.co/papers/${ht}`,rows:[{label:"Models",href:Nt(`https://huggingface.co/models?other=arxiv:${r.arxiv_id}`,C.models),count:Ct(C.models,v==null?void 0:v.modelUrls,v==null?void 0:v.models),isLimited:v==null?void 0:v.isLimited,links:f.models},{label:"Datasets",href:Nt(`https://huggingface.co/datasets?other=arxiv:${r.arxiv_id}`,C.datasets),count:Ct(C.datasets,v==null?void 0:v.datasetUrls,v==null?void 0:v.datasets),isLimited:v==null?void 0:v.isLimited,links:f.datasets},{label:"Spaces",href:Nt(`https://huggingface.co/papers/${ht}`,C.spaces),count:Ct(C.spaces,v==null?void 0:v.spaceUrls,v==null?void 0:v.spaces),isLimited:v==null?void 0:v.isLimited,links:f.spaces}],footer:`Cite arxiv.org/abs/${ht} in a HF README to link it here.`}:{isLoading:!1,paperHref:null,rows:[{label:"Models",href:wt(C.models),count:C.models.length,links:f.models},{label:"Datasets",href:wt(C.datasets),count:C.datasets.length,links:f.datasets},{label:"Spaces",href:wt(C.spaces),count:C.spaces.length,links:f.spaces}],footer:null},Wt=r.tldr||null,Jt=r.num_pages||null,Ie=r.abstract||"",br=Ie.length>it?Ie.slice(0,it)+"…":Ie,jr=z||Ie.length<=it?Ie:br,Xe=(r.methods||[]).filter(d=>d.source_paper_id===r.id),Ye=r.introduced_benchmarks||[],yr=Xe.length>0||Ye.length>0,Xt=r.arxiv_id?`arXiv:${r.arxiv_id}`:"External resource",kr=r.source==="external"?"Source page":"arXiv page",Be=((es=r.project_pages)==null?void 0:es.filter(d=>d.url))??[],_r=(()=>{const d=[];return Xe.length>0&&d.push(Xe.length===1?"this method":"these methods"),Ye.length>0&&d.push(Ye.length===1?"this benchmark":"these benchmarks"),d.length===0?"":d.length===1?d[0]:d.join(" and ")})(),Ze=r.predecessor_papers||[],et=r.successor_papers||[],wr=Ze.length>0||et.length>0,tt=12,gt=r.authors.map((d,N)=>{var Q,J,ie,X;return{name:d,id:((J=(Q=r.author_links)==null?void 0:Q[N])==null?void 0:J.id)??null,hf_username:((X=(ie=r.author_links)==null?void 0:ie[N])==null?void 0:X.hf_username)??null}}),Yt=ee||gt.length<=tt?gt:gt.slice(0,tt);return e.jsxs("div",{className:"page",children:[e.jsxs("div",{className:"breadcrumb",children:[e.jsx(ue,{to:"/",children:"Trending"}),e.jsx("span",{className:"sep",children:"/"}),e.jsx("span",{children:Xt})]}),e.jsxs("div",{className:"detail-grid",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"detail-hero",children:[e.jsxs("div",{className:"detail-hero-main",children:[e.jsx("h1",{className:"detail-title",children:e.jsx(st,{title:r.title})}),e.jsxs("div",{className:"detail-meta",children:[e.jsx("span",{children:Xt}),e.jsx("span",{children:"·"}),e.jsxs("span",{children:["Submitted ",bs(r.published)]}),Jt&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsxs("span",{children:[Jt," pages"]})]}),r.citation_count!=null&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsxs("span",{children:[r.citation_count.toLocaleString()," citations"]})]}),(r.proceeding||r.conference_slug)&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),r.conference_slug?e.jsx("a",{href:`/conferences/${r.conference_slug}`,target:"_blank",rel:"noopener noreferrer",style:{color:"var(--accent-text)"},children:(r.proceeding||r.conference_name||"").replace(/\s+\d{1,2}$/,"")}):e.jsx("span",{children:r.proceeding.replace(/\s+\d{1,2}$/,"")})]}),Gt.length>1&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsx("select",{className:"version-select",value:r.version,onChange:d=>{const N=d.target.value;r.arxiv_id&&a(`/paper/${r.arxiv_id.replace(/v\d+$/,"")}${N?`?version=${N}`:""}`)},children:Gt.map(d=>e.jsxs("option",{value:d.version,children:[d.version," — ",bs(d.published)]},d.version))})]})]}),e.jsxs("div",{className:"detail-authors",children:[Yt.map((d,N)=>e.jsxs(Rt.Fragment,{children:[d.id?e.jsx(ue,{to:`/authors/${d.id}`,children:d.name}):d.hf_username?e.jsx("a",{href:`https://huggingface.co/${d.hf_username}`,target:"_blank",rel:"noopener noreferrer",title:`@${d.hf_username} on Hugging Face`,children:d.name}):e.jsx("a",{children:d.name}),Ntt&&e.jsx("button",{className:"show-more-authors",onClick:()=>b(d=>!d),style:{marginLeft:8,background:"none",border:"none",cursor:"pointer",color:"var(--accent-text)",fontFamily:"var(--mono)",fontSize:12},children:ee?"show fewer":`+${r.authors.length-tt} more`})]}),e.jsxs("div",{className:"action-row",children:[r.url_pdf&&e.jsxs("a",{className:"action-btn",href:r.url_pdf,target:"_blank",rel:"noopener noreferrer",children:[e.jsx(te,{name:"pdf",size:12})," View PDF"]}),r.url_abs&&e.jsx(nt,{showEdit:r.source==="external"&&m,onEdit:()=>ne("source-url"),editAriaLabel:"Edit source URL",children:e.jsxs("a",{className:r.source==="external"&&m?"action-btn-segment action-btn-main":"action-btn",href:r.url_abs,target:"_blank",rel:"noopener noreferrer",children:[e.jsx(te,{name:"external",size:12})," ",kr]})}),ft.paperHref&&(v==null?void 0:v.paperExists)&&e.jsxs("a",{className:"bm-action-btn",href:ft.paperHref,target:"_blank",rel:"noopener noreferrer","aria-label":"View on Hugging Face",children:["View on ",e.jsx("span",{"aria-hidden":"true",children:"🤗"})]}),qe.githubUrl&&e.jsx(nt,{showEdit:m,onEdit:()=>ne("repositories"),editAriaLabel:"Edit code repositories",children:e.jsxs("a",{className:"action-btn-segment action-btn-main",href:qe.githubUrl,target:"_blank",rel:"noopener noreferrer",children:[e.jsx(te,{name:"github",size:12})," Code",qe.github!=null&&e.jsxs("span",{style:{opacity:.7,marginLeft:4},children:["· ",js(qe.github)," ★"]})]})}),qe.githubUrl?null:e.jsxs("button",{type:"button",className:"action-btn",onClick:()=>ne("repositories"),title:"Add GitHub repository",children:[e.jsx(te,{name:"github",size:12})," Add code"]}),Be.length===1?e.jsx(nt,{showEdit:m,onEdit:()=>ne("project-pages"),editAriaLabel:"Edit project pages",children:e.jsxs("a",{className:"action-btn-segment action-btn-main",href:Be[0].url,target:"_blank",rel:"noopener noreferrer",children:[e.jsx(te,{name:"globe",size:12})," Project page"]})}):null,Be.length>1?e.jsx(nt,{showEdit:m,onEdit:()=>ne("project-pages"),editAriaLabel:"Edit project pages",children:e.jsxs(Yr,{children:[e.jsx(Zr,{asChild:!0,children:e.jsxs("button",{type:"button",className:"action-btn-segment action-btn-main",children:[e.jsx(te,{name:"globe",size:12})," Project page"]})}),e.jsx(ea,{align:"start",className:"project-page-menu",children:Be.map((d,N)=>e.jsx(ta,{asChild:!0,children:e.jsx("a",{href:d.url,target:"_blank",rel:"noopener noreferrer",children:ys(d.url,`Project page ${N+1}`)})},d.url))})]})}):null,Be.length===0&&l?e.jsxs("button",{type:"button",className:"action-btn",onClick:()=>ne("project-pages"),title:"Add project page",children:[e.jsx(te,{name:"globe",size:12})," Add project page"]}):null,r.conference_url_abs&&e.jsxs("a",{className:"action-btn",href:r.conference_url_abs,target:"_blank",rel:"noopener noreferrer",children:[e.jsx(te,{name:"external",size:12})," Conference"]}),(r.organizations||[]).map(d=>e.jsxs(ue,{to:`/${d.slug}`,className:"action-btn",title:d.name,"aria-label":d.name,children:[d.logo_url&&e.jsx("span",{style:{display:"inline-flex",alignItems:"center",justifyContent:"center",height:16,width:16,borderRadius:3,overflow:"hidden"},children:e.jsx("img",{src:d.logo_url,alt:"",style:{height:"150%",width:"150%",objectFit:"contain"},onError:N=>{N.currentTarget.style.display="none"}})}),d.name]},d.id)),o&&Ia()&&e.jsx(ci,{paperId:r.id,paperTitle:r.title,onComplete:()=>void k()}),e.jsx(ni,{paperId:r.id})]}),r.leaderboard_ranks&&r.leaderboard_ranks.length>0&&e.jsx(na,{wrap:!0,paperHref:`/paper/${r.arxiv_id||r.id}`,ranks:r.leaderboard_ranks.filter(d=>d.best_rank>=1&&d.best_rank<=3).map(d=>({name:d.dataset_name,slug:d.dataset_slug||null,rank:d.best_rank}))})]}),e.jsx("div",{className:"detail-hero-thumb detail-thumb-wrap",children:e.jsx(ia,{paperId:r.arxiv_id||r.id,title:r.title,thumbnailUrl:sa(r.thumbnail_url),priority:!0})})]}),yr&&e.jsxs("div",{className:"introduced-banner",children:[e.jsx("span",{className:"introduced-label",children:"Introduced"}),e.jsxs("div",{className:"introduced-methods",children:[Xe.map(d=>e.jsxs("button",{type:"button",className:"introduced-pill",onClick:()=>a(`/methods/${d.slug||d.id}`),children:[d.name,e.jsx("span",{className:"introduced-arrow",children:"→"})]},`method-${d.id}`)),Ye.map(d=>e.jsxs("button",{type:"button",className:"introduced-pill",onClick:()=>a(`/benchmark/${d.slug||d.id}`),children:[d.name,e.jsx("span",{className:"introduced-arrow",children:"→"})]},`benchmark-${d.id}`))]}),e.jsxs("span",{className:"introduced-note",children:["This paper is the canonical source for ",_r,"."]})]}),wr&&e.jsxs("div",{className:"introduced-banner lineage-banner",children:[et.length>0&&e.jsxs("div",{className:"lineage-row",children:[e.jsx("span",{className:"introduced-label lineage-label",children:et.length===1?"Follow-up paper":"Follow-up papers"}),e.jsx("div",{className:"introduced-methods",children:et.map(d=>e.jsxs("button",{type:"button",className:"introduced-pill lineage-pill",onClick:()=>a(`/paper/${d.route_identifier}`),children:[e.jsx(st,{title:d.title}),e.jsx("span",{className:"introduced-arrow",children:"→"})]},`successor-${d.id}`))})]}),Ze.length>0&&e.jsxs("div",{className:"lineage-row",children:[e.jsx("span",{className:"introduced-label lineage-label",children:Ze.length===1?"Predecessor paper":"Predecessor papers"}),e.jsx("div",{className:"introduced-methods",children:Ze.map(d=>e.jsxs("button",{type:"button",className:"introduced-pill lineage-pill",onClick:()=>a(`/paper/${d.route_identifier}`),children:[e.jsx("span",{className:"introduced-arrow lineage-arrow-back",children:"←"}),e.jsx(st,{title:d.title})]},`predecessor-${d.id}`))})]})]}),Wt&&e.jsxs(e.Fragment,{children:[e.jsx(He,{id:"tldr",label:"TL;DR · AI-generated"}),e.jsx("div",{className:"tldr-box",children:Wt})]}),e.jsx(He,{id:"abstract",label:"Abstract"}),e.jsx("p",{className:"abstract-text",style:{marginBottom:8},children:e.jsx(ua,{text:jr})}),Ie.length>it&&e.jsx("div",{className:"read-full",onClick:()=>V(d=>!d),children:z?"− collapse abstract":"+ read full abstract"}),e.jsx(He,{id:"tasks",label:"Tasks",accent:e.jsxs("span",{className:"accent",children:[((ts=r.tasks)==null?void 0:ts.length)||0," tagged",e.jsx("button",{type:"button",onClick:()=>ne("tasks"),className:"edit-link",children:"edit"})]})}),e.jsx("div",{className:"paper-tags",style:{marginBottom:8},children:(r.tasks||[]).map(d=>e.jsx(oa,{slug:d.slug||"",label:d.name},d.id))}),e.jsx(He,{id:"methods",label:"Methods",accent:e.jsxs("span",{className:"accent",children:[((ss=r.methods)==null?void 0:ss.length)||0," used",e.jsx("button",{type:"button",onClick:()=>ne("methods"),className:"edit-link",children:"edit"})]})}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginBottom:8},children:(r.methods||[]).map(d=>e.jsx(la,{method:d},d.id))}),e.jsx(He,{id:"results",label:"Results",accent:e.jsxs("span",{className:"accent",children:[(D==null?void 0:D.length)||0," benchmarks",Qt.length>0&&e.jsxs("button",{type:"button",className:"edit-link results-badge-copy",onClick:xr,title:"Copy live leaderboard badges for your repository README",children:[e.jsx(te,{name:"copy",size:10})," Copy PwC badge"]}),o&&Aa()&&e.jsx(li,{paperId:r.id,paperTitle:r.title,onComplete:()=>void L()}),e.jsx("button",{type:"button",onClick:()=>ne("results"),className:"edit-link",children:"edit"})]})}),T?e.jsx(Ke,{className:"h-32 w-full"}):x.length>0?x.map(d=>e.jsxs("div",{className:d.taskSlug?"paper-section-anchor":void 0,id:d.taskSlug?vs(d.taskSlug):void 0,children:[e.jsxs("div",{className:"section-rule",children:[e.jsx("span",{children:d.taskSlug?e.jsxs(e.Fragment,{children:[e.jsx(ue,{to:`/tasks/${d.taskSlug}`,children:d.taskName}),e.jsx("a",{href:hi(d.taskSlug),className:"section-anchor-link results-task-permalink","aria-label":`Permalink to ${d.taskName} results on this paper`,title:"Link to this task's results",children:"#"})]}):d.taskName}),e.jsxs("span",{className:"accent",children:[d.rows.length," ",d.rows.length===1?"result":"results"]})]}),e.jsxs("table",{className:"results-table",children:[e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:"28%"}}),e.jsx("col",{style:{width:"28%"}}),e.jsx("col",{style:{width:"14%"}}),e.jsx("col",{style:{width:"12%"}}),e.jsx("col",{style:{width:"8%"}}),e.jsx("col",{style:{width:"10%"}})]}),e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Benchmark"}),e.jsx("th",{children:"Model"}),e.jsx("th",{children:"Metric"}),e.jsx("th",{children:"Value"}),e.jsx("th",{children:"Rank"}),e.jsx("th",{children:"Compare"})]})}),e.jsx("tbody",{children:d.rows.map(N=>{var Q;return e.jsxs("tr",{children:[e.jsx("td",{className:"benchmark",children:N.dataset_slug?e.jsx(ue,{to:`/benchmark/${N.dataset_slug}`,children:N.dataset_name||"—"}):N.dataset_name||"—"}),e.jsxs("td",{className:"model",title:N.model_name||void 0,children:[N.hf_model_url?e.jsx("a",{href:N.hf_model_url,target:"_blank",rel:"noopener noreferrer",className:"model-hf-link",title:`Open ${N.model_name||"model"} on Hugging Face`,children:N.model_name||"—"}):N.model_name||"—",N.is_open===!1&&e.jsx(ca,{}),(N.external??N.is_external)&&e.jsx(da,{sourceUrl:N.source_url||N.external_source_url||N.result_url})]}),e.jsx("td",{className:"metric",children:N.best_metric}),e.jsx("td",{className:"value",children:ra((Q=N.metrics)==null?void 0:Q[N.best_metric||""])}),e.jsx("td",{className:"rank",children:N.best_rank!=null?`#${N.best_rank}`:"—"}),e.jsx("td",{className:"compare",children:N.dataset_slug&&e.jsx(ue,{to:`/benchmark/${N.dataset_slug}?${[N.task_slug?`task=${encodeURIComponent(N.task_slug)}`:"",`eval=${encodeURIComponent(N.id)}`].filter(Boolean).join("&")}`,children:"Compare →"})})]},N.id)})})]})]},d.taskId)):e.jsx("p",{style:{fontFamily:"var(--mono)",fontSize:12,color:"var(--ink-faint)"},children:"No benchmark results recorded yet."})]}),e.jsxs("aside",{className:"detail-sidebar",children:[e.jsxs("div",{className:"sidebar-card",children:[e.jsxs("div",{className:"sidebar-card-title",children:[e.jsx("span",{children:"GitHub"}),e.jsxs("span",{className:"badge",children:[ge.length," repo",ge.length===1?"":"s",e.jsx("button",{type:"button",onClick:()=>ne("repositories"),className:"edit-link",children:"edit"})]})]}),vr.map(d=>e.jsxs("a",{href:d.url,target:"_blank",rel:"noopener noreferrer",className:"code-line",style:{textDecoration:"none"},children:[e.jsxs("span",{className:"code-line-repo",children:[e.jsx(te,{name:"github",size:12}),e.jsxs("span",{className:"code-line-repo-name",children:[d.owner,"/",d.name]}),d.is_official&&e.jsx("span",{className:"code-line-official",children:"· Official"})]}),e.jsxs("span",{className:"code-line-stars",children:["★ ",js(d.num_stars)]})]},d.id)),ge.length===0&&e.jsx("div",{style:{fontFamily:"var(--mono)",fontSize:11,color:"var(--ink-faint)",padding:"6px 0"},children:"No GitHub repositories linked yet."}),ge.length>_t&&e.jsx("button",{type:"button",className:"bench-show-more",onClick:()=>F(d=>!d),children:R?"− show top 3":`+ show ${ge.length-_t} more repos`})]}),e.jsx(fi,{viewer:ft}),e.jsxs("div",{className:"sidebar-card",children:[e.jsxs("div",{className:"sidebar-card-title",children:[e.jsx("span",{children:"Citation"}),e.jsxs("button",{type:"button",className:"citation-copy-btn",onClick:gr,"aria-label":"Copy citation to clipboard",title:"Copy citation to clipboard",children:[e.jsx(te,{name:"copy",size:11}),fr?"Copied":"Copy"]})]}),e.jsx("pre",{style:{fontFamily:"var(--mono)",fontSize:10.5,lineHeight:1.5,color:"var(--ink-soft)",whiteSpace:"pre-wrap",wordBreak:"break-word",margin:0},children:hr})]}),O.isLoading&&e.jsxs("div",{className:"sidebar-card","aria-busy":"true",children:[e.jsx("div",{className:"sidebar-card-title",children:"Related papers"}),e.jsx("div",{className:"related-meta",children:"Finding related work…"})]}),!O.isLoading&&(((rs=O.data)==null?void 0:rs.length)??0)>0&&e.jsxs("div",{className:"sidebar-card",children:[e.jsx("div",{className:"sidebar-card-title",children:"Related papers"}),O.data.map(d=>e.jsxs(ue,{to:`/paper/${d.arxiv_id||d.id}`,target:"_blank",rel:"noopener noreferrer",className:"related-paper",style:{textDecoration:"none",color:"inherit"},children:[e.jsx("div",{className:"related-title",children:e.jsx(st,{title:d.title})}),e.jsxs("div",{className:"related-meta",children:[e.jsx("span",{children:d.arxiv_id?`arXiv:${d.arxiv_id}`:"External resource"}),d.citation_count!=null&&e.jsxs("span",{children:[d.citation_count.toLocaleString()," cites"]})]})]},d.id))]})]})]}),e.jsx(Xa,{open:I,onOpenChange:Y,paperId:r.id,arxivId:s,initialTaskIds:((as=r.tasks)==null?void 0:as.map(d=>parseInt(d.id)))||[],initialTasks:r.tasks||[],submitMode:Re,isAuthor:Pe}),e.jsx(en,{open:j,onOpenChange:_,paperId:r.id,arxivId:s,initialMethodIds:((ns=r.methods)==null?void 0:ns.map(d=>parseInt(d.id)))||[],initialMethods:r.methods||[],submitMode:Re,isAuthor:Pe}),e.jsx(tn,{open:u,onOpenChange:p,paperId:r.id,arxivId:s,initialRepositories:((is=r.repositories)==null?void 0:is.map(d=>({url:d.url,is_official:d.is_official||!1})))||[],submitMode:Re,isAuthor:Pe}),e.jsx(sn,{open:g,onOpenChange:w,paperId:r.id,arxivId:s,initialProjectPages:((os=r.project_pages)==null?void 0:os.map(d=>({url:d.url,is_official:d.is_official||!1})))||[],submitMode:Re,isAuthor:Pe}),e.jsx(si,{open:S,onOpenChange:H,paperId:r.id,arxivId:s,initialEvaluations:U||[],paperTasks:r.tasks||[],submitMode:Re,isAuthor:Pe}),e.jsx(rn,{open:G,onOpenChange:W,paperId:r.id,arxivId:s,initialUrl:r.source_url??r.url_abs??"",submitMode:Re,isAuthor:Pe}),e.jsx(_a,{open:de!==null,onOpenChange:d=>{d||Ut(null)},sectionLabel:de?di[de]:"this paper",returnTo:typeof window<"u"?window.location.pathname:"/"})]})},fi=({viewer:t})=>e.jsxs("div",{className:"sidebar-card",children:[e.jsx("div",{className:"sidebar-card-title",children:t.paperHref?e.jsx("a",{href:t.paperHref,target:"_blank",rel:"noopener noreferrer",style:{color:"inherit",textDecoration:"none"},children:"🤗 Hugging Face"}):e.jsx("span",{children:"🤗 Hugging Face"})}),t.isLoading?e.jsx(Ke,{className:"h-16 w-full"}):e.jsxs(e.Fragment,{children:[t.rows.map(s=>e.jsx(gi,{...s},s.label)),t.footer&&e.jsx("div",{style:{fontFamily:"var(--mono)",fontSize:10,color:"var(--ink-faint)",marginTop:12},children:t.footer})]})]}),gi=({label:t,href:s,count:a,isLimited:c,links:n})=>{const o=((n==null?void 0:n.length)??0)>0,l=a!=null?`${a}${c?"+":""}`:"—",m=a?e.jsx("a",{href:s,target:"_blank",rel:"noopener noreferrer",className:"hf-artifact-count",children:l}):e.jsx("span",{className:"hf-artifact-count hf-artifact-count--empty",children:l});return e.jsxs("div",{className:"hf-artifact-row",children:[e.jsxs("div",{className:"hf-artifact-row-header",children:[e.jsx("span",{children:t}),m]}),o&&e.jsx("div",{className:"hf-artifact-links",children:n.map(r=>e.jsx("a",{href:r.href,target:"_blank",rel:"noopener noreferrer",children:r.label},r.href))})]})};function wt(t){return t[0]??"https://huggingface.co"}function Nt(t,s){return s[0]??t}function Ct(t,s,a){if(a==null&&t.length===0&&!(s!=null&&s.length))return;const c=new Set([...t,...s??[]]);return Math.max(a??0,c.size)}export{Bi as default};