'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.TabContent = exports.TabLabelContent = exports.Tab = exports.TabLayout = undefined;

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 _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 _ramda = require('ramda');

var _ramda2 = _interopRequireDefault(_ramda);

require('./TabLayout.css');

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; } /* eslint-disable no-unused-vars */


var toArray = function toArray(maybeArray) {
  return _ramda2.default.flatten([maybeArray]);
};

var TabLayout = exports.TabLayout = function (_React$Component) {
  _inherits(TabLayout, _React$Component);

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

    var _this = _possibleConstructorReturn(this, (TabLayout.__proto__ || Object.getPrototypeOf(TabLayout)).call(this, props));

    _this.isSelected = _this.isSelected.bind(_this);
    return _this;
  }

  _createClass(TabLayout, [{
    key: 'isSelected',
    value: function isSelected(index) {
      return index === this.props.selectedIndex;
    }
  }, {
    key: 'render',
    value: function render() {
      var _this2 = this;

      var _props = this.props,
          floatingHeader = _props.floatingHeader,
          headerHeight = _props.headerHeight,
          headerWidth = _props.headerWidth;

      var children = toArray(this.props.children);
      var tabs = _ramda2.default.filter(_ramda2.default.identity, children);
      var labelMap = tabs.map(function (tab, index) {
        return _react2.default.createElement(
          TabLabel,
          _extends({}, tab.props, {
            key: index,
            tabIndex: index,
            themeColor: _this2.props.themeColor,
            onTabClick: _this2.props.onTabClick,
            onSelectClick: _this2.props.selectTab,
            isSelected: _this2.isSelected }),
          tab.props.label
        );
      });
      var contentMap = tabs.map(function (tab, index) {
        return _react2.default.createElement(
          'div',
          { key: index, hidden: !_this2.isSelected(index) },
          tab.props.content
        );
      });
      return _react2.default.createElement(
        'div',
        null,
        _react2.default.createElement(
          TabHeader,
          { floatingHeader: floatingHeader, headerWidth: headerWidth },
          labelMap
        ),
        _react2.default.createElement(
          TabBody,
          { floatingHeader: floatingHeader, headerHeight: headerHeight },
          contentMap
        )
      );
    }
  }]);

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

var Tab = exports.Tab = function Tab(_ref) {
  var label = _ref.label,
      content = _ref.content,
      disabled = _ref.disabled;
};

var TabLabel = function (_React$Component2) {
  _inherits(TabLabel, _React$Component2);

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

    var _this3 = _possibleConstructorReturn(this, (TabLabel.__proto__ || Object.getPrototypeOf(TabLabel)).call(this, props));

    _this3.state = {
      hover: false
    };
    _this3.onMouseOver = _this3.onMouseOver.bind(_this3);
    _this3.onMouseLeave = _this3.onMouseLeave.bind(_this3);
    return _this3;
  }

  _createClass(TabLabel, [{
    key: 'onMouseOver',
    value: function onMouseOver() {
      this.setState({ hover: true });
    }
  }, {
    key: 'onMouseLeave',
    value: function onMouseLeave() {
      this.setState({ hover: false });
    }
  }, {
    key: 'render',
    value: function render() {
      var _props2 = this.props,
          children = _props2.children,
          disabled = _props2.disabled,
          tabIndex = _props2.tabIndex,
          onTabClick = _props2.onTabClick,
          onSelectClick = _props2.onSelectClick,
          isSelected = _props2.isSelected,
          themeColor = _props2.themeColor;

      var selected = isSelected(tabIndex);

      var labelStateClassName = disabled ? 'vs-tab-label-disabled' : selected ? 'vs-tab-label-clicked' : '';
      var labelClassName = 'vs-tab-label ' + labelStateClassName;

      var accentColor = themeColor || '#00af65';

      var hoverStyle = disabled ? {} : selected ? {} : this.state.hover ? { color: accentColor, cursor: 'pointer' } : { color: '#888' };

      var labelStyle = selected ? { borderBottom: '4px solid ' + accentColor } : {};

      return _react2.default.createElement(
        'div',
        { className: labelClassName,
          onClick: function onClick(event) {
            if (!disabled) {
              onSelectClick(event, tabIndex);
              if (onTabClick) onTabClick();
            }
          },
          onMouseOver: this.onMouseOver,
          onMouseLeave: this.onMouseLeave,
          style: hoverStyle
        },
        _react2.default.createElement(
          'div',
          { style: labelStyle },
          children
        )
      );
    }
  }]);

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

var TabLabelContent = exports.TabLabelContent = function TabLabelContent(props) {
  return _react2.default.createElement(
    'div',
    { className: 'vs-tab-label-content standard' },
    props.children
  );
};

var TabHeader = function TabHeader(_ref2) {
  var children = _ref2.children,
      floatingHeader = _ref2.floatingHeader,
      headerWidth = _ref2.headerWidth;

  var floatingClassName = floatingHeader ? 'vs-tab-header-floating' : '';
  var headerClassName = 'vs-tab-header ' + floatingClassName;
  var headerCss = floatingHeader ? { width: '' + headerWidth } : {};
  return _react2.default.createElement(
    'div',
    { className: headerClassName, style: headerCss },
    children
  );
};

var TabBody = function TabBody(_ref3) {
  var children = _ref3.children,
      floatingHeader = _ref3.floatingHeader,
      headerHeight = _ref3.headerHeight;

  var headerHeightCss = floatingHeader ? { paddingTop: '' + headerHeight } : {};
  return _react2.default.createElement(
    'div',
    { className: 'vs-tab-body', style: headerHeightCss },
    children
  );
};

var TabContent = exports.TabContent = function TabContent(props) {
  return _react2.default.createElement(
    'div',
    { className: 'vs-tab-content standard' },
    props.children
  );
};