import{r as l}from"./index-BP8_t0zE.js";import{Z as h,$ as x}from"./defaultI18nProvider-C_r1y4tu.js";var s=function(u,e,o){if(o||arguments.length===2)for(var t=0,c=e.length,a;t<c;t++)(a||!(t in e))&&(a||(a=Array.prototype.slice.call(e,0,t)),a[t]=e[t]);return u.concat(a||Array.prototype.slice.call(e))},M=function(u){var e=u.resource,o=e===void 0?"":e,t=u.disableSyncWithStore,c=t===void 0?!1:t,a="".concat(o,".selectedIds"),d=l.useState(v),I=d[0],p=d[1],S=h(a,v),_=S[0],A=S[1],y=C(a),b=c?I:_,f=c?p:A,m=l.useCallback(function(){c?p(v):y()},[c,y]),g=l.useMemo(function(){return{select:function(r){r&&f(s([],r,!0))},unselect:function(r){!r||r.length===0||f(function(n){return Array.isArray(n)?n.filter(function(i){return!r.includes(i)}):[]})},toggle:function(r){typeof r>"u"||f(function(n){if(!Array.isArray(n))return s([],n,!0);var i=n.indexOf(r);return i>-1?s(s([],n.slice(0,i),!0),n.slice(i+1),!0):s(s([],n,!0),[r],!1)})},clearSelection:function(){m()}}},[f,m]);return[b,g]},v=[],C=function(u){var e=x().removeItem;return l.useCallback(function(o){if(typeof o>"u"&&typeof u>"u")throw new Error("You must provide a key to remove an item from the store");return e(o??u)},[e,u])};export{M as u};
