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