import V from"./Icon.30f6becb.js";import{g as w,C as N,j as n,r as O,s as L,D as U,S as b,F as G,E as p,G as P,H as R,O as g,v as T,o as h,k as z,w as M,a as q,y as d,c as C,b as k,l as S}from"./entry.eb978f24.js";import{u as J}from"./useFormEvents.4d081bc0.js";import{_ as Q}from"./_plugin-vue_export-helper.c27b6911.js";import{t as W,o as X,K as Y,H as Z,T as _,a as I}from"./dom.2ed3c503.js";import{b as x}from"./use-resolve-button-type.97982c22.js";import{f as ee,a as ae}from"./hidden.a9dcbbf7.js";import{d as oe,p as te}from"./use-controllable.6ce54b6b.js";let le=Symbol("GroupContext"),ne=w({name:"Switch",emits:{"update:modelValue":e=>!0},props:{as:{type:[Object,String],default:"button"},modelValue:{type:Boolean,default:void 0},defaultChecked:{type:Boolean,optional:!0},form:{type:String,optional:!0},name:{type:String,optional:!0},value:{type:String,optional:!0},id:{type:String,default:()=>`headlessui-switch-${W()}`}},inheritAttrs:!1,setup(e,{emit:i,attrs:s,slots:o,expose:m}){let t=N(le,null),[l,r]=oe(n(()=>e.modelValue),a=>i("update:modelValue",a),n(()=>e.defaultChecked));function c(){r(!l.value)}let y=O(null),f=t===null?y:t.switchRef,B=x(n(()=>({as:e.as,type:s.type})),f);m({el:f,$el:f});function E(a){a.preventDefault(),c()}function A(a){a.key===I.Space?(a.preventDefault(),c()):a.key===I.Enter&&te(a.currentTarget)}function H(a){a.preventDefault()}let v=n(()=>{var a,u;return(u=(a=X(f))==null?void 0:a.closest)==null?void 0:u.call(a,"form")});return L(()=>{U([v],()=>{if(!v.value||e.defaultChecked===void 0)return;function a(){r(e.defaultChecked)}return v.value.addEventListener("reset",a),()=>{var u;(u=v.value)==null||u.removeEventListener("reset",a)}},{immediate:!0})}),()=>{let{id:a,name:u,value:$,form:D,...j}=e,F={checked:l.value},K={id:a,ref:f,role:"switch",type:B.value,tabIndex:0,"aria-checked":l.value,"aria-labelledby":t?.labelledby.value,"aria-describedby":t?.describedby.value,onClick:E,onKeyup:A,onKeypress:H};return b(G,[u!=null&&l.value!=null?b(ee,Y({features:ae.Hidden,as:"input",type:"checkbox",hidden:!0,readOnly:!0,checked:l.value,form:D,name:u,value:$})):null,Z({ourProps:K,theirProps:{...s,..._(j,["modelValue","defaultChecked"])},slot:F,attrs:s,slots:o,name:"Switch"})])}}});const ue=w({components:{HSwitch:ne,UIcon:V},props:{name:{type:String,default:null},modelValue:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},onIcon:{type:String,default:()=>p.ui.toggle.default.onIcon},offIcon:{type:String,default:()=>p.ui.toggle.default.offIcon},color:{type:String,default:()=>p.ui.toggle.default.color,validator(e){return p.ui.colors.includes(e)}},ui:{type:Object,default:()=>p.ui.toggle}},emits:["update:modelValue"],setup(e,{emit:i}){const s=P(),o=n(()=>R({},e.ui,s.ui.toggle)),{emitFormBlur:m}=J(),t=n({get(){return e.modelValue},set(y){i("update:modelValue",y),m()}}),l=n(()=>g(o.value.base,o.value.rounded,o.value.ring.replaceAll("{color}",e.color),(t.value?o.value.active:o.value.inactive).replaceAll("{color}",e.color))),r=n(()=>g(o.value.icon.on.replaceAll("{color}",e.color))),c=n(()=>g(o.value.icon.off.replaceAll("{color}",e.color)));return{ui:o,active:t,switchClass:l,onIconClass:r,offIconClass:c}}});function ie(e,i,s,o,m,t){const l=V,r=T("HSwitch");return h(),z(r,{modelValue:e.active,"onUpdate:modelValue":i[0]||(i[0]=c=>e.active=c),name:e.name,disabled:e.disabled,class:d(e.switchClass)},{default:M(()=>[q("span",{class:d([e.active?e.ui.container.active:e.ui.container.inactive,e.ui.container.base])},[e.onIcon?(h(),C("span",{key:0,class:d([e.active?e.ui.icon.active:e.ui.icon.inactive,e.ui.icon.base]),"aria-hidden":"true"},[k(l,{name:e.onIcon,class:d(e.onIconClass)},null,8,["name","class"])],2)):S("",!0),e.offIcon?(h(),C("span",{key:1,class:d([e.active?e.ui.icon.inactive:e.ui.icon.active,e.ui.icon.base]),"aria-hidden":"true"},[k(l,{name:e.offIcon,class:d(e.offIconClass)},null,8,["name","class"])],2)):S("",!0)],2)]),_:1},8,["modelValue","name","disabled","class"])}const ye=Q(ue,[["render",ie]]);export{ye as default};
