import{a as e,t}from"./react-DK-MTtD8.js";import{a as n,i as r,r as i,t as a}from"./dist-BcNll9eq.js";import{s as o,t as s}from"./utils-CXcsdpX-.js";import{i as c}from"./dist-DF_Cx1Kb.js";import{t as l}from"./dist-BOk69xU5.js";var u=e(t(),1),d=o(),f=Object.defineProperty,p=(e,t)=>f(e,`name`,{value:t,configurable:!0}),m=`Switch`,[h,g]=r(m),[_,v]=h(m);function y(e){let{__scopeSwitch:t,checked:n,children:r,defaultChecked:i,disabled:o,form:s,name:c,onCheckedChange:l,required:f,value:p=`on`,internal_do_not_use_render:h}=e,[g,v]=a({prop:n,defaultProp:i??!1,onChange:l,caller:m}),[y,b]=u.useState(null),[x,S]=u.useState(null),C=u.useRef(!1),[w,T]=u.useReducer(e=>e+1,0),E={checked:g,setChecked:v,disabled:o,control:y,setControl:b,name:c,form:s,value:p,hasConsumerStoppedPropagationRef:C,userInteractionCount:w,onUserInteraction:T,required:f,defaultChecked:i,isFormControl:!y||!!s||!!y.closest(`form`),bubbleInput:x,setBubbleInput:S};return(0,d.jsx)(_,{scope:t,...E,children:D(h)?h(E):r})}p(y,`SwitchProvider`);var b=`SwitchTrigger`,x=u.forwardRef(p(function({__scopeSwitch:e,onClick:t,...r},a){let{control:o,form:s,value:l,disabled:f,checked:m,required:h,setControl:g,setChecked:_,hasConsumerStoppedPropagationRef:y,onUserInteraction:x,isFormControl:S,bubbleInput:C}=v(b,e),w=c(a,g),T=u.useRef(m);return u.useEffect(()=>{let e=s?o?.ownerDocument.getElementById(s):o?.form;if(e instanceof HTMLFormElement){let t=p(()=>_(T.current),`reset`);return e.addEventListener(`reset`,t),()=>e.removeEventListener(`reset`,t)}},[o,s,_]),(0,d.jsx)(n.button,{type:`button`,role:`switch`,"aria-checked":m,"aria-required":h,"data-state":O(m),"data-disabled":f?``:void 0,disabled:f,value:l,...r,ref:w,onClick:i(t,e=>{x(),_(e=>!e),C&&S&&(y.current=e.isPropagationStopped(),y.current||e.stopPropagation())})})},`SwitchTrigger`)),S=u.forwardRef(p(function(e,t){let{__scopeSwitch:n,name:r,checked:i,defaultChecked:a,required:o,disabled:s,value:c,onCheckedChange:l,form:u,...f}=e;return(0,d.jsx)(y,{__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,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(x,{...f,ref:t,__scopeSwitch:n}),e&&(0,d.jsx)(E,{__scopeSwitch:n})]})})},`Switch`)),C=`SwitchThumb`,w=u.forwardRef(p(function(e,t){let{__scopeSwitch:r,...i}=e,a=v(C,r);return(0,d.jsx)(n.span,{"data-state":O(a.checked),"data-disabled":a.disabled?``:void 0,...i,ref:t})},`SwitchThumb`)),T=`SwitchBubbleInput`,E=u.forwardRef(p(function({__scopeSwitch:e,onClick:t,...r},a){let{control:o,hasConsumerStoppedPropagationRef:s,userInteractionCount:f,checked:p,defaultChecked:m,required:h,disabled:g,name:_,value:y,form:b,bubbleInput:x,setBubbleInput:S}=v(T,e),C=c(a,S),w=l(o),E=u.useRef(!1),D=u.useRef(p),O=u.useRef(f);u.useEffect(()=>{let e=x;if(!e)return;let t=window.HTMLInputElement.prototype,n=Object.getOwnPropertyDescriptor(t,`checked`).set,r=f!==O.current;O.current=f;let i=D.current!==p;D.current=p;let a=!(r&&s.current);if(i&&n){E.current=!r;let t=new Event(`click`,{bubbles:a});n.call(e,p),e.dispatchEvent(t),E.current=!1}},[x,p,s,f]);let k=u.useRef(p);return(0,d.jsx)(n.input,{type:`checkbox`,"aria-hidden":!0,defaultChecked:m??k.current,required:h,disabled:g,name:_,value:y,form:b,...r,tabIndex:-1,ref:C,onClick:i(t,e=>{E.current&&e.stopPropagation()}),style:{...r.style,...w,position:`absolute`,pointerEvents:`none`,opacity:0,margin:0,transform:`translateX(-100%)`}})},`SwitchBubbleInput`));function D(e){return typeof e==`function`}p(D,`isFunction`);function O(e){return e?`checked`:`unchecked`}p(O,`getState`);function k({className:e,size:t=`default`,...n}){return(0,d.jsx)(S,{"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,d.jsx)(w,{"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{k as t};