import e from"../vc-util/Dom/contains.mjs";import t from"../_util/classNames.mjs";import n from"../_util/omit.mjs";import r from"../_util/props-util/initDefaultProps.mjs";import i from"../_util/KeyCode.mjs";import a from"../_util/pickAttrs.mjs";import o from"./IDialogPropTypes.mjs";import{getMotionName as s,getUUID as c}from"./util.mjs";import l from"./Content.mjs";import u from"./Mask.mjs";import{createVNode as d,defineComponent as f,onBeforeUnmount as p,shallowRef as m,watch as h,watchEffect as g}from"vue";var _=f({compatConfig:{MODE:3},name:`VcDialog`,inheritAttrs:!1,props:r({...o(),getOpenCount:Function,scrollLocker:Object},{mask:!0,visible:!1,keyboard:!0,closable:!0,maskClosable:!0,destroyOnClose:!1,prefixCls:`rc-dialog`,getOpenCount:()=>null,focusTriggerAfterClose:!0}),setup(r,{attrs:o,slots:f}){let _=m(),v=m(),y=m(),b=m(r.visible),x=m(`vcDialogTitle${c()}`),S=t=>{if(t)e(v.value,document.activeElement)||(_.value=document.activeElement,y.value?.focus());else{let e=b.value;if(b.value=!1,r.mask&&_.value&&r.focusTriggerAfterClose){try{_.value.focus({preventScroll:!0})}catch{}_.value=null}e&&r.afterClose?.()}},C=e=>{r.onClose?.(e)},w=m(!1),T=m(),E=()=>{clearTimeout(T.value),w.value=!0},D=()=>{T.value=setTimeout(()=>{w.value=!1})},O=e=>{if(!r.maskClosable)return null;w.value?w.value=!1:v.value===e.target&&C(e)},k=e=>{if(r.keyboard&&e.keyCode===i.ESC){e.stopPropagation(),C(e);return}r.visible&&e.keyCode===i.TAB&&y.value.changeActive(!e.shiftKey)};return h(()=>r.visible,()=>{r.visible&&(b.value=!0)},{flush:`post`}),p(()=>{clearTimeout(T.value),r.scrollLocker?.unLock()}),g(()=>{r.scrollLocker?.unLock(),b.value&&r.scrollLocker?.lock()}),()=>{let{prefixCls:e,mask:i,visible:c,maskTransitionName:p,maskAnimation:m,zIndex:h,wrapClassName:g,rootClassName:_,wrapStyle:w,closable:T,maskProps:A,maskStyle:j,transitionName:M,animation:N,wrapProps:P,title:F=f.title}=r,{style:I,class:L}=o;return d(`div`,{class:[`${e}-root`,_],...a(r,{data:!0})},[d(u,{prefixCls:e,visible:i&&c,motionName:s(e,p,m),style:{zIndex:h,...j},maskProps:A},null),d(`div`,{tabIndex:-1,onKeydown:k,class:t(`${e}-wrap`,g),ref:v,onClick:O,role:`dialog`,"aria-labelledby":F?x.value:null,style:{zIndex:h,...w,display:b.value?null:`none`},...P},[d(l,{...n(r,[`scrollLocker`]),style:I,class:L,onMousedown:E,onMouseup:D,ref:y,closable:T,ariaId:x.value,prefixCls:e,visible:c,onClose:C,onVisibleChanged:S,motionName:s(e,M,N)},f)])])}}});export{_ as default};