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