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