import{bc as y,bb as S,aY as s,aU as N,aT as t,a2 as v,x as w,p as C,E,V as I,L as R,aE as u,g as q,c as F,N as L,aF as B}from"./chunk-02oqS8tD.js";import"./chunk-B8Q4vgLh.js";import"./chunk-x_Z6cwvR.js";const O={"failing-request":"grouped by the failing request","transport-failure":"grouped by a request that never completed","selector-failure":"grouped by the step that could not resolve","console-error":"grouped by the error the application logged","insufficient-evidence":"not enough evidence to group by cause"};function T(){const x=y(e=>e.go),l=S(e=>e.projectId),[n,b]=s.useState([]),[p,m]=s.useState(null),[h,g]=s.useState([]),[r,d]=s.useState("loading"),[j,f]=s.useState(""),o=s.useCallback(async()=>{d("loading");try{b([...await N(l===void 0?{}:{projectId:l})]),d("ready")}catch(e){f(e.message),d("error")}},[l]);s.useEffect(()=>{o()},[o]);const k=async e=>{if(p===e.failureSignature){m(null);return}m(e.failureSignature),g([]);try{g(await B(e.failureSignature))}catch(i){f(i.message)}};return t.jsxs(v,{title:"Failure clusters",subtitle:"Failures that share a cause, most frequent first.",onBack:()=>x({name:"tools"}),actions:t.jsx(F,{size:"sm",variant:"outline",className:"h-7",onClick:()=>void o(),title:"Refresh",children:t.jsx(L,{className:"h-3 w-3"})}),children:[r==="loading"&&t.jsx(w,{label:"Grouping failures…"}),r==="error"&&t.jsx(C,{title:"Could not load clusters",message:j,onRetry:()=>void o()}),r==="ready"&&n.length===0&&t.jsx(E,{title:"No failures to group",description:"No failed executions have been uploaded for this workspace yet. Clusters appear once there are failures to group."}),r==="ready"&&n.length>0&&t.jsx(I,{title:`Clusters · ${String(n.length)}`,children:t.jsx("div",{className:"space-y-1",children:n.map(e=>{const i=p===e.failureSignature,c=e.failureSummary?.basis;return t.jsxs("div",{className:"rounded-lg border border-stroke dark:border-stroke/30",children:[t.jsxs("button",{type:"button",onClick:()=>void k(e),className:"flex min-h-6 w-full items-start gap-2 px-2 py-1.5 text-left",children:[t.jsx(R,{className:"mt-0.5 h-3 w-3 shrink-0 text-alert-orange"}),t.jsxs("span",{className:"min-w-0 flex-1",children:[t.jsx("span",{className:"block break-words text-[10.5px] font-medium leading-snug",children:e.summary??e.title??"Unnamed failure"}),t.jsxs("span",{className:"mt-0.5 block font-mono text-[9px] text-muted-foreground",children:["first ",u(e.firstSeen)," · last ",u(e.lastSeen)]}),c&&t.jsx("span",{className:"mt-0.5 block text-[9px] leading-relaxed text-muted-foreground",children:O[c]??c})]}),t.jsx("span",{className:"shrink-0 font-mono text-[13px] font-semibold tabular-nums",children:e.count}),t.jsx(q,{className:i?"mt-0.5 h-3 w-3 shrink-0 rotate-90":"mt-0.5 h-3 w-3 shrink-0"})]}),i&&t.jsxs("div",{className:"space-y-1 border-t border-stroke px-2 py-1.5 dark:border-stroke/30",children:[t.jsxs("p",{className:"font-mono text-[9px] text-muted-foreground",children:[e.environments.length," environment",e.environments.length===1?"":"s"," ·"," ",e.workflows.length," workflow",e.workflows.length===1?"":"s",e.appVersions.length>0?` · ${e.appVersions.join(", ")}`:""]}),h.length===0&&t.jsx("p",{className:"text-[9.5px] text-muted-foreground",children:"Loading executions…"}),h.map(a=>t.jsxs("button",{type:"button",onClick:()=>x({name:"execution-detail",executionId:a.executionId}),className:"flex min-h-5 w-full items-baseline gap-2 rounded px-1 py-0.5 text-left hover:bg-stroke/15",children:[t.jsx("span",{className:"shrink-0 font-mono text-[9px] text-muted-foreground",children:u(a.startedAt)}),t.jsx("span",{className:"min-w-0 flex-1 truncate text-[10px]",children:a.title}),a.executionId===e.representativeExecutionId&&t.jsx("span",{className:"shrink-0 font-mono text-[8.5px] uppercase text-dynamic-azure",children:"latest"})]},a.executionId))]})]},e.failureSignature)})})})]})}export{T as FailureClustersScreen};
//# sourceMappingURL=chunk-CWqKe7Q9.js.map
