import{o as e,r as t,t as n}from"./jsx-runtime-Bypl69v7.js";import{i as r,o as i}from"./button-CYVyx32W.js";import{a,o,r as s,t as c}from"./dist-D46zjeVv.js";import{n as l,t as u}from"./dist-CHib8SFu.js";var d=e(t(),1),f=n(),p=`Switch`,[m,h]=a(p),[g,_]=m(p);function v(e){let{__scopeSwitch:t,checked:n,children:r,defaultChecked:i,disabled:a,form:o,name:s,onCheckedChange:l,required:u,value:m=`on`,internal_do_not_use_render:h}=e,[_,v]=c({prop:n,defaultProp:i??!1,onChange:l,caller:p}),[y,b]=d.useState(null),[x,S]=d.useState(null),C={checked:_,setChecked:v,disabled:a,control:y,setControl:b,name:s,form:o,value:m,hasConsumerStoppedPropagationRef:d.useRef(!1),required:u,defaultChecked:i,isFormControl:!y||!!o||!!y.closest(`form`),bubbleInput:x,setBubbleInput:S};return(0,f.jsx)(g,{scope:t,...C,children:E(h)?h(C):r})}var y=`SwitchTrigger`,b=d.forwardRef(({__scopeSwitch:e,onClick:t,...n},i)=>{let{control:a,form:c,value:l,disabled:u,checked:p,required:m,setControl:h,setChecked:g,hasConsumerStoppedPropagationRef:v,isFormControl:b,bubbleInput:x}=_(y,e),S=r(i,h),C=d.useRef(p);return d.useEffect(()=>{let e=c?a?.ownerDocument.getElementById(c):a?.form;if(e instanceof HTMLFormElement){let t=()=>g(C.current);return e.addEventListener(`reset`,t),()=>e.removeEventListener(`reset`,t)}},[a,c,g]),(0,f.jsx)(s.button,{type:`button`,role:`switch`,"aria-checked":p,"aria-required":m,"data-state":D(p),"data-disabled":u?``:void 0,disabled:u,value:l,...n,ref:S,onClick:o(t,e=>{g(e=>!e),x&&b&&(v.current=e.isPropagationStopped(),v.current||e.stopPropagation())})})});b.displayName=y;var x=d.forwardRef((e,t)=>{let{__scopeSwitch:n,name:r,checked:i,defaultChecked:a,required:o,disabled:s,value:c,onCheckedChange:l,form:u,...d}=e;return(0,f.jsx)(v,{__scopeSwitch:n,checked:i,defaultChecked:a,disabled:s,required:o,onCheckedChange:l,name:r,form:u,value:c,internal_do_not_use_render:({isFormControl:e})=>(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(b,{...d,ref:t,__scopeSwitch:n}),e&&(0,f.jsx)(T,{__scopeSwitch:n})]})})});x.displayName=p;var S=`SwitchThumb`,C=d.forwardRef((e,t)=>{let{__scopeSwitch:n,...r}=e,i=_(S,n);return(0,f.jsx)(s.span,{"data-state":D(i.checked),"data-disabled":i.disabled?``:void 0,...r,ref:t})});C.displayName=S;var w=`SwitchBubbleInput`,T=d.forwardRef(({__scopeSwitch:e,...t},n)=>{let{control:i,hasConsumerStoppedPropagationRef:a,checked:o,defaultChecked:c,required:p,disabled:m,name:h,value:g,form:v,bubbleInput:y,setBubbleInput:b}=_(w,e),x=r(n,b),S=u(o),C=l(i);d.useEffect(()=>{let e=y;if(!e)return;let t=window.HTMLInputElement.prototype,n=Object.getOwnPropertyDescriptor(t,`checked`).set,r=!a.current;if(S!==o&&n){let t=new Event(`click`,{bubbles:r});n.call(e,o),e.dispatchEvent(t)}},[y,S,o,a]);let T=d.useRef(o);return(0,f.jsx)(s.input,{type:`checkbox`,"aria-hidden":!0,defaultChecked:c??T.current,required:p,disabled:m,name:h,value:g,form:v,...t,tabIndex:-1,ref:x,style:{...t.style,...C,position:`absolute`,pointerEvents:`none`,opacity:0,margin:0,transform:`translateX(-100%)`}})});T.displayName=w;function E(e){return typeof e==`function`}function D(e){return e?`checked`:`unchecked`}var O=d.forwardRef(({className:e,...t},n)=>(0,f.jsx)(x,{className:i(`peer inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent shadow-sm 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),...t,ref:n,children:(0,f.jsx)(C,{className:i(`pointer-events-none block h-4 w-4 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-4 data-[state=unchecked]:translate-x-0`)})}));O.displayName=x.displayName;export{O as t};