import{U as e,aG as a,W as i,aH as t,Y as n,I as l,aD as c,x as s,aI as o,a0 as v,a1 as d,aJ as u,aK as r,Z as f,r as p,aj as m,a2 as y,a3 as b,ad as h,aL as k,d as I,e as g,h as x,g as V,a7 as S,aM as T,j as w,k as _,m as C,p as B,an as A,am as N,f as P,aN as j,a6 as E,al as K,aO as L,a8 as U,H,aP as $,ac as z,ap as D}from"./index.286e9b79.js";import{i as F}from"./validator.18338d56.js";import{U as G,C as J,I as M}from"./event.776e7e11.js";const O=e({modelValue:{type:[Boolean,String,Number],default:!1},disabled:{type:Boolean,default:!1},loading:{type:Boolean,default:!1},size:{type:String,validator:F},width:{type:[String,Number],default:""},inlinePrompt:{type:Boolean,default:!1},inactiveActionIcon:{type:a},activeActionIcon:{type:a},activeIcon:{type:a},inactiveIcon:{type:a},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:i(Function)},id:String,tabindex:{type:[String,Number]},label:{type:String,default:void 0},...t(["ariaLabel"])}),W={[G]:e=>n(e)||l(e)||c(e),[J]:e=>n(e)||l(e)||c(e),[M]:e=>n(e)||l(e)||c(e)},Y=["onClick"],Z=["id","aria-checked","aria-disabled","aria-label","name","true-value","false-value","disabled","tabindex","onKeydown"],q=["aria-hidden"],Q=["aria-hidden"],R=["aria-hidden"],X="ElSwitch",ee=s({name:X});const ae=D(U(s({...ee,props:O,emits:W,setup(e,{expose:a,emit:i}){const t=e,{formItem:l}=o(),c=v(),s=d("switch"),{inputId:U}=u(t,{formItemContext:l}),D=r(f((()=>t.loading))),F=p(!1!==t.modelValue),O=p(),W=p(),ee=f((()=>[s.b(),s.m(c.value),s.is("disabled",D.value),s.is("checked",le.value)])),ae=f((()=>[s.e("label"),s.em("label","left"),s.is("active",!le.value)])),ie=f((()=>[s.e("label"),s.em("label","right"),s.is("active",le.value)])),te=f((()=>({width:m(t.width)})));y((()=>t.modelValue),(()=>{F.value=!0}));const ne=f((()=>!!F.value&&t.modelValue)),le=f((()=>ne.value===t.activeValue));[t.activeValue,t.inactiveValue].includes(ne.value)||(i(G,t.inactiveValue),i(J,t.inactiveValue),i(M,t.inactiveValue)),y(le,(e=>{var a;O.value.checked=e,t.validateEvent&&(null==(a=null==l?void 0:l.validate)||a.call(l,"change").catch((e=>b())))}));const ce=()=>{const e=le.value?t.inactiveValue:t.activeValue;i(G,e),i(J,e),i(M,e),H((()=>{O.value.checked=le.value}))},se=()=>{if(D.value)return;const{beforeChange:e}=t;if(!e)return void ce();const a=e();[$(a),n(a)].includes(!0)||z(X,"beforeChange must return type `Promise<boolean>` or `boolean`"),$(a)?a.then((e=>{e&&ce()})).catch((e=>{})):a&&ce()};return h((()=>{O.value.checked=le.value})),k({from:"label",replacement:"aria-label",version:"2.8.0",scope:"el-switch",ref:"https://element-plus.org/en-US/component/switch.html"},f((()=>!!t.label))),a({focus:()=>{var e,a;null==(a=null==(e=O.value)?void 0:e.focus)||a.call(e)},checked:le}),(e,a)=>(I(),g("div",{class:S(V(ee)),onClick:L(se,["prevent"])},[x("input",{id:V(U),ref_key:"input",ref:O,class:S(V(s).e("input")),type:"checkbox",role:"switch","aria-checked":V(le),"aria-disabled":V(D),"aria-label":e.label||e.ariaLabel,name:e.name,"true-value":e.activeValue,"false-value":e.inactiveValue,disabled:V(D),tabindex:e.tabindex,onChange:ce,onKeydown:T(se,["enter"])},null,42,Z),e.inlinePrompt||!e.inactiveIcon&&!e.inactiveText?A("v-if",!0):(I(),g("span",{key:0,class:S(V(ae))},[e.inactiveIcon?(I(),w(V(B),{key:0},{default:_((()=>[(I(),w(C(e.inactiveIcon)))])),_:1})):A("v-if",!0),!e.inactiveIcon&&e.inactiveText?(I(),g("span",{key:1,"aria-hidden":V(le)},N(e.inactiveText),9,q)):A("v-if",!0)],2)),x("span",{ref_key:"core",ref:W,class:S(V(s).e("core")),style:K(V(te))},[e.inlinePrompt?(I(),g("div",{key:0,class:S(V(s).e("inner"))},[e.activeIcon||e.inactiveIcon?(I(),w(V(B),{key:0,class:S(V(s).is("icon"))},{default:_((()=>[(I(),w(C(V(le)?e.activeIcon:e.inactiveIcon)))])),_:1},8,["class"])):e.activeText||e.inactiveText?(I(),g("span",{key:1,class:S(V(s).is("text")),"aria-hidden":!V(le)},N(V(le)?e.activeText:e.inactiveText),11,Q)):A("v-if",!0)],2)):A("v-if",!0),x("div",{class:S(V(s).e("action"))},[e.loading?(I(),w(V(B),{key:0,class:S(V(s).is("loading"))},{default:_((()=>[P(V(j))])),_:1},8,["class"])):V(le)?E(e.$slots,"active-action",{key:1},(()=>[e.activeActionIcon?(I(),w(V(B),{key:0},{default:_((()=>[(I(),w(C(e.activeActionIcon)))])),_:1})):A("v-if",!0)])):V(le)?A("v-if",!0):E(e.$slots,"inactive-action",{key:2},(()=>[e.inactiveActionIcon?(I(),w(V(B),{key:0},{default:_((()=>[(I(),w(C(e.inactiveActionIcon)))])),_:1})):A("v-if",!0)]))],2)],6),e.inlinePrompt||!e.activeIcon&&!e.activeText?A("v-if",!0):(I(),g("span",{key:1,class:S(V(ie))},[e.activeIcon?(I(),w(V(B),{key:0},{default:_((()=>[(I(),w(C(e.activeIcon)))])),_:1})):A("v-if",!0),!e.activeIcon&&e.activeText?(I(),g("span",{key:1,"aria-hidden":!V(le)},N(e.activeText),9,R)):A("v-if",!0)],2))],10,Y))}}),[["__file","switch.vue"]]));export{ae as E};
