import{A as s,a as y,b as m,c as f,d as O,E as S,H as T}from"./C-DQPpgP.js";import{i as b}from"./B3p6J_mX.js";function C(t){return window.getComputedStyle(t).getPropertyValue("direction")}function D(t="ltr",n="horizontal"){return{horizontal:t==="rtl"?m:y,vertical:f}[n]}function F(t="ltr",n="horizontal"){return{horizontal:t==="rtl"?y:m,vertical:s}[n]}function W(t="ltr",n="horizontal"){return["ltr","rtl"].includes(t)||(t="ltr"),["horizontal","vertical"].includes(n)||(n="horizontal"),{nextKey:D(t,n),prevKey:F(t,n)}}function _(t){const n=O(null);function u(){if(!b)return[];const e=document.getElementById(t.rootNodeId.current);return e?t.candidateSelector?Array.from(e.querySelectorAll(t.candidateSelector)):t.candidateAttr?Array.from(e.querySelectorAll(`[${t.candidateAttr}]:not([data-disabled])`)):[]:[]}function v(){var r;const e=u();e.length&&((r=e[0])==null||r.focus())}function K(e,r,a=!1){var I;const g=document.getElementById(t.rootNodeId.current);if(!g||!e)return;const c=u();if(!c.length)return;const l=c.indexOf(e),N=C(g),{nextKey:h,prevKey:A}=W(N,t.orientation.current),x=t.loop.current,d={[h]:l+1,[A]:l-1,[T]:0,[S]:c.length-1};if(a){const z=h===f?y:f,E=A===s?m:s;d[z]=l+1,d[E]=l-1}let i=d[r.key];if(i===void 0)return;r.preventDefault(),i<0&&x?i=c.length-1:i===c.length&&x&&(i=0);const o=c[i];if(o)return o.focus(),n.current=o.id,(I=t.onCandidateFocus)==null||I.call(t,o),o}function R(e){const r=u(),a=n.current!==null;return e&&!a&&r[0]===e?(n.current=e.id,0):(e==null?void 0:e.id)===n.current?0:-1}return{setCurrentTabStopId(e){n.current=e},getTabIndex:R,handleKeydown:K,focusFirstCandidate:v,currentTabStopId:n}}export{_ as u};
