import{a as e,t}from"./react-D0JuimcS.js";import{a as n,i as r,r as i,t as a}from"./dist-ByPkKdya.js";import{o,t as s}from"./utils-Dac180Gn.js";import{a as c}from"./dist-DoFivJu8.js";import{t as l}from"./dist-DAdKzsWl.js";import{t as u}from"./dist-CDFNpkT2.js";var d=e(t(),1),f=o(),p=`Switch`,[m,h]=r(p),[g,_]=m(p);function v(e){let{__scopeSwitch:t,checked:n,children:r,defaultChecked:i,disabled:o,form:s,name:c,onCheckedChange:l,required:u,value:m=`on`,internal_do_not_use_render:h}=e,[_,v]=a({prop:n,defaultProp:i??!1,onChange:l,caller:p}),[y,b]=d.useState(null),[x,S]=d.useState(null),C={checked:_,setChecked:v,disabled:o,control:y,setControl:b,name:c,form:s,value:m,hasConsumerStoppedPropagationRef:d.useRef(!1),required:u,defaultChecked:i,isFormControl:y?!!s||!!y.closest(`form`):!0,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,...r},a)=>{let{value:o,disabled:s,checked:l,required:u,setControl:d,setChecked:p,hasConsumerStoppedPropagationRef:m,isFormControl:h,bubbleInput:g}=_(y,e),v=c(a,d);return(0,f.jsx)(n.button,{type:`button`,role:`switch`,"aria-checked":l,"aria-required":u,"data-state":D(l),"data-disabled":s?``:void 0,disabled:s,value:o,...r,ref:v,onClick:i(t,e=>{p(e=>!e),g&&h&&(m.current=e.isPropagationStopped(),m.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:r,...i}=e,a=_(S,r);return(0,f.jsx)(n.span,{"data-state":D(a.checked),"data-disabled":a.disabled?``:void 0,...i,ref:t})});C.displayName=S;var w=`SwitchBubbleInput`,T=d.forwardRef(({__scopeSwitch:e,...t},r)=>{let{control:i,hasConsumerStoppedPropagationRef:a,checked:o,defaultChecked:s,required:p,disabled:m,name:h,value:g,form:v,bubbleInput:y,setBubbleInput:b}=_(w,e),x=c(r,b),S=l(o),C=u(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)(n.input,{type:`checkbox`,"aria-hidden":!0,defaultChecked:s??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`}function O({className:e,size:t=`default`,...n}){return(0,f.jsx)(x,{"data-slot":`switch`,"data-size":t,className:s(`peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-input focus-visible:border-ring focus-visible:ring-ring/50 dark:data-[state=unchecked]:bg-input/80 group/switch inline-flex shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-[1.15rem] data-[size=default]:w-8 data-[size=sm]:h-3.5 data-[size=sm]:w-6`,e),...n,children:(0,f.jsx)(C,{"data-slot":`switch-thumb`,className:s(`bg-background dark:data-[state=unchecked]:bg-foreground dark:data-[state=checked]:bg-primary-foreground pointer-events-none block rounded-full ring-0 transition-transform group-data-[size=default]/switch:size-4 group-data-[size=sm]/switch:size-3 data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0`)})})}export{O as t};