'use strict';

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

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _getClassName2 = require('babel-plugin-react-css-modules/dist/browser/getClassName');

var _getClassName3 = _interopRequireDefault(_getClassName2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _reactSticky = require('react-sticky');

var _Content = require('./Content');

var _Content2 = _interopRequireDefault(_Content);

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

var _Tab2 = _interopRequireDefault(_Tab);

var _TabsContainer = require('./TabsContainer');

var _TabsContainer2 = _interopRequireDefault(_TabsContainer);

var _Section = require('../Section');

var _Section2 = _interopRequireDefault(_Section);

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

var _styleModuleImportMap = {
  './tabs.scss': {
    'row': 'flive_tabs_row',
    'column': 'flive_tabs_column'
  }
};

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

var Row = _Section2.default.Row;

var componentName = 'Tabber';

var propTypes = {
  /** @ignore */
  className: _propTypes2.default.string,
  /** @ignore */
  children: _propTypes2.default.node,
  sticky: _propTypes2.default.object,
  scrollSpy: _propTypes2.default.object,
  tabDirection: _propTypes2.default.oneOf(['column', 'row'])
};

var defaultProps = {
  className: undefined,
  children: null,
  sticky: null,
  scrollSpy: null,
  tabDirection: 'column'
};

var Tabs = function Tabs(_ref) {
  var className = _ref.className,
      sticky = _ref.sticky,
      scrollSpy = _ref.scrollSpy,
      children = _ref.children,
      tabDirection = _ref.tabDirection,
      props = _objectWithoutProperties(_ref, ['className', 'sticky', 'scrollSpy', 'children', 'tabDirection']);

  var TabsComponent = void 0;
  var styleName = tabDirection;
  switch (tabDirection) {
    case 'column':
      TabsComponent = Row;
      break;
    case 'row':
    default:
      TabsComponent = 'div';
  }
  var content = _react2.default.createElement(
    TabsComponent,
    _extends({}, props, {
      className: (className ? className + ' ' : '') + (0, _getClassName3.default)(styleName, _styleModuleImportMap)
    }),
    _react2.default.Children.map(children, function (child) {
      if (_react2.default.isValidElement(child)) {
        var type = child.type;

        switch (true) {
          case type.componentName === 'TabsContainer':
            return _react2.default.cloneElement(child, { scrollSpy: scrollSpy, sticky: sticky, tabDirection: tabDirection });
          case type.componentName === 'TabsContent':
            return _react2.default.cloneElement(child, { tabDirection: tabDirection });
          default:
            return child;
        }
      }
      return child;
    })
  );
  if (sticky) {
    return _react2.default.createElement(
      _reactSticky.StickyContainer,
      null,
      content
    );
  }
  return content;
};

Tabs.componentName = componentName;
Tabs.propTypes = propTypes;
Tabs.defaultProps = defaultProps;

Tabs.Tab = _Tab2.default;
Tabs.TabsContainer = _TabsContainer2.default;
Tabs.Content = _Content2.default;

exports.default = Tabs;
module.exports = exports['default'];