import{aD as w,ao as V,ap as E,Q as J,be as N,aE as C,as as P,aN as X,ac as Y,aB as g,U as Z,j as L,aP as _,aH as x,W as ee,aQ as ae,aI as ie,s as d,r as te,a5 as ne,bo as se,z as K,o as le,c as v,h as i,b as S,x as c,K as oe,O as a,n as u,l as r,w as p,a1 as b,$ as h,t as T,a0 as O,f as ce,ce as re,H as ue,aL as de,N as ve,bm as F,ad as fe,aU as pe,a4 as he}from"./index-Xuk4tRmH.js";import{i as me}from"./validator-BByWlvSC.js";const be=J({modelValue:{type:[Boolean,String,Number],default:!1},disabled:Boolean,loading:Boolean,size:{type:String,validator:me},width:{type:[String,Number],default:""},inlinePrompt:Boolean,inactiveActionIcon:{type:g},activeActionIcon:{type:g},activeIcon:{type:g},inactiveIcon:{type:g},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:Y(Function)},id:String,tabindex:{type:[String,Number]},...X(["ariaLabel"])}),ye={[P]:l=>w(l)||V(l)||E(l),[C]:l=>w(l)||V(l)||E(l),[N]:l=>w(l)||V(l)||E(l)},M="ElSwitch",Ie=L({name:M}),ke=L({...Ie,props:be,emits:ye,setup(l,{expose:U,emit:f}){const n=l,{formItem:y}=_(),H=x(),t=ee("switch"),{inputId:$}=ae(n,{formItemContext:y}),I=ie(d(()=>n.loading)),B=te(n.modelValue!==!1),m=ne(),Q=d(()=>[t.b(),t.m(H.value),t.is("disabled",I.value),t.is("checked",s.value)]),R=d(()=>[t.e("label"),t.em("label","left"),t.is("active",!s.value)]),W=d(()=>[t.e("label"),t.em("label","right"),t.is("active",s.value)]),j=d(()=>({width:se(n.width)}));K(()=>n.modelValue,()=>{B.value=!0});const A=d(()=>B.value?n.modelValue:!1),s=d(()=>A.value===n.activeValue);[n.activeValue,n.inactiveValue].includes(A.value)||(f(P,n.inactiveValue),f(C,n.inactiveValue),f(N,n.inactiveValue)),K(s,e=>{var o;m.value.checked=e,n.validateEvent&&((o=y?.validate)==null||o.call(y,"change").catch(q=>pe()))});const k=()=>{const e=s.value?n.inactiveValue:n.activeValue;f(P,e),f(C,e),f(N,e),ve(()=>{m.value.checked=s.value})},z=()=>{if(I.value)return;const{beforeChange:e}=n;if(!e){k();return}const o=e();[F(o),w(o)].includes(!0)||fe(M,"beforeChange must return type `Promise<boolean>` or `boolean`"),F(o)?o.then(D=>{D&&k()}).catch(D=>{}):o&&k()},G=()=>{var e,o;(o=(e=m.value)==null?void 0:e.focus)==null||o.call(e)};return le(()=>{m.value.checked=s.value}),U({focus:G,checked:s}),(e,o)=>(i(),v("div",{class:u(a(Q)),onClick:de(z,["prevent"])},[S("input",{id:a($),ref_key:"input",ref:m,class:u(a(t).e("input")),type:"checkbox",role:"switch","aria-checked":a(s),"aria-disabled":a(I),"aria-label":e.ariaLabel,name:e.name,"true-value":e.activeValue,"false-value":e.inactiveValue,disabled:a(I),tabindex:e.tabindex,onChange:k,onKeydown:oe(z,["enter"])},null,42,["id","aria-checked","aria-disabled","aria-label","name","true-value","false-value","disabled","tabindex","onKeydown"]),!e.inlinePrompt&&(e.inactiveIcon||e.inactiveText)?(i(),v("span",{key:0,class:u(a(R))},[e.inactiveIcon?(i(),r(a(h),{key:0},{default:p(()=>[(i(),r(b(e.inactiveIcon)))]),_:1})):c("v-if",!0),!e.inactiveIcon&&e.inactiveText?(i(),v("span",{key:1,"aria-hidden":a(s)},T(e.inactiveText),9,["aria-hidden"])):c("v-if",!0)],2)):c("v-if",!0),S("span",{class:u(a(t).e("core")),style:ue(a(j))},[e.inlinePrompt?(i(),v("div",{key:0,class:u(a(t).e("inner"))},[e.activeIcon||e.inactiveIcon?(i(),r(a(h),{key:0,class:u(a(t).is("icon"))},{default:p(()=>[(i(),r(b(a(s)?e.activeIcon:e.inactiveIcon)))]),_:1},8,["class"])):e.activeText||e.inactiveText?(i(),v("span",{key:1,class:u(a(t).is("text")),"aria-hidden":!a(s)},T(a(s)?e.activeText:e.inactiveText),11,["aria-hidden"])):c("v-if",!0)],2)):c("v-if",!0),S("div",{class:u(a(t).e("action"))},[e.loading?(i(),r(a(h),{key:0,class:u(a(t).is("loading"))},{default:p(()=>[ce(a(re))]),_:1},8,["class"])):a(s)?O(e.$slots,"active-action",{key:1},()=>[e.activeActionIcon?(i(),r(a(h),{key:0},{default:p(()=>[(i(),r(b(e.activeActionIcon)))]),_:1})):c("v-if",!0)]):a(s)?c("v-if",!0):O(e.$slots,"inactive-action",{key:2},()=>[e.inactiveActionIcon?(i(),r(a(h),{key:0},{default:p(()=>[(i(),r(b(e.inactiveActionIcon)))]),_:1})):c("v-if",!0)])],2)],6),!e.inlinePrompt&&(e.activeIcon||e.activeText)?(i(),v("span",{key:1,class:u(a(W))},[e.activeIcon?(i(),r(a(h),{key:0},{default:p(()=>[(i(),r(b(e.activeIcon)))]),_:1})):c("v-if",!0),!e.activeIcon&&e.activeText?(i(),v("span",{key:1,"aria-hidden":!a(s)},T(e.activeText),9,["aria-hidden"])):c("v-if",!0)],2)):c("v-if",!0)],10,["onClick"]))}});var ge=Z(ke,[["__file","switch.vue"]]);const Ee=he(ge);export{Ee as E};
