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