import{r as b,j as e}from"./query-Bw69rE6b.js";import{r as j,c as f}from"./index-CoUu6FiM.js";import{S as y}from"./StatusPill-DBEWzsQ3.js";function w({jobId:r,kind:a,onCancel:i,onTerminal:l}){const m=a==="runs"||a==="apply"?`/api/${a}/${r}/events`:`/api/runs/${r}/events`,{events:n,closed:p,error:o}=j({path:m}),t=b.useMemo(()=>n.find(c=>/^job\./.test(c.type)),[n]);t&&l&&l(t);const d=n.filter(c=>c.type==="writeback.progress"),s=d[d.length-1],x=s?Math.round(Number(s.done||0)/Math.max(1,Number(s.total||1))*100):0,u=t?t.type==="job.done"?"positive":t.type==="job.cancelled"?"warning":"critical":"accent",h=t?t.type==="job.done"?"Done":t.type==="job.cancelled"?"Cancelled":"Failed":"Running";return e.jsxs("section",{className:f("rounded-xl border bg-surface-raised p-4 shadow-card",t?.type==="job.failed"?"border-critical/40":"border-surface-border"),children:[e.jsxs("header",{className:"mb-2 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{tone:u,children:h}),e.jsxs("span",{className:"font-mono text-xs text-ink-dim",children:["#",r.slice(0,8)]})]}),!p&&i&&e.jsx("button",{type:"button",onClick:i,className:"rounded-md bg-surface-subtle px-2 py-1 text-xs text-ink-muted hover:bg-critical/10 hover:text-critical",children:"Cancel"})]}),s&&!t&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between text-[11px] text-ink-dim",children:[e.jsxs("span",{children:[String(s.schema),".",String(s.table),s.column?`.${String(s.column)}`:""]}),e.jsx("span",{children:`${s.done}/${s.total}`})]}),e.jsx("div",{className:"h-1.5 w-full overflow-hidden rounded-full bg-surface-subtle",children:e.jsx("div",{className:"h-full bg-accent transition-all",style:{width:`${x}%`}})})]}),o&&e.jsx("div",{className:"mt-2 text-xs text-critical",children:o}),t&&e.jsxs("div",{className:"mt-2 space-y-1 text-xs text-ink-muted",children:[t.type==="job.done"&&e.jsxs("span",{children:["Applied"," ",e.jsx("span",{className:"font-medium text-ink",children:t.summary?.applied??0})," ","row(s)."]}),t.type==="job.cancelled"&&e.jsxs("span",{children:["Stopped at"," ",e.jsx("span",{className:"font-medium text-ink",children:t.summary?.applied??0})," ","row(s) — already-written comments are kept."]}),t.type==="job.failed"&&e.jsx("span",{className:"text-critical",children:String(t.error||"Worker failed")})]})]})}export{w as J};
