import{A as e,E as t,L as n,O as r,Q as i,R as a,T as o,V as s,Z as c,dt as l,f as u,h as d,ut as f}from"./vue.runtime.esm-bundler-DAWRyTnP.js";import{n as p,t as m}from"./hidden-B1N4-IcY.js";import{_ as h,b as g,n as _,v}from"./keyboard-BsJsGVTq.js";import{o as y}from"./open-closed-X3e8sDI4.js";function b(e,t,n,r){v.isServer||i(i=>{e??=window,e.addEventListener(t,n,r),i(()=>e.removeEventListener(t,n,r))})}var x=(e=>(e[e.Forwards=0]=`Forwards`,e[e.Backwards=1]=`Backwards`,e))(x||{});function S(){let e=l(0);return y(`keydown`,t=>{t.key===`Tab`&&(e.value=t.shiftKey?1:0)}),e}function C({defaultContainers:e=[],portals:t,mainTreeNodeRef:n}={}){let i=l(null),a=h(i);function o(){let n=[];for(let t of e)t!==null&&(t instanceof HTMLElement?n.push(t):`value`in t&&t.value instanceof HTMLElement&&n.push(t.value));if(t!=null&&t.value)for(let e of t.value)n.push(e);for(let e of a?.querySelectorAll(`html > *, body > *`)??[])e!==document.body&&e!==document.head&&e instanceof HTMLElement&&e.id!==`headlessui-portal-root`&&(e.contains(g(i))||e.contains(g(i)?.getRootNode()?.host)||n.some(t=>e.contains(t))||n.push(e));return n}return{resolveContainers:o,contains(e){return o().some(t=>t.contains(e))},mainTreeNodeRef:i,MainTreeNode(){return n==null?r(m,{features:p.Hidden,ref:i}):null}}}function w(){let e=l(null);return{mainTreeNodeRef:e,MainTreeNode(){return r(m,{features:p.Hidden,ref:e})}}}var T=Symbol(`ForcePortalRootContext`);function E(){return e(T,!1)}var D=o({name:`ForcePortalRoot`,props:{as:{type:[Object,String],default:`template`},force:{type:Boolean,default:!1}},setup(e,{slots:t,attrs:n}){return s(T,e.force),()=>{let{force:r,...i}=e;return _({theirProps:i,ourProps:{},slot:{},slots:t,attrs:n,name:`ForcePortalRoot`})}}});function O(e){let t=h(e);if(!t){if(e===null)return null;throw Error(`[Headless UI]: Cannot find ownerDocument for contextElement: ${e}`)}let n=t.getElementById(`headlessui-portal-root`);if(n)return n;let r=t.createElement(`div`);return r.setAttribute(`id`,`headlessui-portal-root`),t.body.appendChild(r)}var k=new WeakMap;function A(e){return k.get(e)??0}function j(e,t){let n=t(A(e));return n<=0?k.delete(e):k.set(e,n),n}var M=o({name:`Portal`,props:{as:{type:[Object,String],default:`div`}},setup(o,{slots:s,attrs:f}){let p=l(null),m=d(()=>h(p)),v=E(),y=e(F,null),b=l(v===!0||y==null?O(p.value):y.resolveTarget());b.value&&j(b.value,e=>e+1);let x=l(!1);n(()=>{x.value=!0}),i(()=>{v||y!=null&&(b.value=y.resolveTarget())});let S=e(N,null),C=!1,w=t();return c(p,()=>{if(C||!S)return;let e=g(p);e&&(a(S.register(e),w),C=!0)}),a(()=>{var e;let t=m.value?.getElementById(`headlessui-portal-root`);!t||b.value!==t||j(b.value,e=>e-1)||b.value.children.length>0||(e=b.value.parentElement)==null||e.removeChild(b.value)}),()=>{if(!x.value||b.value===null)return null;let e={ref:p,"data-headlessui-portal":``};return r(u,{to:b.value},_({ourProps:e,theirProps:o,slot:{},attrs:f,slots:s,name:`Portal`}))}}}),N=Symbol(`PortalParentContext`);function P(){let t=e(N,null),n=l([]);function r(e){return n.value.push(e),t&&t.register(e),()=>i(e)}function i(e){let r=n.value.indexOf(e);r!==-1&&n.value.splice(r,1),t&&t.unregister(e)}let a={register:r,unregister:i,portals:n};return[n,o({name:`PortalWrapper`,setup(e,{slots:t}){return s(N,a),()=>t.default?.call(t)}})]}var F=Symbol(`PortalGroupContext`),I=o({name:`PortalGroup`,props:{as:{type:[Object,String],default:`template`},target:{type:Object,default:null}},setup(e,{attrs:t,slots:n}){return s(F,f({resolveTarget(){return e.target}})),()=>{let{target:r,...i}=e;return _({theirProps:i,ourProps:{},slot:{},attrs:t,slots:n,name:`PortalGroup`})}}});export{C as a,S as c,D as i,b as l,P as n,w as o,I as r,x as s,M as t};