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