import{l as j,m as R,k as y,n as w,F as C,i as b,o as S,p as A,f as T,D as v,q as O,s as P,C as k}from"./index-QQb7wQEC.js";import{a as E,c as F}from"./@tanstack-BUCbhJyH.js";import{o as N}from"./url-D5le3J4q.js";import{r as l,j as t}from"./@radix-DP6vWzyx.js";import{S as m}from"./trash-DkJHMOg7.js";import{u as q,D as x,a as g}from"./delete-run-D-LKbGyz.js";import{S as I}from"./dots-horizontal-DK5Duzx4.js";import{A as M}from"./AlertDialogDropdownItem-C6N2rGrB.js";function Q({params:e}){return["runs",e]}async function B({params:e}){const s=j(R.runs.all+"?"+N(e)),n=await y(s,{method:"GET",headers:{"Content-Type":"application/json"}});if(n.status===404&&w(),!n.ok)throw new C({message:"Error while fetching pipeline runs",status:n.status,statusText:n.statusText});return n.json()}function W(e,s){return E({queryKey:Q(e),queryFn:()=>B(e),...s})}const D=l.createContext(null);function X({children:e}){const[s,n]=l.useState([]),a=F(),{toast:r}=b(),u=q(),o=async i=>{try{const c=i.map(f=>u.mutateAsync({runId:f}));await Promise.all(c),r({description:"Deleted successfully.",status:"success",emphasis:"subtle",rounded:!0}),await a.invalidateQueries({queryKey:["runs"]}),n([])}catch(c){console.error("Failed to delete some runs:",c)}};return t.jsx(D.Provider,{value:{selectedRuns:s,setSelectedRuns:n,bulkDeleteRuns:o},children:e})}function h(){const e=l.useContext(D);if(!e)throw new Error("useRunsSelectorContext must be used within a RunsSelectorProvider");return e}function K(){const[e,s]=l.useState(!1),{bulkDeleteRuns:n,selectedRuns:a}=h();async function r(){await n(a),s(!1)}return t.jsxs(S,{open:e,onOpenChange:s,children:[t.jsx(A,{children:t.jsxs(T,{className:"rounded-sharp border-none bg-white",size:"md",emphasis:"subtle",intent:"secondary",children:[t.jsx(m,{className:"h-5 w-5 shrink-0 gap-1 fill-neutral-400"}),"Delete"]})}),t.jsx(x,{title:`Delete Run${a.length>=2?"s":""}`,handleDelete:r,children:t.jsxs(g,{children:[t.jsx("p",{children:"Are you sure?"}),t.jsx("p",{children:"This action cannot be undone."})]})})]})}function Y(){const{selectedRuns:e}=h();return t.jsxs("div",{className:"flex items-center divide-x divide-theme-border-moderate overflow-hidden rounded-md border border-theme-border-moderate",children:[t.jsx("div",{className:"bg-primary-25 px-2 py-1 font-semibold text-theme-text-brand",children:`${e==null?void 0:e.length} Run${(e==null?void 0:e.length)>1?"s":""} selected`}),t.jsx(K,{})]})}function Z({id:e}){const[s,n]=l.useState(!1),[a,r]=l.useState(!1),u=l.useRef(null),o=l.useRef(null),{bulkDeleteRuns:i}=h();async function c(){await i([e]),p(!1)}function f(){o.current=u.current}function p(d){if(d===!1){r(!1),setTimeout(()=>{n(d)},200);return}n(d)}return t.jsxs(v,{onOpenChange:r,open:a,children:[t.jsx(O,{ref:u,children:t.jsx(I,{className:"h-4 w-4 fill-theme-text-tertiary"})}),t.jsx(P,{hidden:s,onCloseAutoFocus:d=>{o.current&&(o.current.focus(),o.current=null,d.preventDefault())},align:"end",sideOffset:7,children:t.jsx(M,{onSelect:f,open:s,onOpenChange:p,triggerChildren:"Delete",icon:t.jsx(m,{fill:"red"}),children:t.jsx(x,{title:"Delete Run",handleDelete:c,children:t.jsxs(g,{children:[t.jsx("p",{children:"Are you sure?"}),t.jsx("p",{children:"This action cannot be undone."})]})})})})]})}const _=({id:e})=>{const{selectedRuns:s,setSelectedRuns:n}=h(),a=(r,u)=>{n(o=>r?[...o,u]:o.filter(i=>i!==u))};return t.jsx(k,{id:e,onCheckedChange:r=>a(r,e),checked:s.includes(e),className:"h-3 w-3"})};export{_ as R,Z as a,W as b,Y as c,X as d,h as u};
