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