"use strict";const y=require("react"),h=require("./SelectionManager-Bf1F6kPb.cjs.js");function M(i){const t=y.version.split(".");return parseInt(t[0],10)>=19?i:i?"true":void 0}class k{*[Symbol.iterator](){yield*this.iterable}get size(){return this._size}getKeys(){return this.keyMap.keys()}getKeyBefore(t){let e=this.keyMap.get(t);var l;return e&&(l=e.prevKey)!==null&&l!==void 0?l:null}getKeyAfter(t){let e=this.keyMap.get(t);var l;return e&&(l=e.nextKey)!==null&&l!==void 0?l:null}getFirstKey(){return this.firstKey}getLastKey(){return this.lastKey}getItem(t){var e;return(e=this.keyMap.get(t))!==null&&e!==void 0?e:null}at(t){const e=[...this.getKeys()];return this.getItem(e[t])}getChildren(t){let e=this.keyMap.get(t);return e?.childNodes||[]}constructor(t){this.keyMap=new Map,this.firstKey=null,this.lastKey=null,this.iterable=t;let e=n=>{if(this.keyMap.set(n.key,n),n.childNodes&&n.type==="section")for(let o of n.childNodes)e(o)};for(let n of t)e(n);let l=null,f=0,a=0;for(let[n,o]of this.keyMap)l?(l.nextKey=n,o.prevKey=l.key):(this.firstKey=n,o.prevKey=void 0),o.type==="item"&&(o.index=f++),(o.type==="section"||o.type==="item")&&a++,l=o,l.nextKey=void 0;this._size=a;var u;this.lastKey=(u=l?.key)!==null&&u!==void 0?u:null}}function m(i){let{filter:t,layoutDelegate:e}=i,l=h.$7af3f5b51489e0b5$export$253fe78d46329472(i),f=y.useMemo(()=>i.disabledKeys?new Set(i.disabledKeys):new Set,[i.disabledKeys]),a=y.useCallback($=>t?new k(t($)):new k($),[t]),u=y.useMemo(()=>({suppressTextValueWarning:i.suppressTextValueWarning}),[i.suppressTextValueWarning]),n=h.$7613b1592d41b092$export$6cd28814d92fa9c9(i,a,u),o=y.useMemo(()=>new h.$d496c0a20b6e58ec$export$6c8a5aaad13c9852(n,l,{layoutDelegate:e}),[n,l,e]);return x(n,o),{collection:n,disabledKeys:f,selectionManager:o}}function w(i,t){let e=y.useMemo(()=>t?i.collection.filter(t):i.collection,[i.collection,t]),l=i.selectionManager.withCollection(e);return x(e,l),{collection:e,selectionManager:l,disabledKeys:i.disabledKeys}}function x(i,t){const e=y.useRef(null);y.useEffect(()=>{if(t.focusedKey!=null&&!i.getItem(t.focusedKey)&&e.current){const d=e.current.getItem(t.focusedKey),K=[...e.current.getKeys()].map(v=>{const r=e.current.getItem(v);return r?.type==="item"?r:null}).filter(v=>v!==null),s=[...i.getKeys()].map(v=>{const r=i.getItem(v);return r?.type==="item"?r:null}).filter(v=>v!==null);var l,f;const g=((l=K?.length)!==null&&l!==void 0?l:0)-((f=s?.length)!==null&&f!==void 0?f:0);var a,u,n;let c=Math.min(g>1?Math.max(((a=d?.index)!==null&&a!==void 0?a:0)-g+1,0):(u=d?.index)!==null&&u!==void 0?u:0,((n=s?.length)!==null&&n!==void 0?n:0)-1),b=null,p=!1;for(;c>=0;){if(!t.isDisabled(s[c].key)){b=s[c];break}if(c<s.length-1&&!p)c++;else{p=!0;var o,$;c>((o=d?.index)!==null&&o!==void 0?o:0)&&(c=($=d?.index)!==null&&$!==void 0?$:0),c--}}t.setFocusedKey(b?b.key:null)}e.current=i},[i,t])}exports.$cdc5a6778b766db2$export$a9d04c5684123369=M;exports.$e72dd72e1c76a225$export$2f645645f7bca764=m;exports.$e72dd72e1c76a225$export$ba9d38c0f1bf2b36=w;
//# sourceMappingURL=useListState-CzO_maGH.cjs.js.map
