import{j as s,r as x}from"./vendor-tanstack-BVzzyDEt.js";import{cg as j,w,a3 as h,O as g,q as D,I as C,a2 as S}from"./index-BJkJ93Lr.js";import{D as y}from"./delete-confirmation-dialog-Baib9xiM.js";import{u as F}from"./use-delete-confirmation-dialog-DDTCxOIv.js";const k=()=>{const[o,t]=F(),{mutateAsync:n}=j(),a=async(u,i=()=>{})=>{try{const c=await Promise.allSettled(u.map(r=>n(r))),{numFails:l,numSuccess:e}=c.reduce((r,m)=>(m.status==="rejected"?r.numFails+=1:r.numSuccess+=1,r),{numFails:0,numSuccess:0});l>1?w.error(`${l} flow runs failed to delete`):l===1?w.error("Flow run failed to delete"):e>1?w.success(`${e} flow runs deleted`):w.success("Flow run deleted")}catch(c){console.error("Unknown error while deleting flow run.",c)}finally{i()}};return[o,(u,i=()=>{})=>t({title:"Delete Flow Runs",description:"Are you sure you want to delete selected flow runs?",onConfirm:()=>{a(u,i)}})]},T=({count:o=0,...t})=>"results"in t&&"setSelectedRows"in t&&"selectedRows"in t?s.jsx(R,{count:o,...t}):s.jsxs(h,{variant:"bodySmall",className:"text-muted-foreground",children:[o," ",g(o,"Flow run")]});function R({count:o=0,results:t=[],setSelectedRows:n,selectedRows:a}){const[d,u]=k(),i=x.useMemo(()=>t.map(({id:e})=>e),[t]),c=Array.from(a),l=()=>{const e=i.every(f=>a.has(f)),r=i.some(f=>a.has(f));let m=!1;return e?m=!0:r&&(m="indeterminate"),s.jsx(S,{className:"block",checked:m,onCheckedChange:f=>{n(f?new Set(i):new Set)},"aria-label":"Toggle all"})};return a.size>0?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(l,{}),s.jsxs(h,{variant:"bodySmall",className:"text-muted-foreground",children:[c.length," selected"]}),s.jsx(D,{"aria-label":"Delete rows",size:"icon",variant:"secondary",onClick:()=>{u(c,()=>n(new Set))},children:s.jsx(C,{id:"Trash2",className:"size-4"})})]}),s.jsx(y,{...d})]}):s.jsxs("div",{className:"flex items-center gap-2",children:[t&&n&&a&&s.jsx(S,{className:"block",checked:!1,onCheckedChange:e=>{n(new Set(e?i:void 0))},"aria-label":"Toggle all"}),s.jsxs(h,{variant:"bodySmall",className:"text-muted-foreground",children:[o," ",g(o,"Flow run")]})]})}const z=o=>{const[t,n]=x.useState(new Set(o)),a=l=>n(e=>new Set(e).add(l)),d=l=>n(e=>{const r=new Set(e);return r.delete(l),r});return[t,n,{addRow:a,removeRow:d,onSelectRow:(l,e)=>{e?a(l):d(l)},clearSet:()=>n(new Set)}]};export{T as F,z as u};
//# sourceMappingURL=use-flow-runs-selected-rows-DLxgsii4.js.map
