import React from 'react';
import { connect } from '../../redux/store';
import { compose, lifecycle } from 'recompose';
import { Router } from '@reach/router';
import { selectHasRoleSchedulerAdmin, selectHasRoleSchedulerManager, ErrorUnauthorized, CreateScheduler, Scheduler, SchedulersList } from '@kineticdata/bundle-common';
import { actions } from '../../redux/modules/techBarApp';
export var SchedulerSettingsComponent = function SchedulerSettingsComponent(_ref) {
  var kapp = _ref.kapp,
      isSchedulerAdmin = _ref.isSchedulerAdmin,
      isSchedulerManager = _ref.isSchedulerManager,
      profile = _ref.profile;
  return isSchedulerAdmin || isSchedulerManager ? /*#__PURE__*/React.createElement(Router, null, /*#__PURE__*/React.createElement(CreateScheduler, {
    path: "new",
    profile: profile,
    type: "TechBar",
    pathPrefix: "/kapps/".concat(kapp.slug, "/settings/schedulers"),
    breadcrumbs: [{
      label: 'tech bar',
      path: "/kapps/".concat(kapp.slug)
    }, {
      label: 'settings',
      path: "/kapps/".concat(kapp.slug, "/settings")
    }, {
      label: 'schedulers',
      path: "/kapps/".concat(kapp.slug, "/settings/schedulers")
    }]
  }), /*#__PURE__*/React.createElement(Scheduler, {
    path: ":id",
    profile: profile,
    pathPrefix: "/kapps/".concat(kapp.slug, "/settings/schedulers"),
    breadcrumbs: [{
      label: 'tech bar',
      path: "/kapps/".concat(kapp.slug)
    }, {
      label: 'settings',
      path: "/kapps/".concat(kapp.slug, "/settings")
    }, {
      label: 'schedulers',
      path: "/kapps/".concat(kapp.slug, "/settings/schedulers")
    }]
  }), /*#__PURE__*/React.createElement(SchedulersList, {
    "default": true,
    profile: profile,
    pathPrefix: "/kapps/".concat(kapp.slug, "/settings/schedulers"),
    breadcrumbs: [{
      label: 'tech bar',
      path: "/kapps/".concat(kapp.slug)
    }, {
      label: 'settings',
      path: "/kapps/".concat(kapp.slug, "/settings")
    }]
  })) : /*#__PURE__*/React.createElement(ErrorUnauthorized, null);
};
export var mapStateToProps = function mapStateToProps(state, props) {
  return {
    kapp: state.app.kapp,
    isSchedulerAdmin: selectHasRoleSchedulerAdmin(state.app.profile),
    isSchedulerManager: selectHasRoleSchedulerManager(state.app.profile),
    profile: state.app.profile
  };
};
export var mapDispatchToProps = {
  fetchAppDataRequest: actions.fetchAppDataRequest
};
export var SchedulerSettings = compose(connect(mapStateToProps, mapDispatchToProps), lifecycle({
  componentWillUnmount: function componentWillUnmount() {
    this.props.fetchAppDataRequest(true);
  }
}))(SchedulerSettingsComponent);