import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";

/**
 * CheckableTag.jsx
 *
 * @Author: zhangce
 * @Date: 17/8/23 上午11:37
 */
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
/**
 * CheckableTag
 * */

var CheckableTag =
/*#__PURE__*/
function (_React$PureComponent) {
  _inherits(CheckableTag, _React$PureComponent);

  function CheckableTag() {
    var _getPrototypeOf2;

    var _this;

    _classCallCheck(this, CheckableTag);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(CheckableTag)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _defineProperty(_assertThisInitialized(_this), "handleClick", function () {
      var _this$props = _this.props,
          checked = _this$props.checked,
          onChange = _this$props.onChange,
          disabled = _this$props.disabled;

      if (onChange && !disabled) {
        onChange(!checked);
      }
    });

    return _this;
  }

  _createClass(CheckableTag, [{
    key: "render",
    value: function render() {
      var _classNames;

      var _this$props2 = this.props,
          children = _this$props2.children,
          prefixCls = _this$props2.prefixCls,
          checked = _this$props2.checked,
          className = _this$props2.className,
          size = _this$props2.size,
          disabled = _this$props2.disabled,
          other = _objectWithoutProperties(_this$props2, ["children", "prefixCls", "checked", "className", "size", "disabled"]);

      var classString = classNames(prefixCls, "".concat(prefixCls, "-checkable"), "".concat(prefixCls, "-").concat(size), (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-checked"), checked), _defineProperty(_classNames, "".concat(prefixCls, "-disabled"), disabled), _classNames), className);
      return React.createElement("span", _extends({
        className: classString,
        onClick: this.handleClick
      }, other), children);
    }
  }]);

  return CheckableTag;
}(React.PureComponent);

_defineProperty(CheckableTag, "propTypes", {
  /**
   * 类前缀
   * */
  prefixCls: PropTypes.string,

  /**
   * 类名
   * */
  className: PropTypes.string,

  /**
   * 是否被选中
   * */
  checked: PropTypes.bool,

  /**
   * 是否禁用
   * */
  disabled: PropTypes.bool,

  /**
   * 标签大小
   * */
  size: PropTypes.oneOf(['small', 'medium', 'large']),

  /**
   * 选中状态改变回调
   * */
  onChange: PropTypes.func
});

_defineProperty(CheckableTag, "defaultProps", {
  prefixCls: 'ne-tag',
  checked: false,
  size: 'medium',
  disabled: false
});

export default CheckableTag;