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