import{defineComponent as p,shallowRef as i,onMounted as B,onBeforeUnmount as C,createVNode as h}from"vue";import"../button/index.mjs";import{convertLegacyProps as y}from"../button/buttonTypes.mjs";import g from"./hooks/useDestroyed.mjs";import{findDOMNode as O}from"./props-util/index.mjs";import{objectType as P}from"./type.mjs";import b from"../button/button.mjs";const R={type:{type:String},actionFn:Function,close:Function,autofocus:Boolean,prefixCls:String,buttonProps:P(),emitEvent:Boolean,quitOnNullishReturnValue:Boolean};function c(t){return!!(t&&t.then)}const M=p({compatConfig:{MODE:3},name:"ActionButton",props:R,setup(t,{slots:m}){const u=i(!1),a=i(),l=i(!1);let s;const f=g();B(()=>{t.autofocus&&(s=setTimeout(()=>O(a.value)?.focus?.()))}),C(()=>{clearTimeout(s)});const r=(...o)=>{t.close?.(...o)},v=o=>{c(o)&&(l.value=!0,o.then((...e)=>{f.value||(l.value=!1),r(...e),u.value=!1},e=>(f.value||(l.value=!1),u.value=!1,Promise.reject(e))))},d=o=>{const{actionFn:e}=t;if(u.value)return;if(u.value=!0,!e){r();return}let n;if(t.emitEvent){if(n=e(o),t.quitOnNullishReturnValue&&!c(n)){u.value=!1,r(o);return}}else if(e.length)n=e(t.close),u.value=!1;else if(n=e(),!n){r();return}v(n)};return()=>{const{type:o,prefixCls:e,buttonProps:n}=t;return h(b,{...y(o),onClick:d,loading:l.value,prefixCls:e,...n,ref:a},m)}}});export{M as default};
