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