import{r as m,c as x,j as a}from"./@radix-B1sy0Lhr.js";import{h}from"./@tanstack-Dwlisomv.js";import{v as j}from"./index-CO6UN3UX.js";function g(){const t=m.createContext(null);function s(){const r=x.useContext(t);if(!r)throw new Error("DataTableConsumerContext must be used within its Provider");return r}function i({children:r}){const[n,d]=m.useState({}),o=C(n),c=o.length;return a.jsx(t.Provider,{value:{rowSelection:n,setRowSelection:d,selectedRowIDs:o,selectedRowCount:c},children:r})}return{Context:t,ContextProvider:i,useContext:s}}function C(t){return Object.entries(t).filter(([s,i])=>i).map(([s])=>s)}function v({deleteFn:t,queryKeyToInvalidate:s,setRowSelection:i}){const r=h(),{toast:n}=j();async function d(o){if(o.length)try{const l=(await Promise.allSettled(o.map(e=>t(e)))).map((e,u)=>({id:o[u],status:e.status,error:e.status==="rejected"?e.reason:null})).filter(e=>e.status==="rejected"),p=Object.fromEntries(l.map(e=>[e.id,!0]));if(i(p),l.length===0)n({description:"All items deleted successfully.",status:"success",emphasis:"subtle",rounded:!0});else{const e=l.length;console.error(`Failed to delete items:
`,l.map(({id:u,error:f})=>`${u}: ${f}`).join(`
`)),n({status:"error",emphasis:"subtle",description:a.jsxs("p",{children:["Failed to delete ",e," item",e>1?"s":"",":",l.map(({id:u})=>a.jsxs(a.Fragment,{children:[a.jsx("br",{}),a.jsx("span",{children:u})]},u))]}),rounded:!0})}await r.invalidateQueries({queryKey:s})}catch(c){console.error("Bulk delete operation failed:",c),n({status:"error",emphasis:"subtle",description:"Bulk delete operation failed unexpectedly",rounded:!0})}}return{bulkDelete:d}}export{g as c,v as u};
