"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.mapStateToProps = exports.mapDispatchToProps = exports.SchedulerSettingsComponent = exports.SchedulerSettings = void 0;
var _react = _interopRequireDefault(require("react"));
var _store = require("../../redux/store");
var _recompose = require("recompose");
var _router = require("@reach/router");
var _bundleCommon = require("@kineticdata/bundle-common");
var _techBarApp = require("../../redux/modules/techBarApp");
var SchedulerSettingsComponent = exports.SchedulerSettingsComponent = function SchedulerSettingsComponent(_ref) {
  var kapp = _ref.kapp,
    isSchedulerAdmin = _ref.isSchedulerAdmin,
    isSchedulerManager = _ref.isSchedulerManager,
    profile = _ref.profile;
  return isSchedulerAdmin || isSchedulerManager ? /*#__PURE__*/_react["default"].createElement(_router.Router, null, /*#__PURE__*/_react["default"].createElement(_bundleCommon.CreateScheduler, {
    path: "new",
    profile: profile,
    type: "TechBar",
    pathPrefix: "/kapps/".concat(kapp.slug, "/settings/schedulers"),
    breadcrumbs: [{
      label: 'Home',
      path: "/"
    }, {
      label: "".concat(kapp.name, " Settings"),
      to: "/kapps/".concat(kapp.slug, "/settings")
    }, {
      label: 'Schedulers',
      to: "/kapps/".concat(kapp.slug, "/settings/schedulers")
    }]
  }), /*#__PURE__*/_react["default"].createElement(_bundleCommon.Scheduler, {
    path: ":id",
    profile: profile,
    pathPrefix: "/kapps/".concat(kapp.slug, "/settings/schedulers"),
    breadcrumbs: [{
      label: 'Home',
      path: "/"
    }, {
      label: "".concat(kapp.name, " Settings"),
      to: "/kapps/".concat(kapp.slug, "/settings")
    }, {
      label: 'Schedulers',
      to: "/kapps/".concat(kapp.slug, "/settings/schedulers")
    }]
  }), /*#__PURE__*/_react["default"].createElement(_bundleCommon.SchedulersList, {
    "default": true,
    profile: profile,
    pathPrefix: "/kapps/".concat(kapp.slug, "/settings/schedulers"),
    breadcrumbs: [{
      label: 'Home',
      path: "/"
    }, {
      label: "".concat(kapp.name, " Settings"),
      to: "/kapps/".concat(kapp.slug, "/settings")
    }]
  })) : /*#__PURE__*/_react["default"].createElement(_bundleCommon.ErrorUnauthorized, null);
};
var mapStateToProps = exports.mapStateToProps = function mapStateToProps(state, props) {
  return {
    kapp: state.app.kapp,
    isSchedulerAdmin: (0, _bundleCommon.selectHasRoleSchedulerAdmin)(state.app.profile),
    isSchedulerManager: (0, _bundleCommon.selectHasRoleSchedulerManager)(state.app.profile),
    profile: state.app.profile
  };
};
var mapDispatchToProps = exports.mapDispatchToProps = {
  fetchAppDataRequest: _techBarApp.actions.fetchAppDataRequest
};
var SchedulerSettings = exports.SchedulerSettings = (0, _recompose.compose)((0, _store.connect)(mapStateToProps, mapDispatchToProps), (0, _recompose.lifecycle)({
  componentWillUnmount: function componentWillUnmount() {
    this.props.fetchAppDataRequest(true);
  }
}))(SchedulerSettingsComponent);