import{I as e,Q as t,b as n,g as r,gt as i,ut as a,x as o,yt as s,z as c}from"./vue.runtime.esm-bundler-DS0mm12S.js";import{X as l}from"./index-aDrlI3dP.js";import{D as u,O as d}from"./Teleport-CHY6zPT-.js";import{i as f}from"./button-DQxx5HZh.js";import{o as p,u as m}from"./PopperContent-uFA7BIqu.js";var h=`rovingFocusGroup.onEntryFocus`,g={bubbles:!1,cancelable:!0},_={ArrowLeft:`prev`,ArrowUp:`prev`,ArrowRight:`next`,ArrowDown:`next`,PageUp:`first`,Home:`first`,PageDown:`last`,End:`last`};function v(e,t){return t===`rtl`?e===`ArrowLeft`?`ArrowRight`:e===`ArrowRight`?`ArrowLeft`:e:e}function y(e,t,n){let r=v(e.key,n);if(!(t===`vertical`&&[`ArrowLeft`,`ArrowRight`].includes(r))&&!(t===`horizontal`&&[`ArrowUp`,`ArrowDown`].includes(r)))return _[r]}function b(e,t=!1){let n=u();for(let r of e)if(r===n||(r.focus({preventScroll:t}),u()!==n))return}function x(e,t){return e.map((n,r)=>e[(t+r)%e.length])}var[S,C]=d(`RovingFocusGroup`),w=o({__name:`RovingFocusGroup`,props:{orientation:{type:String,required:!1,default:void 0},dir:{type:String,required:!1},loop:{type:Boolean,required:!1,default:!1},currentTabStopId:{type:[String,null],required:!1},defaultCurrentTabStopId:{type:String,required:!1},preventScrollOnEntryFocus:{type:Boolean,required:!1,default:!1},asChild:{type:Boolean,required:!1},as:{type:null,required:!1}},emits:[`entryFocus`,`update:currentTabStopId`],setup(o,{expose:u,emit:d}){let _=o,v=d,{loop:y,orientation:x,dir:S}=i(_),w=m(S),T=l(_,`currentTabStopId`,v,{defaultValue:_.defaultCurrentTabStopId,passive:_.currentTabStopId===void 0}),E=a(!1),D=a(!1),O=a(0),{getItems:k,CollectionSlot:A}=p({isProvider:!0});function j(e){let t=!D.value;if(e.currentTarget&&e.target===e.currentTarget&&t&&!E.value){let t=new CustomEvent(h,g);if(e.currentTarget.dispatchEvent(t),v(`entryFocus`,t),!t.defaultPrevented){let e=k().map(e=>e.ref).filter(e=>e.dataset.disabled!==``);b([e.find(e=>e.getAttribute(`data-active`)===``),e.find(e=>e.getAttribute(`data-highlighted`)===``),e.find(e=>e.id===T.value),...e].filter(Boolean),_.preventScrollOnEntryFocus)}}D.value=!1}function M(){setTimeout(()=>{D.value=!1},1)}return u({getItems:k}),C({loop:y,dir:w,orientation:x,currentTabStopId:T,onItemFocus:e=>{T.value=e},onItemShiftTab:()=>{E.value=!0},onFocusableItemAdd:()=>{O.value++},onFocusableItemRemove:()=>{O.value--}}),(i,a)=>(e(),r(s(A),null,{default:t(()=>[n(s(f),{tabindex:E.value||O.value===0?-1:0,"data-orientation":s(x),as:i.as,"as-child":i.asChild,dir:s(w),style:{outline:`none`},onMousedown:a[0]||=e=>D.value=!0,onMouseup:M,onFocus:j,onBlur:a[1]||=e=>E.value=!1},{default:t(()=>[c(i.$slots,`default`)]),_:3},8,[`tabindex`,`data-orientation`,`as`,`as-child`,`dir`])]),_:3}))}});export{x as a,y as i,S as n,b as r,w as t};