"use strict";const y=require("react");function S(s){let{initialItems:f=[],initialSelectedKeys:d,getKey:i=o=>{var m;return(m=o.id)!==null&&m!==void 0?m:o.key},filter:t,initialFilterText:e=""}=s,[l,r]=y.useState({items:f,selectedKeys:d==="all"?"all":new Set(d||[]),filterText:e}),n=y.useMemo(()=>t?l.items.filter(o=>t(o,l.filterText)):l.items,[l.items,l.filterText,t]);return{...l,items:n,...x({getKey:i},r),getItem(o){return l.items.find(m=>i(m)===o)}}}function x(s,f){let{cursor:d,getKey:i}=s;return{setSelectedKeys(t){f(e=>({...e,selectedKeys:t}))},addKeysToSelection(t){f(e=>e.selectedKeys==="all"?e:t==="all"?{...e,selectedKeys:"all"}:{...e,selectedKeys:new Set([...e.selectedKeys,...t])})},removeKeysFromSelection(t){f(e=>{if(t==="all")return{...e,selectedKeys:new Set};let l=e.selectedKeys==="all"?new Set(e.items.map(i)):new Set(e.selectedKeys);for(let r of t)l.delete(r);return{...e,selectedKeys:l}})},setFilterText(t){f(e=>({...e,filterText:t}))},insert(t,...e){f(l=>u(l,t,...e))},insertBefore(t,...e){f(l=>{let r=l.items.findIndex(n=>i?.(n)===t);if(r===-1)if(l.items.length===0)r=0;else return l;return u(l,r,...e)})},insertAfter(t,...e){f(l=>{let r=l.items.findIndex(n=>i?.(n)===t);if(r===-1)if(l.items.length===0)r=0;else return l;return u(l,r+1,...e)})},prepend(...t){f(e=>u(e,0,...t))},append(...t){f(e=>u(e,e.items.length,...t))},remove(...t){f(e=>{let l=new Set(t),r=e.items.filter(o=>!l.has(i(o))),n="all";if(e.selectedKeys!=="all"){n=new Set(e.selectedKeys);for(let o of t)n.delete(o)}return d==null&&r.length===0&&(n=new Set),{...e,items:r,selectedKeys:n}})},removeSelectedItems(){f(t=>{if(t.selectedKeys==="all")return{...t,items:[],selectedKeys:new Set};let e=t.selectedKeys,l=t.items.filter(r=>!e.has(i(r)));return{...t,items:l,selectedKeys:new Set}})},move(t,e){f(l=>{let r=l.items.findIndex(m=>i(m)===t);if(r===-1)return l;let n=l.items.slice(),[o]=n.splice(r,1);return n.splice(e,0,o),{...l,items:n}})},moveBefore(t,e){f(l=>{let r=l.items.findIndex(m=>i(m)===t);if(r===-1)return l;let o=(Array.isArray(e)?e:[...e]).map(m=>l.items.findIndex(c=>i(c)===m)).sort((m,c)=>m-c);return K(l,o,r)})},moveAfter(t,e){f(l=>{let r=l.items.findIndex(m=>i(m)===t);if(r===-1)return l;let o=(Array.isArray(e)?e:[...e]).map(m=>l.items.findIndex(c=>i(c)===m)).sort((m,c)=>m-c);return K(l,o,r+1)})},update(t,e){f(l=>{let r=l.items.findIndex(o=>i(o)===t);if(r===-1)return l;let n;return typeof e=="function"?n=e(l.items[r]):n=e,{...l,items:[...l.items.slice(0,r),n,...l.items.slice(r+1)]}})}}}function u(s,f,...d){return{...s,items:[...s.items.slice(0,f),...d,...s.items.slice(f)]}}function K(s,f,d){d-=f.filter(e=>e<d).length;let i=f.map(e=>({from:e,to:d++}));for(let e=0;e<i.length;e++){let l=i[e].from;for(let r=e;r<i.length;r++)i[r].from>l&&i[r].from--}for(let e=0;e<i.length;e++){let l=i[e];for(let r=i.length-1;r>e;r--){let n=i[r];n.from<l.to?l.to++:n.from++}}let t=s.items.slice();for(let e of i){let[l]=t.splice(e.from,1);t.splice(e.to,0,l)}return{...s,items:t}}exports.$0d86e9c8f07f9a7b$export$762f73dccccd255d=S;exports.$0d86e9c8f07f9a7b$export$79c0c687a5963b0a=x;
//# sourceMappingURL=useListData-DgCKbwHX.cjs.js.map
