import{c as H,u as S,j as n,d as _,e as N,f as z,M as G,N as K,x as U}from"./ui-vendor-Cn57k9R1.js";import{r as i}from"./react-vendor-B9tfxWGs.js";import{e as w,am as X}from"./index-DT-X9ySe.js";var y="Checkbox",[$,te]=H(y),[J,I]=$(y);function Q(t){const{__scopeCheckbox:s,checked:r,children:l,defaultChecked:c,disabled:e,form:p,name:h,onCheckedChange:d,required:k,value:m="on",internal_do_not_use_render:u}=t,[f,v]=U({prop:r,defaultProp:c??!1,onChange:d,caller:y}),[C,x]=i.useState(null),[g,o]=i.useState(null),a=i.useRef(!1),E=C?!!p||!!C.closest("form"):!0,R={checked:f,disabled:e,setChecked:v,control:C,setControl:x,name:h,form:p,value:m,hasConsumerStoppedPropagationRef:a,required:k,defaultChecked:b(c)?!1:c,isFormControl:E,bubbleInput:g,setBubbleInput:o};return n.jsx(J,{scope:s,...R,children:V(u)?u(R):l})}var B="CheckboxTrigger",M=i.forwardRef(({__scopeCheckbox:t,onKeyDown:s,onClick:r,...l},c)=>{const{control:e,value:p,disabled:h,checked:d,required:k,setControl:m,setChecked:u,hasConsumerStoppedPropagationRef:f,isFormControl:v,bubbleInput:C}=I(B,t),x=S(c,m),g=i.useRef(d);return i.useEffect(()=>{const o=e==null?void 0:e.form;if(o){const a=()=>u(g.current);return o.addEventListener("reset",a),()=>o.removeEventListener("reset",a)}},[e,u]),n.jsx(_.button,{type:"button",role:"checkbox","aria-checked":b(d)?"mixed":d,"aria-required":k,"data-state":F(d),"data-disabled":h?"":void 0,disabled:h,value:p,...l,ref:x,onKeyDown:N(s,o=>{o.key==="Enter"&&o.preventDefault()}),onClick:N(r,o=>{u(a=>b(a)?!0:!a),C&&v&&(f.current=o.isPropagationStopped(),f.current||o.stopPropagation())})})});M.displayName=B;var P=i.forwardRef((t,s)=>{const{__scopeCheckbox:r,name:l,checked:c,defaultChecked:e,required:p,disabled:h,value:d,onCheckedChange:k,form:m,...u}=t;return n.jsx(Q,{__scopeCheckbox:r,checked:c,defaultChecked:e,disabled:h,required:p,onCheckedChange:k,name:l,form:m,value:d,internal_do_not_use_render:({isFormControl:f})=>n.jsxs(n.Fragment,{children:[n.jsx(M,{...u,ref:s,__scopeCheckbox:r}),f&&n.jsx(D,{__scopeCheckbox:r})]})})});P.displayName=y;var T="CheckboxIndicator",q=i.forwardRef((t,s)=>{const{__scopeCheckbox:r,forceMount:l,...c}=t,e=I(T,r);return n.jsx(z,{present:l||b(e.checked)||e.checked===!0,children:n.jsx(_.span,{"data-state":F(e.checked),"data-disabled":e.disabled?"":void 0,...c,ref:s,style:{pointerEvents:"none",...t.style}})})});q.displayName=T;var A="CheckboxBubbleInput",D=i.forwardRef(({__scopeCheckbox:t,...s},r)=>{const{control:l,hasConsumerStoppedPropagationRef:c,checked:e,defaultChecked:p,required:h,disabled:d,name:k,value:m,form:u,bubbleInput:f,setBubbleInput:v}=I(A,t),C=S(r,v),x=G(e),g=K(l);i.useEffect(()=>{const a=f;if(!a)return;const E=window.HTMLInputElement.prototype,j=Object.getOwnPropertyDescriptor(E,"checked").set,L=!c.current;if(x!==e&&j){const O=new Event("click",{bubbles:L});a.indeterminate=b(e),j.call(a,b(e)?!1:e),a.dispatchEvent(O)}},[f,x,e,c]);const o=i.useRef(b(e)?!1:e);return n.jsx(_.input,{type:"checkbox","aria-hidden":!0,defaultChecked:p??o.current,required:h,disabled:d,name:k,value:m,form:u,...s,tabIndex:-1,ref:C,style:{...s.style,...g,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});D.displayName=A;function V(t){return typeof t=="function"}function b(t){return t==="indeterminate"}function F(t){return b(t)?"indeterminate":t?"checked":"unchecked"}const W=i.forwardRef(({className:t,...s},r)=>n.jsx(P,{ref:r,className:w("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",t),...s,children:n.jsx(q,{className:w("flex items-center justify-center text-current"),children:n.jsx(X,{className:"h-4 w-4"})})}));W.displayName=P.displayName;export{W as C};
