import{r as s,ci as C,cj as I,j as a,bK as y,ck as M,cl as H,cm as A,cn as U,a as g}from"./index-B2TpLIOm.js";var b="Switch",[q]=U(b),[z,L]=q(b),P=s.forwardRef((t,r)=>{const{__scopeSwitch:e,name:n,checked:o,defaultChecked:m,required:d,disabled:c,value:l="on",onCheckedChange:v,form:i,...w}=t,[u,p]=s.useState(null),k=C(r,h=>p(h)),S=s.useRef(!1),x=u?i||!!u.closest("form"):!0,[f,B]=I({prop:o,defaultProp:m??!1,onChange:v,caller:b});return a.jsxs(z,{scope:e,checked:f,disabled:c,children:[a.jsx(y.button,{type:"button",role:"switch","aria-checked":f,"aria-required":d,"data-state":N(f),"data-disabled":c?"":void 0,disabled:c,value:l,...w,ref:k,onClick:M(t.onClick,h=>{B(T=>!T),x&&(S.current=h.isPropagationStopped(),S.current||h.stopPropagation())})}),x&&a.jsx(j,{control:u,bubbles:!S.current,name:n,value:l,checked:f,required:d,disabled:c,form:i,style:{transform:"translateX(-100%)"}})]})});P.displayName=b;var E="SwitchThumb",R=s.forwardRef((t,r)=>{const{__scopeSwitch:e,...n}=t,o=L(E,e);return a.jsx(y.span,{"data-state":N(o.checked),"data-disabled":o.disabled?"":void 0,...n,ref:r})});R.displayName=E;var O="SwitchBubbleInput",j=s.forwardRef(({__scopeSwitch:t,control:r,checked:e,bubbles:n=!0,...o},m)=>{const d=s.useRef(null),c=C(d,m),l=H(e),v=A(r);return s.useEffect(()=>{const i=d.current;if(!i)return;const w=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(w,"checked").set;if(l!==e&&p){const k=new Event("click",{bubbles:n});p.call(i,e),i.dispatchEvent(k)}},[l,e,n]),a.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:e,...o,tabIndex:-1,ref:c,style:{...o.style,...v,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})});j.displayName=O;function N(t){return t?"checked":"unchecked"}var _=P,D=R;const F=s.forwardRef(({className:t,...r},e)=>a.jsx(_,{className:g("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",t),...r,ref:e,children:a.jsx(D,{className:g("pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=checked]:rtl:-translate-x-5 data-[state=unchecked]:translate-x-0")})}));F.displayName=_.displayName;export{F as S};
