'use strict';

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

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

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 }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var DragBoxSelect = function (_React$Component) {
  _inherits(DragBoxSelect, _React$Component);

  function DragBoxSelect() {
    var _ref;

    var _temp, _this, _ret;

    _classCallCheck(this, DragBoxSelect);

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

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

      return _react2.default.createElement(DragBox, _extends({}, _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(_extends({}, dragBoxProps, selectableProps));
        }
      }));
    }, _temp), _possibleConstructorReturn(_this, _ret);
  }

  _createClass(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;