import{A as e,H as t,J as n,Q as r,R as ee,Y as i,Z as a,ct as o,dt as s,t as c,y as l}from"./icon-K_9KhGme.js";import{_ as u,i as d,n as f,r as p,s as m,t as te,v as h,y as g}from"./use-form-item-CLvhaz9M.js";import{B as _,C as v,Ct as y,Dt as b,K as x,L as ne,Ot as S,Q as C,Tt as w,U as T,X as E,_ as D,c as O,ct as k,g as A,h as j,j as M,l as N,ot as re,pt as P,v as F,w as I,wt as L,y as R}from"./vue.esm-bundler-DcNPjsgv.js";import{t as z}from"./validator-Bp61J-Hx.js";import{a as B}from"./icon-DARh_Gl7.js";/* empty css             */var V=a({modelValue:{type:[Boolean,String,Number],default:!1},disabled:{type:Boolean,default:void 0},loading:Boolean,size:{type:String,validator:z},width:{type:[String,Number],default:``},inlinePrompt:Boolean,inactiveActionIcon:{type:B},activeActionIcon:{type:B},activeIcon:{type:B},inactiveIcon:{type:B},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:r(Function)},id:String,tabindex:{type:[String,Number]},...m([`ariaLabel`])}),H={[g]:e=>o(e)||L(e)||s(e),[u]:e=>o(e)||L(e)||s(e),[h]:e=>o(e)||L(e)||s(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=e(I({name:J,__name:`switch`,props:V,emits:H,setup(e,{expose:r,emit:a}){let s=e,m=a,{formItem:I}=te(),L=d(),z=ee(`switch`),{inputId:B}=f(s,{formItemContext:I}),V=p(j(()=>{if(s.loading)return!0})),H=re(s.modelValue!==!1),Y=k(),ie=j(()=>[z.b(),z.m(L.value),z.is(`disabled`,V.value),z.is(`checked`,Z.value)]),ae=j(()=>[z.e(`label`),z.em(`label`,`left`),z.is(`active`,!Z.value)]),oe=j(()=>[z.e(`label`),z.em(`label`,`right`),z.is(`active`,Z.value)]),se=j(()=>({width:t(s.width)}));E(()=>s.modelValue,()=>{H.value=!0});let X=j(()=>H.value?s.modelValue:!1),Z=j(()=>X.value===s.activeValue);[s.activeValue,s.inactiveValue].includes(X.value)||(m(g,s.inactiveValue),m(u,s.inactiveValue),m(h,s.inactiveValue)),E(Z,e=>{Y.value.checked=e,s.validateEvent&&I?.validate?.(`change`).catch(e=>n(e))});let Q=()=>{let e=Z.value?s.inactiveValue:s.activeValue;m(g,e),m(u,e),m(h,e),M(()=>{Y.value.checked=Z.value})},$=()=>{if(V.value)return;let{beforeChange:e}=s;if(!e){Q();return}let t=e();[y(t),o(t)].includes(!0)||i(J,"beforeChange must return type `Promise<boolean>` or `boolean`"),y(t)?t.then(e=>{e&&Q()}).catch(e=>{n(J,`some error occurred: ${e}`)}):t&&Q()};return ne(()=>{Y.value.checked=Z.value}),r({focus:()=>{Y.value?.focus?.()},checked:Z}),(t,n)=>(_(),R(`div`,{class:w(ie.value),onClick:N($,[`prevent`])},[A(`input`,{id:P(B),ref_key:`input`,ref:Y,class:w(P(z).e(`input`)),type:`checkbox`,role:`switch`,"aria-checked":Z.value,"aria-disabled":P(V),"aria-label":e.ariaLabel,name:e.name,"true-value":e.activeValue,"false-value":e.inactiveValue,disabled:P(V),tabindex:e.tabindex,onChange:Q,onKeydown:O($,[`enter`])},null,42,U),!e.inlinePrompt&&(e.inactiveIcon||e.inactiveText||t.$slots.inactive)?(_(),R(`span`,{key:0,class:w(ae.value)},[T(t.$slots,`inactive`,{},()=>[e.inactiveIcon?(_(),D(P(c),{key:0},{default:C(()=>[(_(),D(x(e.inactiveIcon)))]),_:1})):F(`v-if`,!0),!e.inactiveIcon&&e.inactiveText?(_(),R(`span`,{key:1,"aria-hidden":Z.value},S(e.inactiveText),9,W)):F(`v-if`,!0)])],2)):F(`v-if`,!0),A(`span`,{class:w(P(z).e(`core`)),style:b(se.value)},[e.inlinePrompt?(_(),R(`div`,{key:0,class:w(P(z).e(`inner`))},[Z.value?(_(),R(`div`,{key:1,class:w(P(z).e(`inner-wrapper`))},[T(t.$slots,`active`,{},()=>[e.activeIcon?(_(),D(P(c),{key:0},{default:C(()=>[(_(),D(x(e.activeIcon)))]),_:1})):F(`v-if`,!0),!e.activeIcon&&e.activeText?(_(),R(`span`,K,S(e.activeText),1)):F(`v-if`,!0)])],2)):(_(),R(`div`,{key:0,class:w(P(z).e(`inner-wrapper`))},[T(t.$slots,`inactive`,{},()=>[e.inactiveIcon?(_(),D(P(c),{key:0},{default:C(()=>[(_(),D(x(e.inactiveIcon)))]),_:1})):F(`v-if`,!0),!e.inactiveIcon&&e.inactiveText?(_(),R(`span`,G,S(e.inactiveText),1)):F(`v-if`,!0)])],2))],2)):F(`v-if`,!0),A(`div`,{class:w(P(z).e(`action`))},[e.loading?(_(),D(P(c),{key:0,class:w(P(z).is(`loading`))},{default:C(()=>[v(P(l))]),_:1},8,[`class`])):Z.value?T(t.$slots,`active-action`,{key:1},()=>[e.activeActionIcon?(_(),D(P(c),{key:0},{default:C(()=>[(_(),D(x(e.activeActionIcon)))]),_:1})):F(`v-if`,!0)]):Z.value?F(`v-if`,!0):T(t.$slots,`inactive-action`,{key:2},()=>[e.inactiveActionIcon?(_(),D(P(c),{key:0},{default:C(()=>[(_(),D(x(e.inactiveActionIcon)))]),_:1})):F(`v-if`,!0)])],2)],6),!e.inlinePrompt&&(e.activeIcon||e.activeText||t.$slots.active)?(_(),R(`span`,{key:1,class:w(oe.value)},[T(t.$slots,`active`,{},()=>[e.activeIcon?(_(),D(P(c),{key:0},{default:C(()=>[(_(),D(x(e.activeIcon)))]),_:1})):F(`v-if`,!0),!e.activeIcon&&e.activeText?(_(),R(`span`,{key:1,"aria-hidden":!Z.value},S(e.activeText),9,q)):F(`v-if`,!0)])],2)):F(`v-if`,!0)],2))}}));export{Y as t};