"use strict";

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

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

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

var _lodash = _interopRequireDefault(require("lodash"));

var _FormGenerator = require("../FormGenerator");

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 _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 _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 TabContainer(props) {
  var value = props.value,
      control = props.control;

  var contentDetails = _lodash.default.find(control.options, {
    value: value
  });

  if (contentDetails && contentDetails.content) {
    var size = 12;
    var GRID = props.library.Grid;
    return _react.default.createElement(GRID, {
      item: true,
      xs: size,
      sm: size,
      md: size,
      xl: size,
      lg: size
    }, _react.default.createElement(_FormGenerator.FormGenerator, {
      data: contentDetails.content.data,
      library: props.library,
      guid: contentDetails.content.guid
    }));
  }

  return _react.default.createElement("div", null);
}

TabContainer.propTypes = process.env.NODE_ENV !== "production" ? {
  control: _propTypes.default.object,
  library: _propTypes.default.object,
  value: _propTypes.default.string
} : {};
TabContainer.defaultProps = {
  control: null,
  library: null,
  value: null
};

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));
    _this.state = {
      value: props.attributes.value
    };
    _this.handleChange = _this.handleChange.bind(_assertThisInitialized(_this));
    return _this;
  }

  _createClass(Tabs, [{
    key: "handleChange",
    value: function handleChange(event, value) {
      this.setState({
        value: value
      });
    }
  }, {
    key: "render",
    value: function render() {
      var props = this.props;
      var value = this.state.value;
      var TABS = props.library[props.component];
      var APPBAR = props.library.AppBar;
      var TAB = props.library.Tab;
      return _react.default.createElement("div", {
        style: props.attributes.style
      }, _react.default.createElement(APPBAR, props.attributes.appBar, _react.default.createElement(TABS, _extends({}, props.attributes.tabs, {
        value: value,
        onChange: this.handleChange
      }), props.control.options.map(function (option, index) {
        return _react.default.createElement(TAB, _extends({}, option, {
          key: index
        }));
      }))), _react.default.createElement(TabContainer, {
        library: props.library,
        control: props.control,
        value: value
      }));
    }
  }]);

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

Tabs.propTypes = process.env.NODE_ENV !== "production" ? {
  library: _propTypes.default.object,
  component: _propTypes.default.string.isRequired,
  attributes: _propTypes.default.object,
  control: _propTypes.default.object,
  rules: _propTypes.default.object
} : {};
Tabs.defaultProps = {
  library: null,
  attributes: null,
  control: null,
  rules: null
};
var _default = Tabs;
exports.default = _default;