"use strict";

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

var _react = _interopRequireDefault(require("react"));

var R = _interopRequireWildcard(require("ramda"));

require("./TabLayout.css");

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

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

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

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function _extends() { _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; }; return _extends.apply(this, arguments); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

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

var TabLayout =
/*#__PURE__*/
function (_React$Component) {
  _inherits(TabLayout, _React$Component);

  function TabLayout(props) {
    var _this;

    _classCallCheck(this, TabLayout);

    _this = _possibleConstructorReturn(this, _getPrototypeOf(TabLayout).call(this, props));
    _this.isSelected = _this.isSelected.bind(_assertThisInitialized(_assertThisInitialized(_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 _this$props = this.props,
          floatingHeader = _this$props.floatingHeader,
          headerHeight = _this$props.headerHeight,
          headerWidth = _this$props.headerWidth;
      var children = toArray(this.props.children);
      var tabs = R.filter(R.identity, children);
      var labelMap = tabs.map(function (tab, index) {
        return _react.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 _react.default.createElement("div", {
          key: index,
          hidden: !_this2.isSelected(index)
        }, tab.props.content);
      });
      return _react.default.createElement("div", null, _react.default.createElement(TabHeader, {
        floatingHeader: floatingHeader,
        headerWidth: headerWidth
      }, labelMap), _react.default.createElement(TabBody, {
        floatingHeader: floatingHeader,
        headerHeight: headerHeight
      }, contentMap));
    }
  }]);

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

exports.TabLayout = TabLayout;

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

exports.Tab = Tab;

var TabLabel =
/*#__PURE__*/
function (_React$Component2) {
  _inherits(TabLabel, _React$Component2);

  function TabLabel(props) {
    var _this3;

    _classCallCheck(this, TabLabel);

    _this3 = _possibleConstructorReturn(this, _getPrototypeOf(TabLabel).call(this, props));
    _this3.state = {
      hover: false
    };
    _this3.onMouseOver = _this3.onMouseOver.bind(_assertThisInitialized(_assertThisInitialized(_this3)));
    _this3.onMouseLeave = _this3.onMouseLeave.bind(_assertThisInitialized(_assertThisInitialized(_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 _this$props2 = this.props,
          children = _this$props2.children,
          disabled = _this$props2.disabled,
          tabIndex = _this$props2.tabIndex,
          onTabClick = _this$props2.onTabClick,
          onSelectClick = _this$props2.onSelectClick,
          isSelected = _this$props2.isSelected,
          themeColor = _this$props2.themeColor,
          restProps = _objectWithoutProperties(_this$props2, ["children", "disabled", "tabIndex", "onTabClick", "onSelectClick", "isSelected", "themeColor"]);

      var selected = isSelected(tabIndex);
      var labelStateClassName = disabled ? 'vs-tab-label-disabled' : selected ? 'vs-tab-label-clicked' : '';
      var labelClassName = "vs-tab-label ".concat(labelStateClassName);
      var accentColor = themeColor || '#49c5b1';
      var hoverStyle = disabled ? {} : selected ? {} : this.state.hover ? {
        color: accentColor,
        cursor: 'pointer'
      } : {
        color: '#888'
      };
      var labelStyle = selected ? {
        borderBottom: "4px solid ".concat(accentColor)
      } : {};
      return _react.default.createElement("div", _extends({}, restProps, {
        className: labelClassName,
        onClick: function onClick(event) {
          if (!disabled) {
            onSelectClick(event, tabIndex);
            if (onTabClick) onTabClick();
          }
        },
        onMouseOver: this.onMouseOver,
        onMouseLeave: this.onMouseLeave,
        style: hoverStyle
      }), _react.default.createElement("div", {
        style: labelStyle
      }, children));
    }
  }]);

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

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

exports.TabLabelContent = TabLabelContent;

var TabHeader = function TabHeader(_ref2) {
  var children = _ref2.children,
      floatingHeader = _ref2.floatingHeader,
      headerWidth = _ref2.headerWidth,
      restProps = _objectWithoutProperties(_ref2, ["children", "floatingHeader", "headerWidth"]);

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

var TabBody = function TabBody(_ref3) {
  var children = _ref3.children,
      floatingHeader = _ref3.floatingHeader,
      headerHeight = _ref3.headerHeight,
      restProps = _objectWithoutProperties(_ref3, ["children", "floatingHeader", "headerHeight"]);

  var headerHeightCss = floatingHeader ? {
    paddingTop: "".concat(headerHeight)
  } : {};
  return _react.default.createElement("div", _extends({}, restProps, {
    className: "vs-tab-body",
    style: headerHeightCss
  }), children);
};

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

exports.TabContent = TabContent;