import{r as o,cJ as _,cK as H,j as r,cH as x,cL as I,cM as M,cN as B,cI as q,bU as g}from"./index-B_1BLMrZ.js";var v="Switch",[z]=q(v),[A,L]=z(v),S=o.forwardRef((e,s)=>{const{__scopeSwitch:t,name:c,checked:n,defaultChecked:l,required:i,disabled:a,value:d="on",onCheckedChange:b,form:m,...p}=e,[u,E]=o.useState(null),R=_(s,f=>E(f)),k=o.useRef(!1),w=u?m||!!u.closest("form"):!0,[h=!1,N]=H({prop:n,defaultProp:l,onChange:b});return r.jsxs(A,{scope:t,checked:h,disabled:a,children:[r.jsx(x.button,{type:"button",role:"switch","aria-checked":h,"aria-required":i,"data-state":P(h),"data-disabled":a?"":void 0,disabled:a,value:d,...p,ref:R,onClick:I(e.onClick,f=>{N(T=>!T),w&&(k.current=f.isPropagationStopped(),k.current||f.stopPropagation())})}),w&&r.jsx(O,{control:u,bubbles:!k.current,name:c,value:d,checked:h,required:i,disabled:a,form:m,style:{transform:"translateX(-100%)"}})]})});S.displayName=v;var C="SwitchThumb",y=o.forwardRef((e,s)=>{const{__scopeSwitch:t,...c}=e,n=L(C,t);return r.jsx(x.span,{"data-state":P(n.checked),"data-disabled":n.disabled?"":void 0,...c,ref:s})});y.displayName=C;var O=e=>{const{control:s,checked:t,bubbles:c=!0,...n}=e,l=o.useRef(null),i=M(t),a=B(s);return o.useEffect(()=>{const d=l.current,b=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(b,"checked").set;if(i!==t&&p){const u=new Event("click",{bubbles:c});p.call(d,t),d.dispatchEvent(u)}},[i,t,c]),r.jsx("input",{type:"checkbox","aria-hidden":!0,defaultChecked:t,...n,tabIndex:-1,ref:l,style:{...e.style,...a,position:"absolute",pointerEvents:"none",opacity:0,margin:0}})};function P(e){return e?"checked":"unchecked"}var j=S,U=y;const D=o.forwardRef(({className:e,...s},t)=>r.jsx(j,{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-none 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",e),...s,ref:t,children:r.jsx(U,{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=unchecked]:translate-x-0")})}));D.displayName=j.displayName;export{D as S};
