'use strict';

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

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

var _reactDnd = require('react-dnd');

var _DragGroupDropAreaContent = require('./styles/DragGroupDropAreaContent');

var _DragGroupDropAreaContent2 = _interopRequireDefault(_DragGroupDropAreaContent);

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

/**
 * The droppable area of a DragGroup. Connected to react-dnd.
 * Renders its children when idle, but if a dragging operation is
 * ongoing, its default Content presenter will render a
 * drop zone box.
 *
 * You may reference this component if you choose to override it
 * in DragGroup, otherwise it is not needed. See DragGroup docs.
 */
var DragGroupDropArea = function (_React$Component) {
  (0, _inherits3.default)(DragGroupDropArea, _React$Component);

  function DragGroupDropArea() {
    (0, _classCallCheck3.default)(this, DragGroupDropArea);
    return (0, _possibleConstructorReturn3.default)(this, (DragGroupDropArea.__proto__ || (0, _getPrototypeOf2.default)(DragGroupDropArea)).apply(this, arguments));
  }

  (0, _createClass3.default)(DragGroupDropArea, [{
    key: 'render',
    value: function render() {
      var _props = this.props,
          connectDropTarget = _props.connectDropTarget,
          Content = _props.Content,
          canDrop = _props.canDrop,
          isOver = _props.isOver,
          children = _props.children;

      return connectDropTarget(_react2.default.createElement(
        'div',
        null,
        _react2.default.createElement(
          Content,
          { canDrop: canDrop, isOver: isOver },
          children
        )
      ));
    }
  }]);
  return DragGroupDropArea;
}(_react2.default.Component);

DragGroupDropArea.propTypes = {
  itemType: _propTypes2.default.string.isRequired,
  groupId: _propTypes2.default.number.isRequired,
  Content: _propTypes2.default.func
};
DragGroupDropArea.defaultProps = {
  Content: _DragGroupDropAreaContent2.default
};


var dropSource = {
  drop: function drop(props) {
    return {
      type: 'group',
      groupId: props.groupId
    };
  }
};

var collect = function collect(connect, monitor) {
  return {
    connectDropTarget: connect.dropTarget(),
    canDrop: monitor.canDrop(),
    isOver: monitor.isOver()
  };
};

exports.default = (0, _reactDnd.DropTarget)(function (props) {
  return props.itemType;
}, dropSource, collect)(DragGroupDropArea);