import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _createSuper from "@babel/runtime/helpers/createSuper";
var _excluded = ["prefixCls", "className", "children", "indeterminate", "style", "onMouseEnter", "onMouseLeave"];
import React, { Component } from 'react';
import classNames from 'classnames';
import shallowEqual from 'shallowequal';
import RcCheckbox from '../rc-components/checkbox';
import CheckboxContext from './CheckboxContext';

var Checkbox = /*#__PURE__*/function (_Component) {
  _inherits(Checkbox, _Component);

  var _super = _createSuper(Checkbox);

  function Checkbox() {
    var _this;

    _classCallCheck(this, Checkbox);

    _this = _super.apply(this, arguments);

    _this.saveCheckbox = function (node) {
      _this.rcCheckbox = node;
    };

    return _this;
  }

  _createClass(Checkbox, [{
    key: "shouldComponentUpdate",
    value: function shouldComponentUpdate(nextProps, nextState, nextContext) {
      var _this$context = this.context,
          checkboxGroup = _this$context.checkboxGroup,
          getPrefixCls = _this$context.getPrefixCls;
      return !shallowEqual(this.props, nextProps) || !shallowEqual(this.state, nextState) || !shallowEqual(checkboxGroup, nextContext.checkboxGroup) || getPrefixCls !== nextContext.getPrefixCls;
    }
  }, {
    key: "focus",
    value: function focus() {
      this.rcCheckbox.focus();
    }
  }, {
    key: "blur",
    value: function blur() {
      this.rcCheckbox.blur();
    }
  }, {
    key: "render",
    value: function render() {
      var props = this.props,
          context = this.context;

      var customizePrefixCls = props.prefixCls,
          className = props.className,
          children = props.children,
          indeterminate = props.indeterminate,
          style = props.style,
          onMouseEnter = props.onMouseEnter,
          onMouseLeave = props.onMouseLeave,
          restProps = _objectWithoutProperties(props, _excluded);

      var checkboxGroup = context.checkboxGroup,
          getPrefixCls = context.getPrefixCls;
      var prefixCls = getPrefixCls('checkbox', customizePrefixCls);

      var checkboxProps = _objectSpread({}, restProps);

      if (checkboxGroup) {
        checkboxProps.onChange = function () {
          return checkboxGroup.toggleOption({
            label: children,
            value: props.value
          });
        };

        checkboxProps.checked = checkboxGroup.value.indexOf(props.value) !== -1;
        checkboxProps.disabled = props.disabled || checkboxGroup.disabled;
      }

      var classString = classNames(className, _defineProperty({}, "".concat(prefixCls, "-wrapper"), true));
      var checkboxClass = classNames(_defineProperty({}, "".concat(prefixCls, "-indeterminate"), indeterminate));
      return /*#__PURE__*/React.createElement("label", {
        className: classString,
        style: style,
        onMouseEnter: onMouseEnter,
        onMouseLeave: onMouseLeave
      }, /*#__PURE__*/React.createElement(RcCheckbox, _extends({}, checkboxProps, {
        prefixCls: prefixCls,
        className: checkboxClass,
        ref: this.saveCheckbox
      })), children !== undefined ? /*#__PURE__*/React.createElement("span", null, children) : null);
    }
  }], [{
    key: "contextType",
    get: function get() {
      return CheckboxContext;
    }
  }]);

  return Checkbox;
}(Component);

export { Checkbox as default };
Checkbox.displayName = 'Checkbox';
Checkbox.defaultProps = {
  indeterminate: false
};
//# sourceMappingURL=Checkbox.js.map
