function n(f,o){let a=f;for(;(a=a.parentElement)&&!a.matches(o););return a}function x(f,o,a){for(let r=f-1;r>=0;r-=1)if(!o[r].disabled)return r;if(a){for(let r=o.length-1;r>-1;r-=1)if(!o[r].disabled)return r}return f}function h(f,o,a){for(let r=f+1;r<o.length;r+=1)if(!o[r].disabled)return r;if(a){for(let r=0;r<o.length;r+=1)if(!o[r].disabled)return r}return f}function A(f,o,a){return n(f,a)===n(o,a)}function I({parentSelector:f,siblingSelector:o,onKeyDown:a,loop:r=!0,activateOnFocus:l=!1,dir:d="rtl",orientation:c}){return t=>{var k;a==null||a(t);const e=Array.from(((k=n(t.currentTarget,f))==null?void 0:k.querySelectorAll(o))||[]).filter(i=>A(t.currentTarget,i,f)),p=e.findIndex(i=>t.currentTarget===i),s=h(p,e,r),u=x(p,e,r),g=d==="rtl"?u:s,b=d==="rtl"?s:u;switch(t.key){case"ArrowRight":{c==="horizontal"&&(t.stopPropagation(),t.preventDefault(),e[g].focus(),l&&e[g].click());break}case"ArrowLeft":{c==="horizontal"&&(t.stopPropagation(),t.preventDefault(),e[b].focus(),l&&e[b].click());break}case"ArrowUp":{c==="vertical"&&(t.stopPropagation(),t.preventDefault(),e[u].focus(),l&&e[u].click());break}case"ArrowDown":{c==="vertical"&&(t.stopPropagation(),t.preventDefault(),e[s].focus(),l&&e[s].click());break}case"Home":{t.stopPropagation(),t.preventDefault(),!e[0].disabled&&e[0].focus();break}case"End":{t.stopPropagation(),t.preventDefault();const i=e.length-1;!e[i].disabled&&e[i].focus();break}}}}export{I as c,n as f};
