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