"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));

var _react = _interopRequireWildcard(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _col = _interopRequireDefault(require("../../../lib/col"));

var _noop = _interopRequireDefault(require("lodash/noop"));

var _checkbox = _interopRequireDefault(require("../../../lib/checkbox"));

var ScreeningOption = /*#__PURE__*/function (_Component) {
  (0, _inherits2["default"])(ScreeningOption, _Component);

  var _super = (0, _createSuper2["default"])(ScreeningOption);

  function ScreeningOption() {
    var _this;

    (0, _classCallCheck2["default"])(this, ScreeningOption);
    _this = _super.apply(this, arguments);

    _this.onMouseLeave = function () {
      var _this$props = _this.props,
          optionkey = _this$props.optionkey,
          value = _this$props.value,
          onMouseLeave = _this$props.onMouseLeave;
      var info = {
        key: optionkey,
        value: value
      };

      if (onMouseLeave) {
        onMouseLeave(info);
      }
    };

    _this.onMouseEnter = function () {
      var _this$props2 = _this.props,
          optionkey = _this$props2.optionkey,
          value = _this$props2.value,
          onMouseEnter = _this$props2.onMouseEnter;
      var info = {
        key: optionkey,
        value: value
      };

      if (onMouseEnter) {
        onMouseEnter(info);
      }
    };

    _this.onClick = function () {
      var _this$props3 = _this.props,
          optionkey = _this$props3.optionkey,
          multiple = _this$props3.multiple,
          onClick = _this$props3.onClick,
          onSelect = _this$props3.onSelect,
          onDeselect = _this$props3.onDeselect,
          value = _this$props3.value,
          isSelected = _this$props3.isSelected;
      var info = {
        key: optionkey,
        value: value
      };

      if (onSelect && onClick) {
        onClick(info);

        if (multiple) {
          if (isSelected && onDeselect) {
            onDeselect(info);
          } else {
            onSelect(info);
          }
        } else {
          onSelect(info);
        }
      }
    };

    return _this;
  }

  (0, _createClass2["default"])(ScreeningOption, [{
    key: "render",
    value: function render() {
      var _classNames;

      var _this$props4 = this.props,
          prefixCls = _this$props4.prefixCls,
          disabled = _this$props4.disabled,
          children = _this$props4.children,
          optionkey = _this$props4.optionkey,
          active = _this$props4.active,
          style = _this$props4.style,
          multiple = _this$props4.multiple,
          onMouseDown = _this$props4.onMouseDown,
          isSelected = _this$props4.isSelected,
          span = _this$props4.span,
          order = _this$props4.order,
          offset = _this$props4.offset,
          push = _this$props4.push,
          pull = _this$props4.pull,
          xs = _this$props4.xs,
          sm = _this$props4.sm,
          md = _this$props4.md,
          lg = _this$props4.lg,
          xl = _this$props4.xl,
          xxl = _this$props4.xxl,
          optionRender = _this$props4.optionRender;
      var ScreeningOptionPrefix = "".concat(prefixCls, "-option");
      var className = (0, _classnames["default"])(ScreeningOptionPrefix, (_classNames = {}, (0, _defineProperty2["default"])(_classNames, "".concat(ScreeningOptionPrefix, "-disabled"), disabled), (0, _defineProperty2["default"])(_classNames, "".concat(ScreeningOptionPrefix, "-selected"), isSelected), (0, _defineProperty2["default"])(_classNames, "".concat(ScreeningOptionPrefix, "-active"), active), _classNames));
      var attrs = {
        optionkey: optionkey,
        className: className,
        span: span,
        order: order,
        offset: offset,
        push: push,
        pull: pull,
        xs: xs,
        sm: sm,
        md: md,
        lg: lg,
        xl: xl,
        xxl: xxl
      };
      var mouseEvent = {};

      if (!disabled) {
        mouseEvent = {
          onClick: this.onClick,
          onMouseLeave: this.onMouseLeave,
          onMouseEnter: this.onMouseEnter,
          onMouseDown: onMouseDown
        };
      }

      var checkbox = multiple ? /*#__PURE__*/_react["default"].createElement(_checkbox["default"], {
        checked: isSelected
      }) : null;
      return /*#__PURE__*/_react["default"].createElement(_col["default"], (0, _extends2["default"])({}, attrs, {
        style: style
      }), /*#__PURE__*/_react["default"].createElement("div", (0, _extends2["default"])({
        className: "".concat(ScreeningOptionPrefix, "-content")
      }, mouseEvent), optionRender || /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, checkbox, children)));
    }
  }]);
  return ScreeningOption;
}(_react.Component);

exports["default"] = ScreeningOption;
ScreeningOption.defaultProps = {
  onSelect: _noop["default"],
  onMouseEnter: _noop["default"],
  onMouseLeave: _noop["default"],
  onMouseDown: _noop["default"],
  isSelected: false
};
//# sourceMappingURL=ScreeningOption.js.map
