import{i as G,U,G as _,w as A,C as g,I as B,y as H,T as K,o as f,c as M,p as N,d as O,s as R,x as j,r as q,e as S,f as z}from"./index-BbBXKozi.js";import{B as J,F as Q}from"./label-DP1H2-kl.js";const a=await G("react"),{createContext:V,Fragment:W,useContext:X,useEffect:Y,useMemo:x,useRef:Z,useState:ee}=a;let w=V(null);w.displayName="GroupContext";let te=W;function ae(l){var o;let[t,s]=ee(null),[u,h]=Q(),[r,v]=A(),c=x(()=>({switch:t,setSwitch:s,labelledby:u,describedby:r}),[t,s,u,r]),d={},y=l;return a.createElement(v,{name:"Switch.Description"},a.createElement(h,{name:"Switch.Label",props:{htmlFor:(o=c.switch)==null?void 0:o.id,onClick(p){t&&(p.currentTarget.tagName==="LABEL"&&p.preventDefault(),t.click(),t.focus({preventScroll:!0}))}}},a.createElement(w.Provider,{value:c},g({ourProps:d,theirProps:y,defaultTag:te,name:"Switch.Group"}))))}let le="button";function re(l,o){var t;let s=B(),{id:u=`headlessui-switch-${s}`,checked:h,defaultChecked:r=!1,onChange:v,disabled:c=!1,name:d,value:y,form:p,...E}=l,n=X(w),b=Z(null),C=H(b,o,n===null?null:n.setSwitch),[i,m]=K(h,v,r),k=f(()=>m?.(!i)),T=f(e=>{if(q(e.currentTarget))return e.preventDefault();e.preventDefault(),k()}),D=f(e=>{e.key===S.Space?(e.preventDefault(),k()):e.key===S.Enter&&z(e.currentTarget)}),P=f(e=>e.preventDefault()),F=x(()=>({checked:i}),[i]),I={id:u,ref:C,role:"switch",type:M(l,b),tabIndex:l.tabIndex===-1?0:(t=l.tabIndex)!=null?t:0,"aria-checked":i,"aria-labelledby":n?.labelledby,"aria-describedby":n?.describedby,disabled:c,onClick:T,onKeyUp:D,onKeyPress:P},L=N();return Y(()=>{var e;let $=(e=b.current)==null?void 0:e.closest("form");$&&r!==void 0&&L.addEventListener($,"reset",()=>{m(r)})},[b,m]),a.createElement(a.Fragment,null,d!=null&&i&&a.createElement(O,{features:R.Hidden,...j({as:"input",type:"checkbox",hidden:!0,readOnly:!0,disabled:c,form:p,checked:i,name:d,value:y})}),g({ourProps:I,theirProps:E,slot:F,defaultTag:le,name:"Switch"}))}let ne=U(re),ie=ae,se=Object.assign(ne,{Group:ie,Label:J,Description:_});export{se as _}; //# sourceMappingURL=switch-XJtiTVLZ.js.map