import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["indeterminate", "className", "children"];
import React, { useImperativeHandle, useEffect, useCallback } from "react";
import PropTypes from "prop-types";
import cx from "classnames";
import getClasses from "./styles";
import { Check, Indeterminate } from "./icons";
var Checkbox = /*#__PURE__*/React.forwardRef(function (props, ref) {
  var classes = getClasses();

  var indeterminate = props.indeterminate,
      className = props.className,
      children = props.children,
      htmlProps = _objectWithoutProperties(props, _excluded);

  var checkboxRef = React.useRef(null);
  useImperativeHandle(ref, function () {
    return checkboxRef === null || checkboxRef === void 0 ? void 0 : checkboxRef.current;
  });
  useEffect(function () {
    if (checkboxRef.current) {
      checkboxRef.current.indeterminate = indeterminate;
    }
  }, [checkboxRef, indeterminate]);
  var handleClick = useCallback(function (ev) {
    ev.stopPropagation();
  }, []);
  return /*#__PURE__*/React.createElement("label", {
    onClick: handleClick,
    className: cx(classes.root, className)
  }, /*#__PURE__*/React.createElement("input", _extends({
    className: classes.input,
    type: "checkbox",
    ref: checkboxRef
  }, htmlProps)), /*#__PURE__*/React.createElement("span", {
    "aria-hidden": "true",
    className: classes.boxIcon
  }, indeterminate ? /*#__PURE__*/React.createElement(Indeterminate, null) : /*#__PURE__*/React.createElement(Check, {
    className: classes.checkSvg
  })), children && /*#__PURE__*/React.createElement("span", null, children));
});
Checkbox.propTypes = {
  checked: PropTypes.bool,
  indeterminate: PropTypes.bool,
  disabled: PropTypes.bool,
  onChange: PropTypes.func,
  name: PropTypes.string
};
Checkbox.defaultProps = {};

if (process.env.NODE_ENV !== "production") {
  Checkbox.displayName = "NextCheckbox";
}

export default Checkbox;