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