import{defineComponent as P,shallowRef as l,onUpdated as U,computed as R,onMounted as S,watch as T,nextTick as k,onBeforeUnmount as L,createVNode as B}from"vue";import D from"./Portal.mjs";import m from"./canUseDom.mjs";import E from"./hooks/useScrollLocker.mjs";import h from"./raf.mjs";import{booleanType as F}from"./type.mjs";import I from"./vue-types/index.mjs";let n=0;const u=m(),N=e=>{if(!u)return null;if(e){if(typeof e=="string")return document.querySelectorAll(e)[0];if(typeof e=="function")return e();if(typeof e=="object"&&e instanceof window.HTMLElement)return e}return document.body},V=P({compatConfig:{MODE:3},name:"PortalWrapper",inheritAttrs:!1,props:{wrapperClassName:String,forceRender:{type:Boolean,default:void 0},getContainer:I.any,visible:{type:Boolean,default:void 0},autoLock:F(),didUpdate:Function},setup(e,{slots:w}){const t=l(),p=l(),v=l(),y=l(1),i=m()&&document.createElement("div"),b=()=>{t.value===i&&t.value?.parentNode?.removeChild(t.value),t.value=null};let r=null;const f=(o=!1)=>o||t.value&&!t.value.parentNode?(r=N(e.getContainer),r?(r.appendChild(t.value),!0):!1):!0,C=()=>u?(t.value||(t.value=i,f(!0)),g(),t.value):null,g=()=>{const{wrapperClassName:o}=e;t.value&&o&&o!==t.value.className&&(t.value.className=o)};return U(()=>{g(),f()}),E(R(()=>e.autoLock&&e.visible&&m()&&(t.value===document.body||t.value===i))),S(()=>{let o=!1;T([()=>e.visible,()=>e.getContainer],([c,a],[d,s])=>{u&&(r=N(e.getContainer),r===document.body&&(c&&!d?n+=1:o&&(n-=1))),o&&(typeof a=="function"&&typeof s=="function"?a.toString()!==s.toString():a!==s)&&b(),o=!0},{immediate:!0,flush:"post"}),k(()=>{f()||(v.value=h(()=>{y.value+=1}))})}),L(()=>{const{visible:o}=e;u&&r===document.body&&(n=o&&n?n-1:n),b(),h.cancel(v.value)}),()=>{const{forceRender:o,visible:c}=e;let a=null;const d={getOpenCount:()=>n,getContainer:C};return y.value&&(o||c||p.value)&&(a=B(D,{getContainer:C,ref:p,didUpdate:e.didUpdate},{default:()=>w.default?.(d)})),a}}});export{V as default};
