import{w as S}from"./use-outside-click.0a4bdcf3.js";import{r as d,B as E,g as p,z as c,C as f,j,s as x,A as y,S as b,aj as B,ak as H}from"./entry.eb978f24.js";import{c as k,m as v}from"./focus-management.165c4009.js";import{H as h,o as w}from"./dom.2ed3c503.js";import{a as F,f as L}from"./hidden.a9dcbbf7.js";var M=(e=>(e[e.Forwards=0]="Forwards",e[e.Backwards=1]="Backwards",e))(M||{});function $(){let e=d(0);return S("keydown",t=>{t.key==="Tab"&&(e.value=t.shiftKey?1:0)}),e}function q(e,t,n,r){k.isServer||E(s=>{e=e??window,e.addEventListener(t,n,r),s(()=>e.removeEventListener(t,n,r))})}let T=Symbol("ForcePortalRootContext");function O(){return f(T,!1)}let z=p({name:"ForcePortalRoot",props:{as:{type:[Object,String],default:"template"},force:{type:Boolean,default:!1}},setup(e,{slots:t,attrs:n}){return c(T,e.force),()=>{let{force:r,...s}=e;return h({theirProps:s,ourProps:{},slot:{},slots:t,attrs:n,name:"ForcePortalRoot"})}}});function R(e){let t=v(e);if(!t){if(e===null)return null;throw new 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)}let D=p({name:"Portal",props:{as:{type:[Object,String],default:"div"}},setup(e,{slots:t,attrs:n}){let r=d(null),s=j(()=>v(r)),a=O(),u=f(C,null),l=d(a===!0||u==null?R(r.value):u.resolveTarget());E(()=>{a||u!=null&&(l.value=u.resolveTarget())});let o=f(m,null);return x(()=>{let i=w(r);i&&o&&y(o.register(i))}),y(()=>{var i,P;let g=(i=s.value)==null?void 0:i.getElementById("headlessui-portal-root");g&&l.value===g&&l.value.children.length<=0&&((P=l.value.parentElement)==null||P.removeChild(l.value))}),()=>{if(l.value===null)return null;let i={ref:r,"data-headlessui-portal":""};return b(B,{to:l.value},h({ourProps:i,theirProps:e,slot:{},attrs:n,slots:t,name:"Portal"}))}}}),m=Symbol("PortalParentContext");function K(){let e=f(m,null),t=d([]);function n(a){return t.value.push(a),e&&e.register(a),()=>r(a)}function r(a){let u=t.value.indexOf(a);u!==-1&&t.value.splice(u,1),e&&e.unregister(a)}let s={register:n,unregister:r,portals:t};return[t,p({name:"PortalWrapper",setup(a,{slots:u}){return c(m,s),()=>{var l;return(l=u.default)==null?void 0:l.call(u)}}})]}let C=Symbol("PortalGroupContext"),V=p({name:"PortalGroup",props:{as:{type:[Object,String],default:"template"},target:{type:Object,default:null}},setup(e,{attrs:t,slots:n}){let r=H({resolveTarget(){return e.target}});return c(C,r),()=>{let{target:s,...a}=e;return h({theirProps:a,ourProps:{},slot:{},attrs:t,slots:n,name:"PortalGroup"})}}});function W({defaultContainers:e=[],portals:t,mainTreeNodeRef:n}={}){let r=d(null),s=v(r);function a(){var u;let l=[];for(let o of e)o!==null&&(o instanceof HTMLElement?l.push(o):"value"in o&&o.value instanceof HTMLElement&&l.push(o.value));if(t!=null&&t.value)for(let o of t.value)l.push(o);for(let o of(u=s?.querySelectorAll("html > *, body > *"))!=null?u:[])o!==document.body&&o!==document.head&&o instanceof HTMLElement&&o.id!=="headlessui-portal-root"&&(o.contains(w(r))||l.some(i=>o.contains(i))||l.push(o));return l}return{resolveContainers:a,contains(u){return a().some(l=>l.contains(u))},mainTreeNodeRef:r,MainTreeNode(){return n!=null?null:b(L,{features:F.Hidden,ref:r})}}}export{q as E,z as P,D as U,K as V,V as _,M as d,$ as n,W as p};
