import{tuple as e,withInstall as t}from"../_util/type.mjs";import n from"../_util/warning.mjs";import r from"../_util/omit.mjs";import{useInjectDisabled as i}from"../config-provider/DisabledContext.mjs";import{getPropsSlot as a}from"../_util/props-util/index.mjs";import o from"../config-provider/hooks/useConfigInject.mjs";import s from"../_util/vue-types/index.mjs";import{useInjectFormItemContext as c}from"../form/FormItemContext.mjs";import l from"../_util/KeyCode.mjs";import u from"../_util/wave/index.mjs";import d from"./style/index.mjs";import{computed as f,createVNode as p,defineComponent as m,nextTick as h,onBeforeMount as g,onMounted as _,ref as v,watch as y}from"vue";import{LoadingOutlined as b}from"@antsoo-lib/icons";var x=e(`small`,`default`),S=()=>({id:String,prefixCls:String,size:s.oneOf(x),disabled:{type:Boolean,default:void 0},checkedChildren:s.any,unCheckedChildren:s.any,tabindex:s.oneOfType([s.string,s.number]),autofocus:{type:Boolean,default:void 0},loading:{type:Boolean,default:void 0},checked:s.oneOfType([s.string,s.number,s.looseBool]),checkedValue:s.oneOfType([s.string,s.number,s.looseBool]).def(!0),unCheckedValue:s.oneOfType([s.string,s.number,s.looseBool]).def(!1),onChange:{type:Function},onClick:{type:Function},onKeydown:{type:Function},onMouseup:{type:Function},"onUpdate:checked":{type:Function},onBlur:Function,onFocus:Function}),C=t(m({compatConfig:{MODE:3},name:`ASwitch`,__ANT_SWITCH:!0,inheritAttrs:!1,props:S(),slots:Object,setup(e,{attrs:t,slots:s,expose:m,emit:x}){let S=c(),C=i(),w=f(()=>e.disabled??C.value);g(()=>{n(!(`defaultChecked`in t),`Switch`,`'defaultChecked' is deprecated, please use 'v-model:checked'`),n(!(`value`in t),`Switch`,"`value` is not validate prop, do you mean `checked`?")});let T=v(e.checked===void 0?t.defaultChecked:e.checked),E=f(()=>T.value===e.checkedValue);y(()=>e.checked,()=>{T.value=e.checked});let{prefixCls:D,direction:O,size:k}=o(`switch`,e),[A,j]=d(D),M=v(),N=()=>{M.value?.focus()};m({focus:N,blur:()=>{M.value?.blur()}}),_(()=>{h(()=>{e.autofocus&&!w.value&&M.value.focus()})});let P=(e,t)=>{w.value||(x(`update:checked`,e),x(`change`,e,t),S.onFieldChange())},F=e=>{x(`blur`,e)},I=t=>{N();let n=E.value?e.unCheckedValue:e.checkedValue;P(n,t),x(`click`,n,t)},L=t=>{t.keyCode===l.LEFT?P(e.unCheckedValue,t):t.keyCode===l.RIGHT&&P(e.checkedValue,t),x(`keydown`,t)},R=e=>{M.value?.blur(),x(`mouseup`,e)},z=f(()=>({[`${D.value}-small`]:k.value===`small`,[`${D.value}-loading`]:e.loading,[`${D.value}-checked`]:E.value,[`${D.value}-disabled`]:w.value,[D.value]:!0,[`${D.value}-rtl`]:O.value===`rtl`,[j.value]:!0}));return()=>A(p(u,null,{default:()=>[p(`button`,{...r(e,[`prefixCls`,`checkedChildren`,`unCheckedChildren`,`checked`,`autofocus`,`checkedValue`,`unCheckedValue`,`id`,`onChange`,`onUpdate:checked`]),...t,id:e.id??S.id.value,onKeydown:L,onClick:I,onBlur:F,onMouseup:R,type:`button`,role:`switch`,"aria-checked":T.value,disabled:w.value||e.loading,class:[t.class,z.value],ref:M},[p(`div`,{class:`${D.value}-handle`},[e.loading?p(b,{class:`${D.value}-loading-icon`},null):null]),p(`span`,{class:`${D.value}-inner`},[p(`span`,{class:`${D.value}-inner-checked`},[a(s,e,`checkedChildren`)]),p(`span`,{class:`${D.value}-inner-unchecked`},[a(s,e,`unCheckedChildren`)])])])]}))}}));export{x as SwitchSizes,C as default,S as switchProps};