text: 'use strict';
  
  exports.__esModule = 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; };
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
  
  function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
  
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
  
  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 _react = require('react');
  
  var _react2 = _interopRequireDefault(_react);
  
  var _reactDom = require('react-dom');
  
  var _reactDom2 = _interopRequireDefault(_reactDom);
  
  var _classnames = require('classnames');
  
  var _classnames2 = _interopRequireDefault(_classnames);
  
  var _utilsOwnerDocument = require('./utils/ownerDocument');
  
  var _utilsOwnerDocument2 = _interopRequireDefault(_utilsOwnerDocument);
  
  var _utilsGetContainer = require('./utils/getContainer');
  
  var _utilsGetContainer2 = _interopRequireDefault(_utilsGetContainer);
  
  var _utilsOverlayPositionUtils = require('./utils/overlayPositionUtils');
  
  var _reactPropTypesLibMountable = require('react-prop-types/lib/mountable');
  
  var _reactPropTypesLibMountable2 = _interopRequireDefault(_reactPropTypesLibMountable);
  
  /**
   * The Position component calulates the corrdinates for its child, to
   * position it relative to a `target` component or node. Useful for creating callouts and tooltips,
   * the Position component injects a `style` props with `left` and `top` values for positioning your component.
   *
   * It also injects "arrow" `left`, and `top` values for styling callout arrows for giving your components
   * a sense of directionality.
   */
  
  var Position = (function (_React$Component) {
    _inherits(Position, _React$Component);
  
    function Position(props, context) {
      _classCallCheck(this, Position);
  
      _React$Component.call(this, props, context);
  
      this.state = {
        positionLeft: 0,
        positionTop: 0,
        arrowOffsetLeft: null,
        arrowOffsetTop: null
      };
  
      this._needsFlush = false;
      this._lastTarget = null;
    }
  
    Position.prototype.componentDidMount = function componentDidMount() {
      this.updatePosition();
    };
  
    Position.prototype.componentWillReceiveProps = function componentWillReceiveProps() {
      this._needsFlush = true;
    };
  
    Position.prototype.componentDidUpdate = function componentDidUpdate(prevProps) {
      if (this._needsFlush) {
        this._needsFlush = false;
        this.updatePosition(prevProps.placement !== this.props.placement);
      }
    };
  
    Position.prototype.componentWillUnmount = function componentWillUnmount() {
      // Probably not necessary, but just in case holding a reference to the
      // target causes problems somewhere.
      this._lastTarget = null;
    };
  
    Position.prototype.render = function render() {
      var _props = this.props;
      var children = _props.children;
      var className = _props.className;
  
      var props = _objectWithoutProperties(_props, ['children', 'className']);
  
      var _state = this.state;
      var positionLeft = _state.positionLeft;
      var positionTop = _state.positionTop;
  
      var arrowPosition = _objectWithoutProperties(_state, ['positionLeft', 'positionTop']);
  
      // These should not be forwarded to the child.
      delete props.target;
      delete props.container;
      delete props.containerPadding;
  
      var child = _react2['default'].Children.only(children);
      return _react.cloneElement(child, _extends({}, props, arrowPosition, {
        //do we need to also forward positionLeft and positionTop if they are set to style?
        positionLeft: positionLeft,
        positionTop: positionTop,
        className: _classnames2['default'](className, child.props.className),
        style: _extends({}, child.props.style, {
          left: positionLeft,
          top: positionTop
        })
      }));
    };
  
    Position.prototype.getTargetSafe = function getTargetSafe() {
      if (!this.props.target) {
        return null;
      }
  
      var target = this.props.target(this.props);
      if (!target) {
        // This is so we can just use === check below on all falsy targets.
        return null;
      }
  
      return target;
    };
  
    Position.prototype.updatePosition = function updatePosition(placementChanged) {
      var target = this.getTargetSafe();
  
      if (!this.props.shouldUpdatePosition && target === this._lastTarget && !placementChanged) {
        return;
      }
  
      this._lastTarget = target;
  
      if (!target) {
        this.setState({
          positionLeft: 0,
          positionTop: 0,
          arrowOffsetLeft: null,
          arrowOffsetTop: null
        });
  
        return;
      }
  
      var overlay = _reactDom2['default'].findDOMNode(this);
      var container = _utilsGetContainer2['default'](this.props.container, _utilsOwnerDocument2['default'](this).body);
  
      this.setState(_utilsOverlayPositionUtils.calcOverlayPosition(this.props.placement, overlay, target, container, this.props.containerPadding));
    };
  
    return Position;
  })(_react2['default'].Component);
  
  Position.propTypes = {
    /**
     * Function mapping props to a DOM node the component is positioned next to
     *
     */
    target: _react2['default'].PropTypes.func,
  
    /**
     * "offsetParent" of the component
     */
    container: _react2['default'].PropTypes.oneOfType([_reactPropTypesLibMountable2['default'], _react2['default'].PropTypes.func]),
    /**
     * Minimum spacing in pixels between container border and component border
     */
    containerPadding: _react2['default'].PropTypes.number,
    /**
     * How to position the component relative to the target
     */
    placement: _react2['default'].PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
    /**
     * Whether the position should be changed on each update
     */
    shouldUpdatePosition: _react2['default'].PropTypes.bool
  };
  
  Position.displayName = 'Position';
  
  Position.defaultProps = {
    containerPadding: 0,
    placement: 'right',
    shouldUpdatePosition: false
  };
  
  exports['default'] = Position;
  module.exports = exports['default'];