"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue"),W=require("../_util/props-util/index.js"),H=require("../_util/wave/index.js"),J=require("../config-provider/DisabledContext.js"),K=require("../config-provider/hooks/useConfigInject.js"),Q=require("../space/Compact.js"),X=require("../vc-util/devWarning.js"),Y=require("./LoadingIcon.js"),Z=require("./button-group.js"),M=require("./buttonTypes.js"),ee=require("./style/index.js"),te=require("../_util/props-util/initDefaultProps.js"),j=/^[\u4E00-\u9FA5]{2}$/,D=j.test.bind(j);function m(n){return n==="text"||n==="link"}const ne=t.defineComponent({compatConfig:{MODE:3},name:"AButton",inheritAttrs:!1,__ANT_BUTTON:!0,props:te.default(M.buttonProps(),{type:"default"}),slots:Object,setup(n,{slots:T,attrs:N,emit:$,expose:P}){const{prefixCls:c,autoInsertSpaceInButton:w,direction:q,size:R}=K.default("btn",n),[I,_]=ee.default(c),A=Z.GroupSizeContext.useInject(),O=J.useInjectDisabled(),g=t.computed(()=>n.disabled??O.value),r=t.shallowRef(null),f=t.shallowRef(void 0);let h=!1;const a=t.shallowRef(!1),i=t.shallowRef(!1),S=t.computed(()=>w.value!==!1),{compactSize:V,compactItemClassnames:E}=Q.useCompactItemContext(c,q),C=t.computed(()=>typeof n.loading=="object"&&n.loading.delay?n.loading.delay||!0:!!n.loading);t.watch(C,e=>{clearTimeout(f.value),typeof C.value=="number"?f.value=setTimeout(()=>{a.value=e},C.value):a.value=e},{immediate:!0});const U=t.computed(()=>{const{type:e,shape:u="default",ghost:d,block:l,danger:v}=n,o=c.value,p={large:"lg",small:"sm",middle:void 0},b=V.value||A?.size||R.value,s=b&&p[b]||"";return[E.value,{[_.value]:!0,[`${o}`]:!0,[`${o}-${u}`]:u!=="default"&&u,[`${o}-${e}`]:e,[`${o}-${s}`]:s,[`${o}-loading`]:a.value,[`${o}-background-ghost`]:d&&!m(e),[`${o}-two-chinese-chars`]:i.value&&S.value,[`${o}-block`]:l,[`${o}-dangerous`]:!!v,[`${o}-rtl`]:q.value==="rtl"}]}),k=()=>{const e=r.value;if(!e||w.value===!1)return;const u=e.textContent;h&&D(u)?i.value||(i.value=!0):i.value&&(i.value=!1)},F=e=>{if(a.value||g.value){e.preventDefault();return}$("click",e)},G=e=>{$("mousedown",e)},L=(e,u)=>{const d=u?" ":"";if(e.type===t.Text){let l=e.children.trim();return D(l)&&(l=l.split("").join(d)),t.createVNode("span",null,[l])}return e};return t.watchEffect(()=>{X.default(!(n.ghost&&m(n.type)),"Button","`link` or `text` button can't be a `ghost` button.")}),t.onMounted(k),t.onUpdated(k),t.onBeforeUnmount(()=>{f.value&&clearTimeout(f.value)}),P({focus:()=>{r.value?.focus()},blur:()=>{r.value?.blur()}}),()=>{const{icon:e=T.icon?.()}=n,u=W.flattenChildren(T.default?.());h=u.length===1&&!e&&!m(n.type);const{type:d,htmlType:l,href:v,title:o,target:p}=n,b=a.value?"loading":e,s={...N,title:o,disabled:g.value,class:[U.value,N.class,{[`${c.value}-icon-only`]:u.length===0&&!!b}],onClick:F,onMousedown:G};g.value||delete s.disabled;const z=e&&!a.value?e:t.createVNode(Y.default,{existIcon:!!e,prefixCls:c.value,loading:!!a.value},null),B=u.map(y=>L(y,h&&S.value));if(v!==void 0)return I(t.createVNode("a",{...s,href:v,target:p,ref:r},[z,B]));let x=t.createVNode("button",{...s,ref:r,type:l},[z,B]);if(!m(d)){const y=(function(){return x})();x=t.createVNode(H.default,{ref:"wave",disabled:!!a.value},{default:()=>[y]})}return I(x)}}});exports.buttonProps=M.buttonProps;exports.default=ne;
