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