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