import{r as i,j as n,O as y,V as H,W as N,X as G,Y as L,Z as O,w as v,G as R}from"./index-C-gKvEDq.js";import{u as U}from"./command-CyAetjD5.js";var g="Switch",[W]=O(g),[X,P]=W(g);function D(t){const{__scopeSwitch:a,checked:s,children:c,defaultChecked:e,disabled:r,form:o,name:f,onCheckedChange:p,required:b,value:d="on",internal_do_not_use_render:l}=t,[u,w]=H({prop:s,defaultProp:e??!1,onChange:p,caller:g}),[h,m]=i.useState(null),[x,C]=i.useState(null),k=i.useRef(!1),S=h?!!o||!!h.closest("form"):!0,_={checked:u,setChecked:w,disabled:r,control:h,setControl:m,name:f,form:o,value:d,hasConsumerStoppedPropagationRef:k,required:b,defaultChecked:e,isFormControl:S,bubbleInput:x,setBubbleInput:C};return n.jsx(X,{scope:a,..._,children:Y(l)?l(_):c})}var I="SwitchTrigger",T=i.forwardRef(({__scopeSwitch:t,onClick:a,...s},c)=>{const{value:e,disabled:r,checked:o,required:f,setControl:p,setChecked:b,hasConsumerStoppedPropagationRef:d,isFormControl:l,bubbleInput:u}=P(I,t),w=N(c,p);return n.jsx(y.button,{type:"button",role:"switch","aria-checked":o,"aria-required":f,"data-state":q(o),"data-disabled":r?"":void 0,disabled:r,value:e,...s,ref:w,onClick:G(a,h=>{b(m=>!m),u&&l&&(d.current=h.isPropagationStopped(),d.current||h.stopPropagation())})})});T.displayName=I;var j=i.forwardRef((t,a)=>{const{__scopeSwitch:s,name:c,checked:e,defaultChecked:r,required:o,disabled:f,value:p,onCheckedChange:b,form:d,...l}=t;return n.jsx(D,{__scopeSwitch:s,checked:e,defaultChecked:r,disabled:f,required:o,onCheckedChange:b,name:c,form:d,value:p,internal_do_not_use_render:({isFormControl:u})=>n.jsxs(n.Fragment,{children:[n.jsx(T,{...l,ref:a,__scopeSwitch:s}),u&&n.jsx(M,{__scopeSwitch:s})]})})});j.displayName=g;var B="SwitchThumb",V=i.forwardRef((t,a)=>{const{__scopeSwitch:s,...c}=t,e=P(B,s);return n.jsx(y.span,{"data-state":q(e.checked),"data-disabled":e.disabled?"":void 0,...c,ref:a})});V.displayName=B;var z="SwitchBubbleInput",M=i.forwardRef(({__scopeSwitch:t,...a},s)=>{const{control:c,hasConsumerStoppedPropagationRef:e,checked:r,defaultChecked:o,required:f,disabled:p,name:b,value:d,form:l,bubbleInput:u,setBubbleInput:w}=P(z,t),h=N(s,w),m=U(r),x=L(c);i.useEffect(()=>{const k=u;if(!k)return;const S=window.HTMLInputElement.prototype,E=Object.getOwnPropertyDescriptor(S,"checked").set,A=!e.current;if(m!==r&&E){const F=new Event("click",{bubbles:A});E.call(k,r),k.dispatchEvent(F)}},[u,m,r,e]);const C=i.useRef(r);return n.jsx(y.input,{type:"checkbox","aria-hidden":!0,defaultChecked:o??C.current,required:f,disabled:p,name:b,value:d,form:l,...a,tabIndex:-1,ref:h,style:{...a.style,...x,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});M.displayName=z;function Y(t){return typeof t=="function"}function q(t){return t?"checked":"unchecked"}const Z=R("peer inline-flex 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-neutral-300 dark:data-[state=unchecked]:bg-neutral-600",{variants:{size:{default:"h-5 w-10",large:"h-6 w-12"}},defaultVariants:{size:"default"}}),$=R("pointer-events-none block rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=unchecked]:translate-x-0",{variants:{size:{default:"h-4 w-4 data-[state=checked]:translate-x-5",large:"h-5 w-5 data-[state=checked]:translate-x-6"}},defaultVariants:{size:"default"}}),J=R("font-medium",{variants:{size:{default:"text-sm leading-5",large:"text-base leading-6"}},defaultVariants:{size:"default"}}),K=i.forwardRef(({className:t,size:a,label:s,rtl:c=!1,...e},r)=>{const o=n.jsx(j,{className:v(Z({size:a,className:t})),...e,ref:r,children:n.jsx(V,{className:v($({size:a}))})});return s?n.jsxs("div",{className:v("inline-flex items-center gap-2.5",c&&"flex-row-reverse"),children:[o,n.jsx("label",{className:v(J({size:a}),"cursor-pointer select-none",e.disabled&&"opacity-50 cursor-not-allowed"),onClick:()=>!e.disabled&&e.onCheckedChange?.(!e.checked),children:s})]}):o});K.displayName=j.displayName;export{K as S};
