"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 _core = require("@redux-devtools/core");
var _ui = require("@redux-devtools/ui");
var _RecordButton = _interopRequireDefault(require("./buttons/RecordButton"));
var _PersistButton = _interopRequireDefault(require("./buttons/PersistButton"));
var _LockButton = _interopRequireDefault(require("./buttons/LockButton"));
var _InstanceSelector = _interopRequireDefault(require("./InstanceSelector"));
var _SyncButton = _interopRequireDefault(require("./buttons/SyncButton"));
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; }
// eslint-disable-next-line @typescript-eslint/unbound-method
const {
  reset,
  rollback,
  commit,
  sweep
} = _core.ActionCreators;
class TopButtons extends _react.Component {
  shouldComponentUpdate(nextProps) {
    return nextProps.options !== this.props.options || nextProps.liftedState !== this.props.liftedState;
  }
  handleRollback = () => {
    this.props.dispatch(rollback());
  };
  handleSweep = () => {
    this.props.dispatch(sweep());
  };
  handleCommit = () => {
    this.props.dispatch(commit());
  };
  handleReset = () => {
    this.props.dispatch(reset());
  };
  render() {
    const options = this.props.options;
    const features = options.features;
    const {
      computedStates,
      skippedActionIds,
      isPaused,
      isLocked
    } = this.props.liftedState;
    const noStates = computedStates.length < 2;
    return /*#__PURE__*/_react.default.createElement(_ui.Toolbar, {
      borderPosition: "bottom"
    }, features.pause && /*#__PURE__*/_react.default.createElement(_RecordButton.default, {
      paused: isPaused
    }), features.persist && /*#__PURE__*/_react.default.createElement(_PersistButton.default, null), features.lock && /*#__PURE__*/_react.default.createElement(_LockButton.default, {
      locked: isLocked,
      disabled: options.lib !== 'redux'
    }), /*#__PURE__*/_react.default.createElement(_ui.Divider, null), /*#__PURE__*/_react.default.createElement(_ui.Button, {
      title: "Reset to the state you created the store with",
      tooltipPosition: "bottom",
      onClick: this.handleReset
    }, "Reset"), /*#__PURE__*/_react.default.createElement(_ui.Button, {
      title: "Roll back to the last committed state",
      tooltipPosition: "bottom",
      onClick: this.handleRollback,
      disabled: noStates
    }, "Revert"), /*#__PURE__*/_react.default.createElement(_ui.Button, {
      title: "Remove all currently disabled actions from the log",
      tooltipPosition: "bottom",
      onClick: this.handleSweep,
      disabled: skippedActionIds.length === 0
    }, "Sweep"), /*#__PURE__*/_react.default.createElement(_ui.Button, {
      title: "Remove all actions from the log,\\a and make the current state your initial state",
      tooltipPosition: "bottom",
      onClick: this.handleCommit,
      disabled: noStates
    }, "Commit"), /*#__PURE__*/_react.default.createElement(_ui.Divider, null), /*#__PURE__*/_react.default.createElement(_InstanceSelector.default, null), features.sync && /*#__PURE__*/_react.default.createElement(_SyncButton.default, null));
  }
}
exports.default = TopButtons;