"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.mapStateToProps = exports.mapDispatchToProps = exports.TechBarSettingsComponent = exports.TechBarSettings = void 0;
var _react = _interopRequireDefault(require("react"));
var _store = require("../../redux/store");
var _recompose = require("recompose");
var _bundleCommon = require("@kineticdata/bundle-common");
var _PageTitle = require("../shared/PageTitle");
var _router = require("@reach/router");
var _techBarApp = require("../../redux/modules/techBarApp");
var _react2 = require("@kineticdata/react");
var getStatusColor = function getStatusColor(status) {
  return status === 'Inactive' ? 'status--red' : 'status--green';
};
var TechBarSettingsComponent = exports.TechBarSettingsComponent = function TechBarSettingsComponent(_ref) {
  var kapp = _ref.kapp,
    techBars = _ref.techBars;
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "page-container"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "page-panel"
  }, /*#__PURE__*/_react["default"].createElement(_PageTitle.PageTitle, {
    settings: true,
    breadcrumbs: [{
      label: 'Home',
      to: '/'
    }, {
      label: "".concat(kapp.name, " Settings"),
      to: '..'
    }],
    title: "Tech Bars"
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "list-wrapper"
  }, techBars.size > 0 && /*#__PURE__*/_react["default"].createElement("table", {
    className: "table table-sm table-striped table-schedulers table--settings"
  }, /*#__PURE__*/_react["default"].createElement("thead", {
    className: "header"
  }, /*#__PURE__*/_react["default"].createElement("tr", null, /*#__PURE__*/_react["default"].createElement("th", {
    scope: "col"
  }, /*#__PURE__*/_react["default"].createElement(_react2.I18n, null, "Name")), /*#__PURE__*/_react["default"].createElement("th", {
    scope: "col"
  }, /*#__PURE__*/_react["default"].createElement(_react2.I18n, null, "Status")), /*#__PURE__*/_react["default"].createElement("th", {
    scope: "col"
  }, /*#__PURE__*/_react["default"].createElement(_react2.I18n, null, "Location")))), /*#__PURE__*/_react["default"].createElement("tbody", null, techBars.map(function (scheduler) {
    return /*#__PURE__*/_react["default"].createElement("tr", {
      key: scheduler.id
    }, /*#__PURE__*/_react["default"].createElement("td", null, /*#__PURE__*/_react["default"].createElement(_router.Link, {
      to: "".concat(scheduler.id)
    }, /*#__PURE__*/_react["default"].createElement(_react2.I18n, null, scheduler.values['Name']))), /*#__PURE__*/_react["default"].createElement("td", null, /*#__PURE__*/_react["default"].createElement("span", {
      className: "status ".concat(getStatusColor(scheduler.values['Status']))
    }, /*#__PURE__*/_react["default"].createElement(_react2.I18n, null, scheduler.values['Status']))), /*#__PURE__*/_react["default"].createElement("td", null, /*#__PURE__*/_react["default"].createElement(_react2.I18n, null, scheduler.values['Location'])));
  }))), techBars.size === 0 && /*#__PURE__*/_react["default"].createElement("div", {
    className: "empty-state"
  }, /*#__PURE__*/_react["default"].createElement("h5", null, /*#__PURE__*/_react["default"].createElement(_react2.I18n, null, "No Tech Bars Found"))))));
};
var mapStateToProps = exports.mapStateToProps = function mapStateToProps(state, props) {
  var techBars = (0, _bundleCommon.selectHasRoleSchedulerAdmin)(state.app.profile) ? state.techBarApp.schedulers : state.techBarApp.schedulers.filter(function (s) {
    return _bundleCommon.Utils.isMemberOf(state.app.profile, "Role::Scheduler::".concat(s.values['Name'])) || _bundleCommon.Utils.isMemberOf(state.app.profile, "Scheduler::".concat(s.values['Name']));
  });
  return {
    kapp: (0, _bundleCommon.selectCurrentKapp)(state),
    techBars: techBars
  };
};
var mapDispatchToProps = exports.mapDispatchToProps = {
  fetchAppDataRequest: _techBarApp.actions.fetchAppDataRequest
};
var TechBarSettings = exports.TechBarSettings = (0, _recompose.compose)((0, _store.connect)(mapStateToProps, mapDispatchToProps), (0, _recompose.lifecycle)({
  componentDidMount: function componentDidMount() {
    // this.props.fetchAppDataRequest();
  }
}))(TechBarSettingsComponent);