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

var _recompose = require('recompose');

var _StyleRoot = require('./styles/StyleRoot');

var _StyleRoot2 = _interopRequireDefault(_StyleRoot);

var _withDragDropContext = require('./withDragDropContext');

var _withDragDropContext2 = _interopRequireDefault(_withDragDropContext);

var _DragLayer = require('../DragLayer');

var _DragLayer2 = _interopRequireDefault(_DragLayer);

var _reactDom = require('react-dom');

var _reactDom2 = _interopRequireDefault(_reactDom);

var _irisTheme = require('../../theme/irisTheme');

var _irisTheme2 = _interopRequireDefault(_irisTheme);

require('./styles/global');

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

// injects a global stylesheet

/**
 * Including this provider at the root of your app will define some global styling,
 * and set up needed contexts for interactions like drag and drop. It also allows
 * you to control the theme programmatically or apply a different theme at a
 * particular level.
 */
var BandwidthProvider = function (_React$PureComponent) {
  (0, _inherits3.default)(BandwidthProvider, _React$PureComponent);

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

  (0, _createClass3.default)(BandwidthProvider, [{
    key: 'render',
    value: function render() {
      var _props = this.props,
          StyleRoot = _props.StyleRoot,
          DragLayer = _props.DragLayer,
          dragLayerPortal = _props.dragLayerPortal,
          customTheme = _props.customTheme,
          children = _props.children;

      var styleRootProps = {};
      if (customTheme) styleRootProps.customTheme = customTheme;
      return _react2.default.createElement(
        StyleRoot,
        (0, _extends3.default)({ className: 'styleroot' }, styleRootProps),
        children,
        dragLayerPortal ? _reactDom2.default.createPortal(_react2.default.createElement(DragLayer, null), dragLayerPortal) : _react2.default.createElement(DragLayer, null)
      );
    }
  }]);
  return BandwidthProvider;
}(_react2.default.PureComponent);

BandwidthProvider.propTypes = {
  /**
   *  A custom theme; pass one of the themes from `themes/` or pass in your own JSON!
   */
  customTheme: _propTypes2.default.object,
  /**
   * The DOM element to attach the drag layer. By default, attaches it to this component
   */
  dragLayerPortal: _propTypes2.default.object,
  /**
   * Custom StyleRoot component
   */
  StyleRoot: _propTypes2.default.oneOfType([_propTypes2.default.func, _propTypes2.default.symbol]),
  /**
   * Custom drag layer component
   */
  DragLayer: _propTypes2.default.func,
  children: _propTypes2.default.node.isRequired
};
BandwidthProvider.defaultProps = {
  customTheme: _irisTheme2.default,
  dragLayerPortal: null,
  StyleRoot: _StyleRoot2.default,
  DragLayer: _DragLayer2.default
};
exports.default = (0, _withDragDropContext2.default)(BandwidthProvider);