'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');

var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 *  **DragBoxSelect** is a specialized usage of [DragBox](/#!/DragBox) that is also accessible via `DragBox.Select`. It is
 *  provided as a convenience as it is a commonly used group of components. All properties available in both
 *  [Selectable](/#!/Selectable) and [DragBox](/#!/DragBox) are passed into the `renderContents`
 *  render prop for **DragBoxSelect**.
 */
var DragBoxSelect = function (_React$Component) {
  (0, _inherits3.default)(DragBoxSelect, _React$Component);

  function DragBoxSelect() {
    var _ref;

    var _temp, _this, _ret;

    (0, _classCallCheck3.default)(this, DragBoxSelect);

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

    return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = DragBoxSelect.__proto__ || (0, _getPrototypeOf2.default)(DragBoxSelect)).call.apply(_ref, [this].concat(args))), _this), _this.renderDragBox = function (selectableProps) {
      var _this2 = _this,
          _renderContents = _this2.props.renderContents;

      return _react2.default.createElement(DragBox, (0, _extends3.default)({}, _this.props, {
        onCollisionBegin: function onCollisionBegin(items) {
          return items.forEach(selectableProps.toggleItem);
        },
        onCollisionEnd: function onCollisionEnd(items) {
          return items.forEach(selectableProps.toggleItem);
        },
        renderContents: function renderContents(dragBoxProps) {
          return _renderContents((0, _extends3.default)({}, dragBoxProps, selectableProps));
        }
      }));
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  (0, _createClass3.default)(DragBoxSelect, [{
    key: 'render',
    value: function render() {
      return _react2.default.createElement(Selectable, { render: this.renderDragBox });
    }
  }]);
  return DragBoxSelect;
}(_react2.default.Component);

DragBoxSelect.propTypes = {
  /**
   * Callback invoked when the mouse is clicked in the **DragBoxSelect** area
   */
  onMouseDown: _propTypes2.default.func,
  /**
   * Callback invoked when the mouse is released in the **DragBoxSelect** area.
   * Passed the **Set** of collision keys as its argument.
   */
  onMouseUp: _propTypes2.default.func,
  /**
   * Callback invoked when the **DragBoxSelect** box set of collisions changes.
   * Called with an object that has two keys, `added` and `removed`, each
   * with an array of items that were just added or removed respectively
   * to the collision set.
   */
  onCollisionChange: _propTypes2.default.func,
  /**
   * Callback invoked when the **DragBoxSelect** box collides with new items
   * that it wasn't colliding with at the previous mouse position.
   * Called with an array of items that have just been collided with.
   */
  onCollisionBegin: _propTypes2.default.func,
  /**
   * Callback invoked when the **DragBoxSelect** box stops colliding with items
   * that it was colliding with at the previous mouse position.
   * Called with an array of items that have just stopped colliding.
   */
  onCollisionEnd: _propTypes2.default.func,
  /**
   * Render prop to render contents inside **DragBoxSelect**.
   * Supports all callbacks that **DragBoxSelect** itself supports as well as the following props:
   *
   * *collisions*: The **Set** of keys that are currently being collided with
   *
   * *getRef*: A function that should be passed into the `ref` property of each child
   * that can be selected by **DragBoxSelect**. It should be called with a unique key
   * for each component. For example, `<button ref={getRef("uniquekey")} key="uniquekey" />`.
   */
  renderContents: _propTypes2.default.func,
  /**
   * Render prop to render the draggable rectangle. It is passed an object with the left, top, width, and height of
   * the rectangle to be drawn should return the component to render.
   */
  renderRect: _propTypes2.default.func
};
exports.default = DragBoxSelect;