import e,{forwardRef as a,useRef as t,useCallback as o,useEffect as i,useMemo as l}from"react";import n from"classnames";import{isNil as r,noop as s}from"es-toolkit";import{Icon as c}from"@vibe/icon/mockedClassNames";import{Remove as m,Check as d}from"@vibe/icons";import{useSupportFirefoxLabelClick as u}from"./hooks/useSupportFirefoxLabelClick.js";import p from"../../hooks/useMergeRef.js";import{getTestId as C}from"../../tests/testIds.js";import{ComponentDefaultTestId as b,ComponentVibeId as f}from"../../tests/constants.js";import E from"../Text/Text.js";import k from"./Checkbox.module.scss.js";var v=a((function(a,v){var h=a.className,x=a.checkboxClassName,N=a.labelClassName,B=a.ariaLabel,y=a.label,H=a.ariaLabelledBy,F=a.onChange,K=void 0===F?s:F,O=a.checked,X=a.autoFocus,g=a.indeterminate,L=void 0!==g&&g,j=a.disabled,w=void 0!==j&&j,S=a.defaultChecked,A=a.tabIndex,I=a.value,M=void 0===I?"":I,T=a.name,_=void 0===T?"":T,U=a.id,q=a.separateLabel,z=void 0!==q&&q,R=a["data-testid"],D=t(null),G=p(v,D),J=t(null),P=o((function(){var e=D.current;e&&window.requestAnimationFrame((function(){window.requestAnimationFrame((function(){e.blur()}))}))}),[D]),Q=S;r(Q)&&r(O)&&(Q=!1),i((function(){D.current&&(D.current.indeterminate=L)}),[D,L]);var V=u({inputRef:D}).onClickCapture,W=l((function(){return B||("string"==typeof y?y:"")}),[B,y]);return z?e.createElement("div",{className:n(k.wrapper,h),"data-testid":R||C(b.CHECKBOX,U),"data-vibe":f.CHECKBOX},e.createElement("input",{ref:G,id:U,className:k.input,value:M,name:_,type:"checkbox",autoFocus:X,onChange:K,defaultChecked:Q,disabled:w,"aria-label":W,"aria-labelledby":H,checked:O,tabIndex:A}),e.createElement("label",{htmlFor:U,className:n(k.checkbox,x),"data-testid":C(b.CHECKBOX_CHECKBOX,U),onMouseUp:P,onClickCapture:V},e.createElement(c,{className:k.icon,iconType:"svg",icon:L?m:d,ignoreFocusStyle:!0,ariaHidden:!0,iconSize:"16"})),!1===y?null:e.createElement("label",{htmlFor:U,className:n(k.label,N),"data-testid":C(b.CHECKBOX_LABEL,U),onMouseUp:P,onClickCapture:V},e.createElement(E,{element:"span",type:"text2"},y))):e.createElement("label",{className:n(k.wrapper,h),onMouseUp:P,"data-testid":R||C(b.CHECKBOX,U),htmlFor:U,onClickCapture:V,"data-vibe":f.CHECKBOX},e.createElement("input",{ref:G,id:U,className:k.input,value:M,name:_,type:"checkbox",autoFocus:X,onChange:K,defaultChecked:Q,disabled:w,"aria-label":W,"aria-labelledby":H,checked:O,tabIndex:A}),e.createElement("div",{className:n(k.checkbox,x),ref:J,"data-testid":C(b.CHECKBOX_CHECKBOX,U)},e.createElement(c,{className:k.icon,iconType:"svg",icon:L?m:d,ignoreFocusStyle:!0,ariaHidden:!0,iconSize:"16"})),!1===y?null:e.createElement(E,{element:"span",type:"text2",className:n(k.label,N),"data-testid":C(b.CHECKBOX_LABEL,U)},y))}));export{v as default};
//# sourceMappingURL=Checkbox.js.map
