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