import{g as p,dh as x,an as y,aE as g}from"./BoB2h2qv.js";let f=0;function b(){p(e=>{if(!x)return;const t=document.querySelectorAll("[data-reka-focus-guard]");document.body.insertAdjacentElement("afterbegin",t[0]??m()),document.body.insertAdjacentElement("beforeend",t[1]??m()),f++,e(()=>{f===1&&document.querySelectorAll("[data-reka-focus-guard]").forEach(a=>a.remove()),f--})})}function m(){const e=document.createElement("span");return e.setAttribute("data-reka-focus-guard",""),e.tabIndex=0,e.style.outline="none",e.style.opacity="0",e.style.position="fixed",e.style.pointerEvents="none",e}function V(e){const t=y("",1e3);return{search:t,handleTypeaheadSearch:(u,l)=>{t.value=t.value+u;{const r=g(),c=l.map(n=>({...n,textValue:n.value?.textValue??n.ref.textContent?.trim()??""})),s=c.find(n=>n.ref===r),o=c.map(n=>n.textValue),h=A(o,t.value,s?.textValue),i=c.find(n=>n.textValue===h);return i&&i.ref.focus(),i?.ref}},resetTypeahead:()=>{t.value=""}}}function v(e,t){return e.map((a,d)=>e[(t+d)%e.length])}function A(e,t,a){const u=t.length>1&&Array.from(t).every(o=>o===t[0])?t[0]:t,l=a?e.indexOf(a):-1;let r=v(e,Math.max(l,0));u.length===1&&(r=r.filter(o=>o!==a));const s=r.find(o=>o.toLowerCase().startsWith(u.toLowerCase()));return s!==a?s:void 0}export{b as a,V as u};
