import E from"./Icon.fe8c0e68.js";import{g as $,C as N,j as r,r as U,s as L,D as O,R as w,F as P,E as R,G as S,N as C,v as z,o as k,k as M,w as T,a as J,y as d,c as I,b as V,l as B,K as q}from"./entry.9e31e8a4.js";import{t as Q}from"./tw-merge.27ca352e.js";import{z as W,u as X}from"./ui.config.7ae255de.js";import{u as Y}from"./useFormGroup.38d9f2fe.js";import{_ as Z}from"./_plugin-vue_export-helper.c27b6911.js";import{t as _,o as x,K as ee,H as ae,T as oe,a as A}from"./dom.737f30ce.js";import{b as te}from"./use-resolve-button-type.13bd624b.js";import{f as le,a as ne}from"./hidden.1f99b477.js";import{d as re,p as se}from"./use-controllable.c4815e67.js";import"./index.87a09f8b.js";let ie=Symbol("GroupContext"),ue=$({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-${_()}`}},inheritAttrs:!1,setup(e,{emit:u,attrs:o,slots:p,expose:m}){let l=N(ie,null),[t,n]=re(r(()=>e.modelValue),a=>u("update:modelValue",a),r(()=>e.defaultChecked));function c(){n(!t.value)}let f=U(null),i=l===null?f:l.switchRef,g=te(r(()=>({as:e.as,type:o.type})),i);m({el:i,$el:i});function h(a){a.preventDefault(),c()}function b(a){a.key===A.Space?(a.preventDefault(),c()):a.key===A.Enter&&se(a.currentTarget)}function D(a){a.preventDefault()}let v=r(()=>{var a,s;return(s=(a=x(i))==null?void 0:a.closest)==null?void 0:s.call(a,"form")});return L(()=>{O([v],()=>{if(!v.value||e.defaultChecked===void 0)return;function a(){n(e.defaultChecked)}return v.value.addEventListener("reset",a),()=>{var s;(s=v.value)==null||s.removeEventListener("reset",a)}},{immediate:!0})}),()=>{let{id:a,name:s,value:F,form:H,...K}=e,j={checked:t.value},G={id:a,ref:i,role:"switch",type:g.value,tabIndex:0,"aria-checked":t.value,"aria-labelledby":l?.labelledby.value,"aria-describedby":l?.describedby.value,onClick:h,onKeyup:b,onKeypress:D};return w(P,[s!=null&&t.value!=null?w(le,ee({features:ne.Hidden,as:"input",type:"checkbox",hidden:!0,readOnly:!0,checked:t.value,form:H,name:s,value:F})):null,ae({ourProps:G,theirProps:{...o,...oe(K,["modelValue","defaultChecked"])},slot:j,attrs:o,slots:p,name:"Switch"})])}}});const y=R(S.ui.strategy,S.ui.toggle,W),ce=$({components:{HSwitch:ue,UIcon:E},inheritAttrs:!1,props:{id:{type:String,default:null},name:{type:String,default:null},modelValue:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},onIcon:{type:String,default:()=>y.default.onIcon},offIcon:{type:String,default:()=>y.default.offIcon},color:{type:String,default:()=>y.default.color,validator(e){return S.ui.colors.includes(e)}},ui:{type:Object,default:void 0}},emits:["update:modelValue"],setup(e,{emit:u}){const{ui:o,attrs:p,attrsClass:m}=X("toggle",e.ui,y),{emitFormChange:l,formGroup:t}=Y(e),n=r(()=>t?.error?.value?"red":e.color),c=t?.labelFor,f=r({get(){return e.modelValue},set(b){u("update:modelValue",b),l()}}),i=r(()=>Q(C(o.value.base,o.value.rounded,o.value.ring.replaceAll("{color}",n.value),(f.value?o.value.active:o.value.inactive).replaceAll("{color}",n.value)),m)),g=r(()=>C(o.value.icon.on.replaceAll("{color}",n.value))),h=r(()=>C(o.value.icon.off.replaceAll("{color}",n.value)));return{ui:o,attrs:p,id:c,active:f,switchClass:i,onIconClass:g,offIconClass:h}}});function de(e,u,o,p,m,l){const t=E,n=z("HSwitch");return k(),M(n,q({id:e.id,modelValue:e.active,"onUpdate:modelValue":u[0]||(u[0]=c=>e.active=c),name:e.name,disabled:e.disabled,class:e.switchClass},e.attrs),{default:T(()=>[J("span",{class:d([e.active?e.ui.container.active:e.ui.container.inactive,e.ui.container.base])},[e.onIcon?(k(),I("span",{key:0,class:d([e.active?e.ui.icon.active:e.ui.icon.inactive,e.ui.icon.base]),"aria-hidden":"true"},[V(t,{name:e.onIcon,class:d(e.onIconClass)},null,8,["name","class"])],2)):B("",!0),e.offIcon?(k(),I("span",{key:1,class:d([e.active?e.ui.icon.inactive:e.ui.icon.active,e.ui.icon.base]),"aria-hidden":"true"},[V(t,{name:e.offIcon,class:d(e.offIconClass)},null,8,["name","class"])],2)):B("",!0)],2)]),_:1},16,["id","modelValue","name","disabled","class"])}const we=Z(ce,[["render",de]]);export{we as default};
