'use strict';

exports.__esModule = true;

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

require('./style.scss');

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _Tab = require('./Tab');

var _Tab2 = _interopRequireDefault(_Tab);

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

var Tabs = function (_React$Component) {
  _inherits(Tabs, _React$Component);

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

    var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));

    _this.activate = function (tab) {
      _this.setState({ activeTab: tab });
    };

    _this.state = {
      activeTab: _this.props.children[0].props.label
    };
    return _this;
  }

  Tabs.prototype.render = function render() {
    var activate = this.activate,
        _props = this.props,
        children = _props.children,
        _props$className = _props.className,
        className = _props$className === undefined ? { root: '', tabs: '' } : _props$className,
        activeTab = this.state.activeTab;


    return _react2.default.createElement(
      'div',
      { className: 'Tabs ' + (className.root || '') },
      _react2.default.createElement(
        'ol',
        { className: 'Tabs-list ' + (className.tabs || '') },
        children.map(function (child) {
          var label = child.props.label;

          var key = label;
          /* use children as key for labels with markup */
          if ((typeof label === 'undefined' ? 'undefined' : _typeof(label)) === 'object' && label !== null) key = label.props.children;
          return _react2.default.createElement(_Tab2.default, { key: key, activeTab: activeTab, className: 'Tabs-listItem', label: label, onClick: activate });
        })
      ),
      children.map(function (child) {
        return child.props.label === activeTab && child.props.children;
      })
    );
  };

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

Tabs.propTypes = process.env.NODE_ENV !== "production" ? {
  children: _propTypes2.default.instanceOf(Array).isRequired,
  className: _propTypes2.default.shape({
    root: _propTypes2.default.string,
    tabs: _propTypes2.default.string
  })
} : {};
exports.default = Tabs;
module.exports = exports['default'];