import{a1 as e,b2 as a,aZ as i,O as t,b$ as n,bI as c,a2 as l,bJ as s,a3 as o,P as v,cK as u,S as d,bK as r,bm as f,af as b,bM as p,bL as y,q as m,c as h,a9 as k,s as I,o as g,e as x,f as V,g as S,z as T,N as w,k as _,C,l as B,w as A,Y as N,$ as P,t as $,X as E,i as K,bp as L,a0 as z,b_ as j,p as q,cL as F,b4 as J,R as M,a$ as O,an as R}from"./wbs-f6dQykzJ.js";const X=t({modelValue:{type:[Boolean,String,Number],default:!1},disabled:Boolean,loading:Boolean,size:{type:String,validator:u},width:{type:[String,Number],default:""},inlinePrompt:Boolean,inactiveActionIcon:{type:v},activeActionIcon:{type:v},activeIcon:{type:v},inactiveIcon:{type:v},activeText:{type:String,default:""},inactiveText:{type:String,default:""},activeValue:{type:[Boolean,String,Number],default:!0},inactiveValue:{type:[Boolean,String,Number],default:!1},name:{type:String,default:""},validateEvent:{type:Boolean,default:!0},beforeChange:{type:o(Function)},id:String,tabindex:{type:[String,Number]},...s(["ariaLabel"])}),Y={[l]:t=>e(t)||a(t)||i(t),[c]:t=>e(t)||a(t)||i(t),[n]:t=>e(t)||a(t)||i(t)},Z="ElSwitch",D=d({name:Z});const G=R(M(d({...D,props:X,emits:Y,setup(a,{expose:i,emit:t}){const s=a,{formItem:o}=r(),v=f(),u=b("switch"),{inputId:d}=p(s,{formItemContext:o}),M=y(m((()=>s.loading))),R=h(!1!==s.modelValue),X=h(),Y=h(),D=m((()=>[u.b(),u.m(v.value),u.is("disabled",M.value),u.is("checked",W.value)])),G=m((()=>[u.e("label"),u.em("label","left"),u.is("active",!W.value)])),H=m((()=>[u.e("label"),u.em("label","right"),u.is("active",W.value)])),Q=m((()=>({width:k(s.width)})));I((()=>s.modelValue),(()=>{R.value=!0}));const U=m((()=>!!R.value&&s.modelValue)),W=m((()=>U.value===s.activeValue));[s.activeValue,s.inactiveValue].includes(U.value)||(t(l,s.inactiveValue),t(c,s.inactiveValue),t(n,s.inactiveValue)),I(W,(e=>{var a;X.value.checked=e,s.validateEvent&&(null==(a=null==o?void 0:o.validate)||a.call(o,"change").catch((e=>O())))}));const ee=()=>{const e=W.value?s.inactiveValue:s.activeValue;t(l,e),t(c,e),t(n,e),q((()=>{X.value.checked=W.value}))},ae=()=>{if(M.value)return;const{beforeChange:a}=s;if(!a)return void ee();const i=a();[F(i),e(i)].includes(!0)||J(Z,"beforeChange must return type `Promise<boolean>` or `boolean`"),F(i)?i.then((e=>{e&&ee()})).catch((e=>{})):i&&ee()};return g((()=>{X.value.checked=W.value})),i({focus:()=>{var e,a;null==(a=null==(e=X.value)?void 0:e.focus)||a.call(e)},checked:W}),(e,a)=>(V(),x("div",{class:C(_(D)),onClick:j(ae,["prevent"])},[S("input",{id:_(d),ref_key:"input",ref:X,class:C(_(u).e("input")),type:"checkbox",role:"switch","aria-checked":_(W),"aria-disabled":_(M),"aria-label":e.ariaLabel,name:e.name,"true-value":e.activeValue,"false-value":e.inactiveValue,disabled:_(M),tabindex:e.tabindex,onChange:ee,onKeydown:w(ae,["enter"])},null,42,["id","aria-checked","aria-disabled","aria-label","name","true-value","false-value","disabled","tabindex","onKeydown"]),e.inlinePrompt||!e.inactiveIcon&&!e.inactiveText?T("v-if",!0):(V(),x("span",{key:0,class:C(_(G))},[e.inactiveIcon?(V(),B(_(P),{key:0},{default:A((()=>[(V(),B(N(e.inactiveIcon)))])),_:1})):T("v-if",!0),!e.inactiveIcon&&e.inactiveText?(V(),x("span",{key:1,"aria-hidden":_(W)},$(e.inactiveText),9,["aria-hidden"])):T("v-if",!0)],2)),S("span",{ref_key:"core",ref:Y,class:C(_(u).e("core")),style:z(_(Q))},[e.inlinePrompt?(V(),x("div",{key:0,class:C(_(u).e("inner"))},[e.activeIcon||e.inactiveIcon?(V(),B(_(P),{key:0,class:C(_(u).is("icon"))},{default:A((()=>[(V(),B(N(_(W)?e.activeIcon:e.inactiveIcon)))])),_:1},8,["class"])):e.activeText||e.inactiveText?(V(),x("span",{key:1,class:C(_(u).is("text")),"aria-hidden":!_(W)},$(_(W)?e.activeText:e.inactiveText),11,["aria-hidden"])):T("v-if",!0)],2)):T("v-if",!0),S("div",{class:C(_(u).e("action"))},[e.loading?(V(),B(_(P),{key:0,class:C(_(u).is("loading"))},{default:A((()=>[K(_(L))])),_:1},8,["class"])):_(W)?E(e.$slots,"active-action",{key:1},(()=>[e.activeActionIcon?(V(),B(_(P),{key:0},{default:A((()=>[(V(),B(N(e.activeActionIcon)))])),_:1})):T("v-if",!0)])):_(W)?T("v-if",!0):E(e.$slots,"inactive-action",{key:2},(()=>[e.inactiveActionIcon?(V(),B(_(P),{key:0},{default:A((()=>[(V(),B(N(e.inactiveActionIcon)))])),_:1})):T("v-if",!0)]))],2)],6),e.inlinePrompt||!e.activeIcon&&!e.activeText?T("v-if",!0):(V(),x("span",{key:1,class:C(_(H))},[e.activeIcon?(V(),B(_(P),{key:0},{default:A((()=>[(V(),B(N(e.activeIcon)))])),_:1})):T("v-if",!0),!e.activeIcon&&e.activeText?(V(),x("span",{key:1,"aria-hidden":!_(W)},$(e.activeText),9,["aria-hidden"])):T("v-if",!0)],2))],10,["onClick"]))}}),[["__file","switch.vue"]]));export{G as E};
