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