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