import React__default, { forwardRef, useId } from 'react';
import classnames from 'classnames';
import { I as Icon } from './Icon-es.js';
import { T as Text } from './Text-es.js';
import { f as filterDataAttributes } from './filterDataAttributes-es.js';

var styles = {"checkBoxParent":"YxKKPXAU10s-","wrapper":"KxWx-msbH9c-","disabled":"TKr3J-6ARFo-","checkHolder":"NO34ZbhNqhI-","input":"XnCmS-EzK2M-","checkBox":"_-8JCQE6SA9s-","indeterminate":"rqHq3ff9In0-","invalid":"Gqnclw4WaeQ-","label":"l8z5TxzVvqA-","description":"DcBfVgpiWa4-","spinning":"rFBN9M5-4Ok-"};

const Checkbox = forwardRef(function CheckboxInternal(props, ref) {
    const { checked, defaultChecked, disabled, label, name, value, indeterminate = false, description, id, onBlur, onChange, onFocus, onClick, onMouseDown, onMouseUp, onPointerDown, onPointerUp, invalid, } = props;
    const descriptionIdentifier = useId();
    const descriptionVisible = Boolean(description);
    const wrapperClassName = classnames(styles.wrapper, disabled && styles.disabled, invalid && styles.invalid);
    const isInvalid = Boolean(invalid);
    const inputClassName = classnames(styles.input, {
        [styles.indeterminate]: indeterminate,
    });
    const dataAttrs = filterDataAttributes(props);
    const iconName = indeterminate ? "minus2" : "checkmark";
    const labelContent = typeof label === "string" ? React__default.createElement(Text, null, label) : label;
    const descriptionContent = typeof description === "string" ? (React__default.createElement(Text, { size: "small", variation: "subdued" }, description)) : (description);
    function handleChange(event) {
        const newChecked = event.currentTarget.checked;
        onChange === null || onChange === void 0 ? void 0 : onChange(newChecked, event);
    }
    return (React__default.createElement("div", { className: styles.checkBoxParent },
        React__default.createElement("label", { className: wrapperClassName },
            React__default.createElement("span", { className: styles.checkHolder },
                React__default.createElement("input", Object.assign({ ref: ref, type: "checkbox", id: id, className: inputClassName, name: name, "aria-label": props["aria-label"], "aria-describedby": descriptionVisible
                        ? descriptionIdentifier
                        : props["aria-describedby"], "aria-invalid": isInvalid ? true : undefined, "aria-required": props["aria-required"], checked: checked, value: value, defaultChecked: defaultChecked, disabled: disabled, onChange: handleChange, onFocus: onFocus, onBlur: onBlur, onClick: onClick, onMouseDown: onMouseDown, onMouseUp: onMouseUp, onPointerDown: onPointerDown, onPointerUp: onPointerUp }, dataAttrs)),
                React__default.createElement("span", { className: styles.checkBox },
                    React__default.createElement(Icon, { name: iconName, color: "surface" }))),
            labelContent && React__default.createElement("span", { className: styles.label }, labelContent)),
        description && (React__default.createElement("div", { id: descriptionIdentifier, className: styles.description }, descriptionContent))));
});
Checkbox.displayName = "Checkbox";

export { Checkbox as C };
