"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.CN_TABS_CONTENT = exports.CN_TABS_TITLE = exports.CN_TABS_TITLES = void 0;

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

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

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _classnames = _interopRequireDefault(require("classnames"));

var _styles = require("@vincent_za/styles");

var _component = _interopRequireDefault(require("../Scroll/component"));

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 _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 _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

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 _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _templateObject4() {
  var data = _taggedTemplateLiteral([""]);

  _templateObject4 = function _templateObject4() {
    return data;
  };

  return data;
}

function _templateObject3() {
  var data = _taggedTemplateLiteral(["\n  margin-right: ", ";\n  padding-bottom: ", ";\n  box-shadow: ", ";\n  color: ", ";\n  cursor: pointer;\n\n  &:hover {\n    color: ", ";\n  };\n"]);

  _templateObject3 = function _templateObject3() {
    return data;
  };

  return data;
}

function _templateObject2() {
  var data = _taggedTemplateLiteral(["\n  display: flex;\n  margin: 0 ", ";\n  text-transform: uppercase;\n"]);

  _templateObject2 = function _templateObject2() {
    return data;
  };

  return data;
}

function _templateObject() {
  var data = _taggedTemplateLiteral([""]);

  _templateObject = function _templateObject() {
    return data;
  };

  return data;
}

function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }

var CN_TABS_TITLES = 'tabs-titles';
exports.CN_TABS_TITLES = CN_TABS_TITLES;
var CN_TABS_TITLE = 'tabs-title';
exports.CN_TABS_TITLE = CN_TABS_TITLE;
var CN_TABS_CONTENT = 'tabs-content';
exports.CN_TABS_CONTENT = CN_TABS_CONTENT;

var Wrap = _styledComponents.default.div(_templateObject());

var Titles = _styledComponents.default.ul(_templateObject2(), _styles.REM_UNIT_LG);

var Title = _styledComponents.default.li(_templateObject3(), _styles.REM_UNIT_LG, _styles.REM_UNIT_LG, function (props) {
  return props.isActive && "inset 0 -2px ".concat(_styles.COLOR_PRIMARY);
}, function (props) {
  return props.isActive ? _styles.GRAY_X11 : _styles.SONIC_SILVER;
}, _styles.GRAY_X11);

var Detail = _styledComponents.default.div(_templateObject4());

var DetailScroll = (0, _component.default)(Detail);

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

  function Tabs(props) {
    var _this;

    _classCallCheck(this, Tabs);

    _this = _possibleConstructorReturn(this, _getPrototypeOf(Tabs).call(this, props));

    _defineProperty(_assertThisInitialized(_this), "onTabSelect", function (selectedTab) {
      _this.setState({
        activeTab: selectedTab
      });

      _this.props.callback({
        selectedTab: selectedTab
      });
    });

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

  _createClass(Tabs, [{
    key: "shouldComponentUpdate",
    value: function shouldComponentUpdate(nextProps, nextState) {
      if (nextState.activeTab !== this.state.activeTab) return true;
      if (nextProps.children !== this.props.children) return true;
      return false;
    }
  }, {
    key: "render",
    value: function render() {
      var _this2 = this;

      var activeTab = this.state.activeTab;
      var _this$props = this.props,
          isTouchDevice = _this$props.isTouchDevice,
          titles = _this$props.titles,
          children = _this$props.children,
          className = _this$props.className;
      return _react.default.createElement(Wrap, {
        className: className
      }, _react.default.createElement(Titles, {
        className: CN_TABS_TITLES
      }, titles.map(function (title) {
        return _react.default.createElement(Title, {
          isActive: activeTab === title,
          onClick: function onClick() {
            return _this2.onTabSelect(title);
          },
          className: (0, _classnames.default)(CN_TABS_TITLE, {
            'is-active': activeTab === title
          }),
          key: title
        }, title);
      })), _react.default.createElement(DetailScroll, {
        isTouchDevice: isTouchDevice,
        isNoOverflow: true,
        isOverflowY: true,
        className: CN_TABS_CONTENT
      }, children[activeTab]));
    }
  }]);

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

Tabs.propTypes = {
  isTouchDevice: _propTypes.bool.isRequired,
  titles: (0, _propTypes.arrayOf)(_propTypes.string).isRequired,
  children: (0, _propTypes.shape)(_propTypes.node.isRequired).isRequired,
  className: _propTypes.string,
  callback: _propTypes.func
};
Tabs.defaultProps = {
  className: undefined,
  callback: function callback() {}
};
var _default = Tabs;
exports.default = _default;