'use strict';

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

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _lodash = require('lodash');

var _lodash2 = _interopRequireDefault(_lodash);

var _index = require('../../constants/index');

var _reactRouter = require('react-router');

var _getListId = require('../../utils/get-list-id');

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

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

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

if (process.env.BROWSER) {}
var styles = {
  "outer": "SubNavBar__outer___2eGbe",
  "mobile-link-item": "SubNavBar__mobile-link-item___3OE6x",
  "subnav": "SubNavBar__subnav___3SYZR",
  "item": "SubNavBar__item___2bKCQ",
  "donateBtn": "SubNavBar__donateBtn___15a_h",
  "items": "SubNavBar__items___nWAa-",
  "active": "SubNavBar__active___1t6Ri",
  "links": "SubNavBar__links___iPale",
  "inlineBtn": "SubNavBar__inlineBtn___UA4RI",
  "triangle": "SubNavBar__triangle___GVXRc",
  "white": "SubNavBar__white___g53J9",
  "dark": "SubNavBar__dark___2zZYo"
};

var Items = function (_Component) {
  _inherits(Items, _Component);

  function Items() {
    _classCallCheck(this, Items);

    return _possibleConstructorReturn(this, (Items.__proto__ || Object.getPrototypeOf(Items)).apply(this, arguments));
  }

  _createClass(Items, [{
    key: 'render',
    value: function render() {
      var _props = this.props;
      var children = _props.children;
      var path = _props.path;

      var _children = [];
      children.map(function (child, i) {
        var itemClassName = void 0;
        if (child.props.href === path) {
          itemClassName = styles.active;
        }
        _children.push(_react2.default.createElement(
          'li',
          { className: (0, _classnames2.default)(styles.item, itemClassName), key: i },
          child
        ));
      });
      return _react2.default.createElement(
        'ul',
        { className: styles.items },
        _children
      );
    }
  }]);

  return Items;
}(_react.Component);

var SubNavBar = function (_Component2) {
  _inherits(SubNavBar, _Component2);

  function SubNavBar(props) {
    _classCallCheck(this, SubNavBar);

    var _this2 = _possibleConstructorReturn(this, (SubNavBar.__proto__ || Object.getPrototypeOf(SubNavBar)).call(this, props));

    _this2.state = {
      open: false
    };
    return _this2;
  }

  _createClass(SubNavBar, [{
    key: 'render',
    value: function render() {
      var _this3 = this;

      var _props2 = this.props;
      var bgStyle = _props2.bgStyle;
      var path = _props2.path;

      var subMenuClass = void 0;
      var subMenuLinks = [];

      if (bgStyle === 'dark') {
        subMenuClass = styles.dark;
      } else {
        subMenuClass = styles.white;
      }

      for (var i in _index.subnavPath) {
        var topicName = _lodash2.default.get(_index.subnavPath, [i, 'title']);
        var topicId = (0, _getListId.getTopicId)(topicName);
        subMenuLinks.push(_react2.default.createElement(
          _reactRouter.Link,
          { key: i, to: '' + _index.LINK_PREFIX.TOPIC + topicId },
          _react2.default.createElement(
            'h1',
            { onClick: function onClick() {
                if (_this3.props.onClick) {
                  _this3.props.onClick();
                }
              } },
            _index.subnavPath[i].title
          )
        ));
      }

      return _react2.default.createElement(
        'div',
        { className: (0, _classnames2.default)(styles.subnav, subMenuClass) },
        _react2.default.createElement(
          'div',
          { className: styles.outer },
          _react2.default.createElement(
            Items,
            { path: path, bgStyle: bgStyle },
            subMenuLinks
          ),
          _react2.default.createElement(
            'div',
            { className: styles.links },
            _react2.default.createElement('div', { className: styles.inlineBtn })
          )
        )
      );
    }
  }]);

  return SubNavBar;
}(_react.Component);

exports.default = SubNavBar;