import{$n as e,Br as t,Bt as n,F as ee,Ht as r,Jr as te,Or as i,Pr as a,Qn as o,Rr as s,Tr as c,Ut as l,W as u,Xr as ne,Xt as d,ar as f,c as p,cr as m,di as h,fr as g,jr as _,l as v,li as y,lr as b,mi as x,nt as S,or as C,ot as re,p as w,pi as T,pr as E,qt as D,s as O,sr as k,ti as A,u as j,ui as M,v as N,yr as P,zt as F}from"./style-QAnagFj5.js";import{F as I,I as L,P as R,f as z}from"./style-BqiJaO0R.js";import{t as B}from"./validator-3ig2Krpt.js";var V=r({modelValue:{type:[Boolean,String,Number],default:!1},disabled:{type:Boolean,default:void 0},loading:Boolean,size:{type:String,validator:B},width:{type:[String,Number],default:``},inlinePrompt:Boolean,inactiveActionIcon:{type:N},activeActionIcon:{type:N},activeIcon:{type:N},inactiveIcon:{type:N},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:l(Function)},id:String,tabindex:{type:[String,Number]},...z([`ariaLabel`])}),H={[L]:e=>D(e)||M(e)||d(e),[R]:e=>D(e)||M(e)||d(e),[I]:e=>D(e)||M(e)||d(e)},U=[`id`,`aria-checked`,`aria-disabled`,`aria-label`,`name`,`true-value`,`false-value`,`disabled`,`tabindex`],W=[`aria-hidden`],G={key:1},K={key:1},q=[`aria-hidden`],J=`ElSwitch`,Y=u(E({name:J,__name:`switch`,props:V,emits:H,setup(r,{expose:l,emit:u}){let d=r,E=u,{formItem:M}=O(),N=j(),z=S(`switch`),{inputId:B}=p(d,{formItemContext:M}),V=v(f(()=>{if(d.loading)return!0})),H=te(d.modelValue!==!1),Y=ne(),ie=f(()=>[z.b(),z.m(N.value),z.is(`disabled`,V.value),z.is(`checked`,Z.value)]),ae=f(()=>[z.e(`label`),z.em(`label`,`left`),z.is(`active`,!Z.value)]),oe=f(()=>[z.e(`label`),z.em(`label`,`right`),z.is(`active`,Z.value)]),se=f(()=>({width:re(d.width)}));s(()=>d.modelValue,()=>{H.value=!0});let X=f(()=>H.value?d.modelValue:!1),Z=f(()=>X.value===d.activeValue);[d.activeValue,d.inactiveValue].includes(X.value)||(E(L,d.inactiveValue),E(R,d.inactiveValue),E(I,d.inactiveValue)),s(Z,e=>{Y.value.checked=e,d.validateEvent&&M?.validate?.(`change`).catch(e=>F(e))});let Q=()=>{let e=Z.value?d.inactiveValue:d.activeValue;E(L,e),E(R,e),E(I,e),P(()=>{Y.value.checked=Z.value})},$=()=>{if(V.value)return;let{beforeChange:e}=d;if(!e){Q();return}let t=e();[y(t),D(t)].includes(!0)||n(J,"beforeChange must return type `Promise<boolean>` or `boolean`"),y(t)?t.then(e=>{e&&Q()}).catch(e=>{F(J,`some error occurred: ${e}`)}):t&&Q()};return c(()=>{Y.value.checked=Z.value}),l({focus:()=>{Y.value?.focus?.()},checked:Z}),(n,te)=>(i(),b(`div`,{class:h(ie.value),onClick:e($,[`prevent`])},[C(`input`,{id:A(B),ref_key:`input`,ref:Y,class:h(A(z).e(`input`)),type:`checkbox`,role:`switch`,"aria-checked":Z.value,"aria-disabled":A(V),"aria-label":r.ariaLabel,name:r.name,"true-value":r.activeValue,"false-value":r.inactiveValue,disabled:A(V),tabindex:r.tabindex,onChange:Q,onKeydown:o($,[`enter`])},null,42,U),!r.inlinePrompt&&(r.inactiveIcon||r.inactiveText||n.$slots.inactive)?(i(),b(`span`,{key:0,class:h(ae.value)},[_(n.$slots,`inactive`,{},()=>[r.inactiveIcon?(i(),k(A(w),{key:0},{default:t(()=>[(i(),k(a(r.inactiveIcon)))]),_:1})):m(`v-if`,!0),!r.inactiveIcon&&r.inactiveText?(i(),b(`span`,{key:1,"aria-hidden":Z.value},x(r.inactiveText),9,W)):m(`v-if`,!0)])],2)):m(`v-if`,!0),C(`span`,{class:h(A(z).e(`core`)),style:T(se.value)},[r.inlinePrompt?(i(),b(`div`,{key:0,class:h(A(z).e(`inner`))},[Z.value?(i(),b(`div`,{key:1,class:h(A(z).e(`inner-wrapper`))},[_(n.$slots,`active`,{},()=>[r.activeIcon?(i(),k(A(w),{key:0},{default:t(()=>[(i(),k(a(r.activeIcon)))]),_:1})):m(`v-if`,!0),!r.activeIcon&&r.activeText?(i(),b(`span`,K,x(r.activeText),1)):m(`v-if`,!0)])],2)):(i(),b(`div`,{key:0,class:h(A(z).e(`inner-wrapper`))},[_(n.$slots,`inactive`,{},()=>[r.inactiveIcon?(i(),k(A(w),{key:0},{default:t(()=>[(i(),k(a(r.inactiveIcon)))]),_:1})):m(`v-if`,!0),!r.inactiveIcon&&r.inactiveText?(i(),b(`span`,G,x(r.inactiveText),1)):m(`v-if`,!0)])],2))],2)):m(`v-if`,!0),C(`div`,{class:h(A(z).e(`action`))},[r.loading?(i(),k(A(w),{key:0,class:h(A(z).is(`loading`))},{default:t(()=>[g(A(ee))]),_:1},8,[`class`])):Z.value?_(n.$slots,`active-action`,{key:1},()=>[r.activeActionIcon?(i(),k(A(w),{key:0},{default:t(()=>[(i(),k(a(r.activeActionIcon)))]),_:1})):m(`v-if`,!0)]):Z.value?m(`v-if`,!0):_(n.$slots,`inactive-action`,{key:2},()=>[r.inactiveActionIcon?(i(),k(A(w),{key:0},{default:t(()=>[(i(),k(a(r.inactiveActionIcon)))]),_:1})):m(`v-if`,!0)])],2)],6),!r.inlinePrompt&&(r.activeIcon||r.activeText||n.$slots.active)?(i(),b(`span`,{key:1,class:h(oe.value)},[_(n.$slots,`active`,{},()=>[r.activeIcon?(i(),k(A(w),{key:0},{default:t(()=>[(i(),k(a(r.activeIcon)))]),_:1})):m(`v-if`,!0),!r.activeIcon&&r.activeText?(i(),b(`span`,{key:1,"aria-hidden":!Z.value},x(r.activeText),9,q)):m(`v-if`,!0)])],2)):m(`v-if`,!0)],2))}}));export{Y as t};