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