import{a as e,b as t}from"./vendor-zU9dkAB-.js";function n(e){if(e&&"object"==typeof e){const t=e.name;if("string"==typeof t&&t.length>0)return t}return String(e??"")}function l(l){const o=l.getKey??n,[i,s]=e(l.initialSelectionMode??!1),[c,r]=e(new Set),[a,f]=e(null),h=(e,t)=>{const n=new Set(e);r(n);const o=l.items();if(0===n.size||null===t||0===o.length)return void f(null);const i=o.length-1;f(Math.max(0,Math.min(t,i)))},u=()=>{h(new Set,null)},d=(e,t,n)=>{const i=l.items();if(!i.length)return void u();const s=i.length-1,r=Math.max(0,Math.min(e,s)),a=Math.max(0,Math.min(t,s)),f=Math.min(r,a),d=Math.max(r,a),g=new Set(c());for(let l=f;l<=d;l++){const e=o(i[l]);e&&(n?g.add(e):g.delete(e))}h(g,a)},g=t(()=>{const e=l.items();if(!e.length)return!1;const t=c();for(const n of e){const e=o(n);if(!e||!t.has(e))return!1}return!0});return{selected:c,selectionMode:i,setSelectionMode:e=>s("function"==typeof e?t=>e(t):e),lastAnchorIndex:a,setSelection:h,clearSelection:u,updateSelectionRange:d,updateSelectionSingle:(e,t)=>{d(e,e,t)},toggleSelectAll:()=>{const e=l.items();if(!e.length)return void u();const t=e.map(o).filter(Boolean),n=c();t.every(e=>n.has(e))?u():h(new Set(t),e.length-1)},allSelected:g,isSelected:e=>c().has(e),reconcile:()=>{const e=l.items();if(0===e.length)return void(c().size>0&&u());const t=new Set(e.map(o).filter(e=>Boolean(e))),n=c();let i=!1;const s=new Set;for(const l of n)t.has(l)?s.add(l):i=!0;const r=a(),f=null!==r&&r>=e.length;if(!i&&!f)return;let d=null;if(s.size>0){if(null!==r&&!f){const t=o(e[r]);t&&s.has(t)&&(d=r)}if(null===d)for(let t=e.length-1;t>=0;t--){const n=o(e[t]);if(n&&s.has(n)){d=t;break}}null===d&&(d=e.length-1)}h(s,d)}}}export{l as u};
