import{bE as D,r as t,bL as S,bF as B,bH as w,bI as v,bJ as E,bK as M,e2 as q,j as l,av as C,I as j}from"./index-f9c70843.js";import{b as K}from"./index-d8909728.js";const N="Checkbox",[L,U]=D(N),[O,A]=L(N),H=t.forwardRef((e,c)=>{const{__scopeCheckbox:r,name:d,checked:u,defaultChecked:a,required:p,disabled:i,value:b="on",onCheckedChange:h,...g}=e,[n,m]=t.useState(null),_=S(c,o=>m(o)),x=t.useRef(!1),y=n?!!n.closest("form"):!0,[f=!1,k]=B({prop:u,defaultProp:a,onChange:h}),I=t.useRef(f);return t.useEffect(()=>{const o=n==null?void 0:n.form;if(o){const $=()=>k(I.current);return o.addEventListener("reset",$),()=>o.removeEventListener("reset",$)}},[n,k]),t.createElement(O,{scope:r,state:f,disabled:i},t.createElement(w.button,v({type:"button",role:"checkbox","aria-checked":s(f)?"mixed":f,"aria-required":p,"data-state":P(f),"data-disabled":i?"":void 0,disabled:i,value:b},g,{ref:_,onKeyDown:E(e.onKeyDown,o=>{o.key==="Enter"&&o.preventDefault()}),onClick:E(e.onClick,o=>{k($=>s($)?!0:!$),y&&(x.current=o.isPropagationStopped(),x.current||o.stopPropagation())})})),y&&t.createElement(X,{control:n,bubbles:!x.current,name:d,value:b,checked:f,required:p,disabled:i,style:{transform:"translateX(-100%)"}}))}),F="CheckboxIndicator",T=t.forwardRef((e,c)=>{const{__scopeCheckbox:r,forceMount:d,...u}=e,a=A(F,r);return t.createElement(M,{present:d||s(a.state)||a.state===!0},t.createElement(w.span,v({"data-state":P(a.state),"data-disabled":a.disabled?"":void 0},u,{ref:c,style:{pointerEvents:"none",...e.style}})))}),X=e=>{const{control:c,checked:r,bubbles:d=!0,...u}=e,a=t.useRef(null),p=K(r),i=q(c);return t.useEffect(()=>{const b=a.current,h=window.HTMLInputElement.prototype,n=Object.getOwnPropertyDescriptor(h,"checked").set;if(p!==r&&n){const m=new Event("click",{bubbles:d});b.indeterminate=s(r),n.call(b,s(r)?!1:r),b.dispatchEvent(m)}},[p,r,d]),t.createElement("input",v({type:"checkbox","aria-hidden":!0,defaultChecked:s(r)?!1:r},u,{tabIndex:-1,ref:a,style:{...e.style,...i,position:"absolute",pointerEvents:"none",opacity:0,margin:0}}))};function s(e){return e==="indeterminate"}function P(e){return s(e)?"indeterminate":e?"checked":"unchecked"}const R=H,z=T,J=t.forwardRef(({className:e,...c},r)=>l.jsx(R,{ref:r,className:C("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:l.jsx(z,{className:C("flex items-center justify-center text-current"),children:l.jsx(j,{name:"Check",className:"h-4 w-4 stroke-2"})})}));J.displayName=R.displayName;const V=({className:e="",checked:c})=>l.jsx("div",{className:C(e,"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",c?"bg-primary text-primary-foreground":""),children:c&&l.jsx("div",{className:"flex items-center justify-center text-current",children:l.jsx(j,{name:"Check",className:"h-4 w-4"})})});export{J as C,V as a};
