import{aI as S,e1 as M}from"./app-k0jcl5PQ.js";import{u as I}from"./Bpw1_OdO.chunk.js";const F=(r,u={})=>{const{idField:s="id",persistNamespace:g}=u,c=u.initialState?u.initialState:new Map,t=S.useRef(c),f=M(),a=I(r),h=I(g);S.useEffect(()=>{if(u.initialState||g&&h===g)return;const e=a==null?void 0:a.map(d=>d[s]).join(),n=r==null?void 0:r.map(d=>d[s]).join();e!==n&&p()},[a,h,r,u.initialState]),S.useEffect(()=>{var e;(e=u.preselectedIds)!=null&&e.length&&m(u.preselectedIds)},[]);function p(){t.current.clear(),f()}function y(){const e=!k();r.forEach(n=>{e?t.current.set(n[s].toString(),!0):t.current.delete(n[s].toString())}),f()}function E(e){const n=!t.current.get(e.toString());n?t.current.set(e.toString(),n):t.current.delete(e.toString()),f()}function i(e){return typeof e=="number"?e=e.toString():typeof e!="string"&&(e=e[s].toString()),t.current.get(e)}function C(){return Array.from(t.current.keys())}function b(){r!=null&&r.length&&(r.forEach(e=>{t.current.delete(e[s].toString())}),f())}function v(){return r!=null&&r.length?!!r.find(e=>i(e)):!1}function k(){return r!=null&&r.length?r.every(i):!1}function m(e){e.forEach(n=>{t.current.set(n,!0)}),f()}function x(){return t.current.size}function B(){return t.current}return{onToggleBulk:y,onToggleItem:E,getSelected:C,isChecked:i,bulkChecked:k(),deselectAll:b,hasSomeSelections:v,setSelected:m,getSelectedCount:x,reset:p,getMap:B}};export{F as u};
//# sourceMappingURL=CyqCElfh.chunk.js.map
