'use strict';

exports.__esModule = true;

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

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

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

var Topbar = function (_React$Component) {
  (0, _inherits3.default)(Topbar, _React$Component);

  function Topbar() {
    var _temp, _this, _ret;

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

    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, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = {
      isMobileOpen: false,
      activeIndex: null,
      focus: 0
    }, _this.getChildContext = function () {
      return {
        activeIndex: _this.state.activeIndex,
        onActivate: function onActivate(index) {
          return _this.setSelected(index);
        },
        onFocus: function onFocus(index) {
          return _this.setState(function () {
            return { focus: index };
          });
        },
        focus: _this.state.focus
      };
    }, _this.setSelected = function (index) {
      if (index === _this.state.activeIndex) return;
      _this.setState(function () {
        return { activeIndex: index };
      });
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  Topbar.prototype.render = function render() {
    var _this2 = this;

    var cuiTopBarClass = 'cui-top-bar';
    var cuiBrandClass = 'cui-brand';
    var _props = this.props,
        anchor = _props.anchor,
        color = _props.color,
        fixed = _props.fixed,
        icon = _props.icon,
        image = _props.image,
        title = _props.title;

    var brandNode = _react2.default.createElement(
      'a',
      { className: cuiTopBarClass + '__brand ' + cuiBrandClass, href: anchor },
      _react2.default.createElement(
        'div',
        { className: cuiBrandClass + '__logo' },
        image ? image : _react2.default.createElement('i', { className: 'icon ' + icon })
      ),
      _react2.default.createElement(
        'div',
        { className: cuiBrandClass + '__title' },
        title
      )
    );

    var injectChildren = _react2.default.Children.map(this.props.children, function (child) {
      if (child.type.displayName === 'TopbarMobile') {
        return _react2.default.cloneElement(child, {
          brandNode: brandNode
        });
      } else {
        return child;
      }
    });

    return _react2.default.createElement(
      'div',
      {
        className: '' + cuiTopBarClass + ('' + (fixed && ' ' + cuiTopBarClass + '--fixed' || '')) + (' ' + cuiTopBarClass + '--' + color),
        role: 'navigation',
        ref: function ref(_ref) {
          _this2.parentContainer = _ref;
        } },
      _react2.default.createElement(
        'div',
        { className: cuiTopBarClass + '__container row' },
        brandNode,
        injectChildren
      )
    );
  };

  return Topbar;
}(_react2.default.Component);

Topbar.displayName = 'Topbar';
exports.default = Topbar;


Topbar.childContextTypes = {
  focus: _propTypes2.default.number,
  activeIndex: _propTypes2.default.number,
  onActivate: _propTypes2.default.func,
  onFocus: _propTypes2.default.func
};

Topbar.defaultProps = {
  className: '',
  title: '',
  icon: 'icon-cisco-logo',
  image: null,
  anchor: null,
  color: 'dark',
  fixed: false,
  children: null
};
module.exports = exports['default'];