import{a0 as Y,a1 as Z,ax as w,ad as V,ae as E,a2 as L,a4 as _,G as d,r as S,y as M,e as x,o as i,c as v,a as T,f as a,n as u,aq as ee,g as c,w as p,al as y,l as r,t as C,h as ae,ab as F,a7 as ie,A as te,a5 as ne,ca as O,ai as se}from"./index-25eb6331.js";import{s as g,U as N,C as P,M as B,n as oe,k as le,o as ce,u as re,I as ue,j as de,E as m,N as ve,_ as fe,t as pe}from"./index-3bef6acb.js";import{i as me}from"./validator-551b2058.js";import{k as he}from"./request-14d7fed5.js";const ye=Y({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:Z(Function)},id:String,tabindex:{type:[String,Number]},...he(["ariaLabel"])}),be={[N]:o=>w(o)||V(o)||E(o),[P]:o=>w(o)||V(o)||E(o),[B]:o=>w(o)||V(o)||E(o)},U="ElSwitch",ke=L({name:U}),Ie=L({...ke,props:ye,emits:be,setup(o,{expose:G,emit:f}){const n=o,{formItem:b}=oe(),$=le(),t=_("switch"),{inputId:j}=ce(n,{formItemContext:b}),k=re(d(()=>n.loading)),A=S(n.modelValue!==!1),h=S(),q=S(),H=d(()=>[t.b(),t.m($.value),t.is("disabled",k.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:ue(n.width)}));M(()=>n.modelValue,()=>{A.value=!0});const z=d(()=>A.value?n.modelValue:!1),s=d(()=>z.value===n.activeValue);[n.activeValue,n.inactiveValue].includes(z.value)||(f(N,n.inactiveValue),f(P,n.inactiveValue),f(B,n.inactiveValue)),M(s,e=>{var l;h.value.checked=e,n.validateEvent&&((l=b==null?void 0:b.validate)==null||l.call(b,"change").catch(X=>de()))});const I=()=>{const e=s.value?n.inactiveValue:n.activeValue;f(N,e),f(P,e),f(B,e),ne(()=>{h.value.checked=s.value})},D=()=>{if(k.value)return;const{beforeChange:e}=n;if(!e){I();return}const l=e();[O(l),w(l)].includes(!0)||pe(U,"beforeChange must return type `Promise<boolean>` or `boolean`"),O(l)?l.then(K=>{K&&I()}).catch(K=>{}):l&&I()},Q=()=>{var e,l;(l=(e=h.value)==null?void 0:e.focus)==null||l.call(e)};return x(()=>{h.value.checked=s.value}),G({focus:Q,checked:s}),(e,l)=>(i(),v("div",{class:u(a(H)),onClick:te(D,["prevent"])},[T("input",{id:a(j),ref_key:"input",ref:h,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:ee(D,["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(),c(a(m),{key:0},{default:p(()=>[(i(),c(y(e.inactiveIcon)))]),_:1})):r("v-if",!0),!e.inactiveIcon&&e.inactiveText?(i(),v("span",{key:1,"aria-hidden":a(s)},C(e.inactiveText),9,["aria-hidden"])):r("v-if",!0)],2)):r("v-if",!0),T("span",{ref_key:"core",ref:q,class:u(a(t).e("core")),style:ie(a(J))},[e.inlinePrompt?(i(),v("div",{key:0,class:u(a(t).e("inner"))},[e.activeIcon||e.inactiveIcon?(i(),c(a(m),{key:0,class:u(a(t).is("icon"))},{default:p(()=>[(i(),c(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"])):r("v-if",!0)],2)):r("v-if",!0),T("div",{class:u(a(t).e("action"))},[e.loading?(i(),c(a(m),{key:0,class:u(a(t).is("loading"))},{default:p(()=>[ae(a(ve))]),_:1},8,["class"])):a(s)?F(e.$slots,"active-action",{key:1},()=>[e.activeActionIcon?(i(),c(a(m),{key:0},{default:p(()=>[(i(),c(y(e.activeActionIcon)))]),_:1})):r("v-if",!0)]):a(s)?r("v-if",!0):F(e.$slots,"inactive-action",{key:2},()=>[e.inactiveActionIcon?(i(),c(a(m),{key:0},{default:p(()=>[(i(),c(y(e.inactiveActionIcon)))]),_:1})):r("v-if",!0)])],2)],6),!e.inlinePrompt&&(e.activeIcon||e.activeText)?(i(),v("span",{key:1,class:u(a(W))},[e.activeIcon?(i(),c(a(m),{key:0},{default:p(()=>[(i(),c(y(e.activeIcon)))]),_:1})):r("v-if",!0),!e.activeIcon&&e.activeText?(i(),v("span",{key:1,"aria-hidden":!a(s)},C(e.activeText),9,["aria-hidden"])):r("v-if",!0)],2)):r("v-if",!0)],10,["onClick"]))}});var ge=fe(Ie,[["__file","switch.vue"]]);const Te=se(ge);export{Te as E};
