'use strict';

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

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 _SidebarListShowMore = require('./styles/SidebarListShowMore');

var _SidebarListShowMore2 = _interopRequireDefault(_SidebarListShowMore);

var _SidebarListItem = require('./SidebarListItem');

var _SidebarListItem2 = _interopRequireDefault(_SidebarListItem);

var _SidebarListContainer = require('./styles/SidebarListContainer');

var _SidebarListContainer2 = _interopRequireDefault(_SidebarListContainer);

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

/**
 * Lays out items vertically in a sidebar. Does not handle scrolling.
 * Use [SidebarList.Item](/#!/SidebarListItem) as the child elements.
 *
 * You can show selected state by either passing an `active` prop to the correct item
 * or linking your list to your router so that each item is a unique route. If you go that direction,
 * you can wrap the items with `<Route/>` components from React Router, and have them utilize RR's
 * built-in route matching logic to determine rendering appearance.
 */
var SidebarList = function (_React$PureComponent) {
  (0, _inherits3.default)(SidebarList, _React$PureComponent);

  function SidebarList() {
    var _ref;

    var _temp, _this, _ret;

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

    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 = SidebarList.__proto__ || (0, _getPrototypeOf2.default)(SidebarList)).call.apply(_ref, [this].concat(args))), _this), _this.renderPrevious = function () {
      var _this$props = _this.props,
          hasPreviousPage = _this$props.hasPreviousPage,
          onPreviousPageClicked = _this$props.onPreviousPageClicked,
          ShowMore = _this$props.ShowMore;

      if (hasPreviousPage) {
        return _react2.default.createElement(
          ShowMore,
          { onClick: onPreviousPageClicked },
          'Show Previous'
        );
      }

      return null;
    }, _this.renderNext = function () {
      var _this$props2 = _this.props,
          hasNextPage = _this$props2.hasNextPage,
          onNextPageClicked = _this$props2.onNextPageClicked,
          ShowMore = _this$props2.ShowMore;

      if (hasNextPage) {
        return _react2.default.createElement(
          ShowMore,
          { onClick: onNextPageClicked },
          'Show Next'
        );
      }

      return null;
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  (0, _createClass3.default)(SidebarList, [{
    key: 'render',
    value: function render() {
      var _props = this.props,
          Container = _props.Container,
          children = _props.children,
          rest = (0, _objectWithoutProperties3.default)(_props, ['Container', 'children']);

      return _react2.default.createElement(
        Container,
        rest,
        this.renderPrevious(),
        children,
        this.renderNext()
      );
    }
  }]);
  return SidebarList;
}(_react2.default.PureComponent);

SidebarList.propTypes = {
  /**
   * List items.
   */
  children: _propTypes2.default.node.isRequired,
  /**
   * Indicates whether the list should show that it has a next page.
   */
  hasNextPage: _propTypes2.default.bool,
  /**
   * Indicates whether the list should show that it has a previous page.
   */
  hasPreviousPage: _propTypes2.default.bool,
  /**
   * Called when the button to load the next page is clicked.
   */
  onNextPageClicked: _propTypes2.default.func,
  /**
   * Called when the button to load the previous page is clicked.
   */
  onPreviousPageClicked: _propTypes2.default.func,
  /**
   * Adds a class name to the containing list element.
   */
  className: _propTypes2.default.string,
  /**
   * Adds an id to the containing list element.
   */
  id: _propTypes2.default.string,
  /**
   * A compoennt to render the container around the list
   */
  Container: _propTypes2.default.func,
  /**
   * A container that renders a clickable 'show more' area
   */
  ShowMore: _propTypes2.default.func
};
SidebarList.defaultProps = {
  hasNextPage: false,
  hasPreviousPage: false,
  onNextPageClicked: function onNextPageClicked() {
    return null;
  },
  onPreviousPageClicked: function onPreviousPageClicked() {
    return null;
  },
  className: null,
  id: null,
  Container: _SidebarListContainer2.default,
  ShowMore: _SidebarListShowMore2.default
};


SidebarList.Item = _SidebarListItem2.default;
exports.default = SidebarList;