import{r as a,j as e}from"./@radix-AvWw-1nd.js";import{S as p}from"./trash-B_JgTgqd.js";import{D as x,a as D}from"./DeleteAlertDialog-CTLRrcFM.js";import{i as j,v as R,w as C,f as w,D as b,x as y,y as S,C as v,E as A}from"./index-DWoLoYDY.js";import{A as O}from"./AlertDialogDropdownItem-XL2NfFgP.js";import{u as k}from"./delete-run-CzPWbsBy.js";import{c as T}from"./@tanstack-CcI3lvwB.js";const g=a.createContext(null);function z({children:n}){const[s,r]=a.useState([]),l=T(),{toast:t}=j(),u=k(),o=async i=>{try{const c=i.map(f=>u.mutateAsync({runId:f}));await Promise.all(c),t({description:"Deleted successfully.",status:"success",emphasis:"subtle",rounded:!0}),await l.invalidateQueries({queryKey:["runs"]}),r([])}catch(c){console.error("Failed to delete some runs:",c)}};return e.jsx(g.Provider,{value:{selectedRuns:s,setSelectedRuns:r,bulkDeleteRuns:o},children:n})}function h(){const n=a.useContext(g);if(!n)throw new Error("useRunsSelectorContext must be used within a RunsSelectorProvider");return n}function N(){const[n,s]=a.useState(!1),{bulkDeleteRuns:r,selectedRuns:l}=h();async function t(){await r(l),s(!1)}return e.jsxs(R,{open:n,onOpenChange:s,children:[e.jsx(C,{children:e.jsxs(w,{className:"rounded-sharp border-none bg-white",size:"md",emphasis:"subtle",intent:"secondary",children:[e.jsx(p,{className:"h-5 w-5 shrink-0 gap-1 fill-neutral-400"}),"Delete"]})}),e.jsx(x,{title:`Delete Run${l.length>=2?"s":""}`,handleDelete:t,children:e.jsxs(D,{children:[e.jsx("p",{children:"Are you sure?"}),e.jsx("p",{children:"This action cannot be undone."})]})})]})}function F(){const{selectedRuns:n}=h();return e.jsxs("div",{className:"flex items-center divide-x divide-theme-border-moderate overflow-hidden rounded-md border border-theme-border-moderate",children:[e.jsx("div",{className:"bg-primary-25 px-2 py-1 font-semibold text-theme-text-brand",children:`${n==null?void 0:n.length} Run${(n==null?void 0:n.length)>1?"s":""} selected`}),e.jsx(N,{})]})}function H({id:n}){const[s,r]=a.useState(!1),[l,t]=a.useState(!1),u=a.useRef(null),o=a.useRef(null),{bulkDeleteRuns:i}=h();async function c(){await i([n]),m(!1)}function f(){o.current=u.current}function m(d){if(d===!1){t(!1),setTimeout(()=>{r(d)},200);return}r(d)}return e.jsxs(b,{onOpenChange:t,open:l,children:[e.jsx(y,{ref:u,children:e.jsx(S,{className:"h-4 w-4 fill-theme-text-tertiary"})}),e.jsx(v,{hidden:s,onCloseAutoFocus:d=>{o.current&&(o.current.focus(),o.current=null,d.preventDefault())},align:"end",sideOffset:7,children:e.jsx(O,{onSelect:f,open:s,onOpenChange:m,triggerChildren:"Delete",icon:e.jsx(p,{fill:"red"}),children:e.jsx(x,{title:"Delete Run",handleDelete:c,children:e.jsxs(D,{children:[e.jsx("p",{children:"Are you sure?"}),e.jsx("p",{children:"This action cannot be undone."})]})})})})]})}const Q=({id:n})=>{const{selectedRuns:s,setSelectedRuns:r}=h(),l=(t,u)=>{r(o=>t?[...o,u]:o.filter(i=>i!==u))};return e.jsx(A,{id:n,onCheckedChange:t=>l(t,n),checked:s.includes(n),className:"h-3 w-3"})};export{z as R,Q as a,H as b,F as c,h as u};
