'use strict';

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

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

var _extends3 = _interopRequireDefault(_extends2);

var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');

var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);

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 _styledComponents = require('styled-components');

var _styledComponents2 = _interopRequireDefault(_styledComponents);

var _Icon = require('../Icon');

var _Icon2 = _interopRequireDefault(_Icon);

var _Container = require('./styles/Container');

var _Container2 = _interopRequireDefault(_Container);

var _ChildContainer = require('./styles/ChildContainer');

var _ChildContainer2 = _interopRequireDefault(_ChildContainer);

var _IconGroup = require('./styles/IconGroup');

var _IconGroup2 = _interopRequireDefault(_IconGroup);

var _DragContext = require('./DragContext');

var _DragContext2 = _interopRequireDefault(_DragContext);

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

var DragHandle = (0, _styledComponents2.default)(_Icon2.default).withConfig({
  displayName: 'DragContainer__DragHandle'
})(['&:hover:not(:active){cursor:pointer;}']);

var DefaultControls = _react2.default.createElement(
  _react2.default.Fragment,
  null,
  _react2.default.createElement(_Icon2.default, { name: 'settings' }),
  _react2.default.createElement(_Icon2.default, { name: 'delete3' })
);

/**
 * This is a prebuilt example container that can be used with [DragList](/#!/DragList)
 * or [DragGroup](/#!/DragGroup). It features a drag handle and a section that can have
 * controls for the item - just set `controls` to a react node and attach handlers for
 * the click events as needed.
 */

var DragContainer = function (_React$PureComponent) {
  (0, _inherits3.default)(DragContainer, _React$PureComponent);

  function DragContainer() {
    var _ref;

    var _temp, _this, _ret;

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

    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 = DragContainer.__proto__ || (0, _getPrototypeOf2.default)(DragContainer)).call.apply(_ref, [this].concat(args))), _this), _this.renderContents = function (_ref2) {
      var isDragging = _ref2.isDragging,
          wrapDragHandle = _ref2.wrapDragHandle;
      var _this$props = _this.props,
          canDrag = _this$props.canDrag,
          controls = _this$props.controls,
          children = _this$props.children,
          Container = _this$props.Container,
          ChildContainer = _this$props.ChildContainer,
          IconGroup = _this$props.IconGroup,
          rest = (0, _objectWithoutProperties3.default)(_this$props, ['canDrag', 'controls', 'children', 'Container', 'ChildContainer', 'IconGroup']);


      return _react2.default.createElement(
        Container,
        (0, _extends3.default)({ isDragging: isDragging }, rest),
        _react2.default.createElement(
          ChildContainer,
          { isDragging: isDragging },
          children
        ),
        _react2.default.createElement(
          IconGroup,
          { isDragging: isDragging },
          controls,
          canDrag && wrapDragHandle && wrapDragHandle(_react2.default.createElement(DragHandle, { name: 'moveGrabber' }))
        )
      );
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  (0, _createClass3.default)(DragContainer, [{
    key: 'render',
    value: function render() {
      return _react2.default.createElement(
        _DragContext2.default.Consumer,
        null,
        this.renderContents
      );
    }
  }]);
  return DragContainer;
}(_react2.default.PureComponent);

DragContainer.Context = _DragContext2.default;
DragContainer.propTypes = {
  /**
   * Should dragging be enabled or not?
   */
  canDrag: _propTypes2.default.bool,
  /**
   * Pass in custom controls for the list item.
   */
  controls: _propTypes2.default.node,
  children: _propTypes2.default.node.isRequired
};
DragContainer.defaultProps = {
  canDrag: true,
  controls: DefaultControls,
  Container: _Container2.default,
  ChildContainer: _ChildContainer2.default,
  IconGroup: _IconGroup2.default
};
exports.default = DragContainer;