import{j as e}from"./vendor-motion-DtkLES98.js";import{a as l,d as o,F as N}from"./vendor-icons-Chitvt0Q.js";import{b,d as v,e as R,k as y,L as _,B as n,C as i,s as w,f as C,c as L,g as k,P as m,R as E}from"./index-BE8hoqa3.js";import"./vendor-react-CnbABWH8.js";function F(){const c=b(),[t,u]=l.useState(null),[a,r]=l.useState(null),[h,d]=l.useState("");l.useEffect(()=>{if(!t){r(null),d("");return}v(t).then(r).catch(()=>r(null)),R(t).then(s=>d(s.log||"")).catch(()=>d(""))},[t]);const p=l.useCallback(async s=>{confirm(`Kill run ${s}?`)&&await y(s)},[]);if(c._loading)return e.jsx(_,{label:"Loading runs…"});const j=c.active,x=c.recent,g=[...j.map(s=>({idea_id:s.idea_id,status:"RUNNING",host:s.host,gpu:s.gpu,elapsed_min:s.elapsed_min,title:s.title})),...x];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h2",{className:"text-lg font-bold",children:"Runs"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(n,{color:"blue",children:[j.length," running"]}),e.jsxs(n,{color:"green",children:[x.filter(s=>s.status==="COMPLETED").length," completed"]}),e.jsxs(n,{color:"red",children:[x.filter(s=>s.status==="FAILED"||s.status==="ERROR").length," failed"]})]})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-3",children:[e.jsxs("div",{className:"lg:col-span-2 space-y-2",children:[g.length===0&&e.jsx(i,{children:e.jsx("p",{className:"text-sm text-gray-500",children:"No runs yet"})}),g.map(s=>e.jsx(i,{onClick:()=>u(s.idea_id),className:t===s.idea_id?"border-purple-500/30":"",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(n,{color:w(s.status),children:s.status}),e.jsx("span",{className:"text-sm font-medium",children:C(s.idea_id,s.title)})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[s.host&&e.jsx("span",{className:"text-[10px] text-gray-500",children:s.host}),s.gpu!=null&&e.jsxs("span",{className:"text-[10px] text-gray-500",children:["GPU ",s.gpu]}),e.jsx("span",{className:"text-[10px] text-gray-500",children:L(s.elapsed_min)}),s.metric!=null&&e.jsx("span",{className:"text-xs font-mono text-emerald-400",children:k(s.metric)}),s.status==="RUNNING"&&e.jsxs("button",{onClick:f=>{f.stopPropagation(),p(s.idea_id)},className:"flex items-center gap-1 rounded px-2 py-0.5 text-[10px] text-red-400 hover:bg-red-500/10 transition-colors",children:[e.jsx(o,{size:10})," Kill"]})]})]})},s.idea_id))]}),e.jsx("div",{className:"space-y-4",children:t?e.jsxs(e.Fragment,{children:[e.jsxs(i,{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("h3",{className:"text-sm font-bold",children:t}),e.jsx("button",{onClick:()=>u(null),className:"text-gray-500 hover:text-white",children:e.jsx(o,{size:14})})]}),a?e.jsxs("div",{className:"space-y-2 text-xs",children:[a.claim&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(m,{label:"Host",value:a.claim.claimed_by}),e.jsx(m,{label:"GPU",value:a.claim.gpu}),e.jsx(m,{label:"Claimed At",value:a.claim.claimed_at})]}),a.metrics&&e.jsx(E,{title:"Metrics",defaultOpen:!0,children:e.jsx("pre",{className:"text-[10px] text-gray-400 whitespace-pre-wrap overflow-auto max-h-48",children:JSON.stringify(a.metrics,null,2)})}),e.jsxs("button",{onClick:()=>p(t),className:"flex items-center gap-1.5 rounded-lg bg-red-500/10 px-3 py-1.5 text-xs font-medium text-red-400 hover:bg-red-500/20 transition-colors border border-red-500/20 mt-2",children:[e.jsx(o,{size:12})," Kill Run"]})]}):e.jsx("p",{className:"text-xs text-gray-500",children:"Loading..."})]}),h&&e.jsxs(i,{children:[e.jsxs("h3",{className:"mb-2 text-sm font-bold flex items-center gap-2",children:[e.jsx(N,{size:14})," Log"]}),e.jsx("pre",{className:"text-[10px] text-gray-400 whitespace-pre-wrap overflow-auto max-h-96 font-mono",children:h})]})]}):e.jsx(i,{children:e.jsx("p",{className:"text-xs text-gray-500",children:"Select a run to view details"})})})]})]})}export{F as default};
