"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue");require("../config-provider/index.js");require("../hooks/index.js");const h=require("./style/index.js"),f=require("./utils.js"),w=require("../config-provider/hooks/use-namespace.js"),B=require("../hooks/useControllableValue.js"),N=e.defineComponent({name:"ApMask",__name:"index",props:{open:{type:Boolean},"onUpdate:open":{},deleteOnClose:{type:Boolean},closable:{type:Boolean,default:!0},disabled:{type:Boolean},onBeforeClose:{},contentStyle:{type:[Boolean,null,String,Object,Array]},zIndex:{},escClosable:{type:Boolean,default:!0}},emits:["update:open"],setup(l,{emit:m}){const t=l,{b:s,e:d,em:p}=w.useNamespace("mask"),v=h.default("mask"),y=m,k=t.zIndex||f.getMaskZIndex(),{value:o,updateValue:u}=B.useControllableValue(t,y,{valuePropName:"open"}),r=e.ref(t.open);e.watch(()=>o.value,n=>{n&&(r.value=n)});const c=e.ref();e.watch(c,n=>{n&&n.addEventListener("wheel",a=>{a.stopPropagation(),a.preventDefault()})}),e.watchEffect(n=>{if(!o.value)return;const a=f.lockScrollable();n(()=>{a?.()})}),e.onMounted(()=>{document.addEventListener("keydown",i)}),e.onUnmounted(()=>{document.removeEventListener("keydown",i)});function C(){r.value=!1}async function b(){if(t.closable){if(t.onBeforeClose){await t.onBeforeClose()&&u(!1);return}u(!1)}}function i(n){!o.value||!(t.closable&&t.escClosable)||n.key==="Escape"&&u(!1)}return(n,a)=>!l.deleteOnClose||r.value?(e.openBlock(),e.createBlock(e.Teleport,{key:0,to:"body"},[e.createElementVNode("div",{ref_key:"wrapper",ref:c,class:e.normalizeClass([e.unref(s)(),e.unref(v)]),style:e.normalizeStyle({zIndex:e.unref(k),visibility:r.value?void 0:"hidden"})},[e.createVNode(e.Transition,{appear:"",name:e.unref(s)("fade"),onAfterLeave:C},{default:e.withCtx(()=>[e.unref(o)?(e.openBlock(),e.createElementBlock("div",{key:0,class:e.normalizeClass([e.unref(d)("mask"),{[e.unref(p)("mask","disabled")]:l.disabled}]),onClick:b},[e.renderSlot(n.$slots,"mask",{},()=>[e.createElementVNode("div",{class:e.normalizeClass(e.unref(d)("mask-inner"))},null,2)])],2)):e.createCommentVNode("",!0)]),_:3},8,["name"]),e.createElementVNode("div",{style:e.normalizeStyle(l.contentStyle)},[e.createVNode(e.Transition,{appear:"",name:e.unref(s)("fade")},{default:e.withCtx(()=>[e.unref(o)?e.renderSlot(n.$slots,"default",{key:0}):e.createCommentVNode("",!0)]),_:3},8,["name"])],4)],6)])):e.createCommentVNode("",!0)}});exports.default=N;
