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

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

import './style.scss';

import React from 'react';
import PropTypes from 'prop-types';

import Tab from './Tab';

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 React.createElement(
      'div',
      { className: 'Tabs ' + (className.root || '') },
      React.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 React.createElement(Tab, { 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;
}(React.Component);

Tabs.propTypes = process.env.NODE_ENV !== "production" ? {
  children: PropTypes.instanceOf(Array).isRequired,
  className: PropTypes.shape({
    root: PropTypes.string,
    tabs: PropTypes.string
  })
} : {};


export default Tabs;