import{r as i,j as n,m as H,P as _,g as z,i as S,k as N,W as G,Y as K,o as U,b as w}from"./index-DHiKqTn6.js";import{C as X}from"./check-DCv_Nj_2.js";var y="Checkbox",[W]=U(y),[Y,P]=W(y);function $(t){const{__scopeCheckbox:s,checked:r,children:l,defaultChecked:c,disabled:e,form:p,name:b,onCheckedChange:d,required:k,value:C="on",internal_do_not_use_render:u}=t,[f,v]=z({prop:r,defaultProp:c??!1,onChange:d,caller:y}),[m,x]=i.useState(null),[g,o]=i.useState(null),a=i.useRef(!1),E=m?!!p||!!m.closest("form"):!0,R={checked:f,disabled:e,setChecked:v,control:m,setControl:x,name:b,form:p,value:C,hasConsumerStoppedPropagationRef:a,required:k,defaultChecked:h(c)?!1:c,isFormControl:E,bubbleInput:g,setBubbleInput:o};return n.jsx(Y,{scope:s,...R,children:J(u)?u(R):l})}var B="CheckboxTrigger",M=i.forwardRef(({__scopeCheckbox:t,onKeyDown:s,onClick:r,...l},c)=>{const{control:e,value:p,disabled:b,checked:d,required:k,setControl:C,setChecked:u,hasConsumerStoppedPropagationRef:f,isFormControl:v,bubbleInput:m}=P(B,t),x=S(c,C),g=i.useRef(d);return i.useEffect(()=>{const o=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":h(d)?"mixed":d,"aria-required":k,"data-state":F(d),"data-disabled":b?"":void 0,disabled:b,value:p,...l,ref:x,onKeyDown:N(s,o=>{o.key==="Enter"&&o.preventDefault()}),onClick:N(r,o=>{u(a=>h(a)?!0:!a),m&&v&&(f.current=o.isPropagationStopped(),f.current||o.stopPropagation())})})});M.displayName=B;var I=i.forwardRef((t,s)=>{const{__scopeCheckbox:r,name:l,checked:c,defaultChecked:e,required:p,disabled:b,value:d,onCheckedChange:k,form:C,...u}=t;return n.jsx($,{__scopeCheckbox:r,checked:c,defaultChecked:e,disabled:b,required:p,onCheckedChange:k,name:l,form:C,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})]})})});I.displayName=y;var T="CheckboxIndicator",q=i.forwardRef((t,s)=>{const{__scopeCheckbox:r,forceMount:l,...c}=t,e=P(T,r);return n.jsx(H,{present:l||h(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:b,disabled:d,name:k,value:C,form:u,bubbleInput:f,setBubbleInput:v}=P(A,t),m=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=h(e),j.call(a,h(e)?!1:e),a.dispatchEvent(O)}},[f,x,e,c]);const o=i.useRef(h(e)?!1:e);return n.jsx(_.input,{type:"checkbox","aria-hidden":!0,defaultChecked:p??o.current,required:b,disabled:d,name:k,value:C,form:u,...s,tabIndex:-1,ref:m,style:{...s.style,...g,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});D.displayName=A;function J(t){return typeof t=="function"}function h(t){return t==="indeterminate"}function F(t){return h(t)?"indeterminate":t?"checked":"unchecked"}const Q=i.forwardRef(({className:t,...s},r)=>n.jsx(I,{ref:r,className:w("peer h-4 w-4 shrink-0 rounded-[3px] 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"})})}));Q.displayName=I.displayName;export{Q as C};
