"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactRedux = require("react-redux");
var _ui = require("@redux-devtools/ui");
var _inspectorMonitor = require("@redux-devtools/inspector-monitor");
var _actions = require("../../../actions");
var _RawTab = _interopRequireDefault(require("./RawTab"));
var _ChartTab = _interopRequireDefault(require("./ChartTab"));
var _VisualDiffTab = _interopRequireDefault(require("./VisualDiffTab"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
class SubTabs extends _react.Component {
  constructor(props) {
    super(props);
    this.updateTabs(props);
  }
  UNSAFE_componentWillReceiveProps(nextProps) {
    if (nextProps.parentTab !== this.props.parentTab) {
      this.updateTabs(nextProps);
    }
  }
  selector = () => {
    switch (this.props.parentTab) {
      case 'Action':
        return {
          data: this.props.action
        };
      case 'Diff':
        return {
          data: this.props.delta
        };
      default:
        return {
          data: this.props.nextState
        };
    }
  };
  updateTabs(props) {
    const parentTab = props.parentTab;
    if (parentTab === 'Diff') {
      this.tabs = [{
        name: 'Tree',
        component: _inspectorMonitor.DiffTab,
        selector: () => this.props
      }, {
        name: 'Raw',
        component: _VisualDiffTab.default,
        selector: this.selector
      }];
      return;
    }
    this.tabs = [{
      name: 'Tree',
      component: parentTab === 'Action' ? _inspectorMonitor.ActionTab : _inspectorMonitor.StateTab,
      selector: () => this.props
    }, {
      name: 'Chart',
      component: _ChartTab.default,
      selector: this.selector
    }, {
      name: 'Raw',
      component: _RawTab.default,
      selector: this.selector
    }];
  }
  render() {
    let selected = this.props.selected;
    if (selected === 'Chart' && this.props.parentTab === 'Diff') selected = 'Tree';
    return /*#__PURE__*/_react.default.createElement(_ui.Tabs, {
      tabs: this.tabs,
      selected: selected || 'Tree',
      onClick: this.props.selectMonitorTab
    });
  }
}
const mapStateToProps = state => ({
  parentTab: state.monitor.monitorState.tabName,
  selected: state.monitor.monitorState.subTabName
});
const actionCreators = {
  selectMonitorTab: _actions.selectMonitorTab
};
var _default = exports.default = (0, _reactRedux.connect)(mapStateToProps, actionCreators)(SubTabs);