"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.mapStateToProps = exports.SidebarComponent = exports.Sidebar = void 0;
var _react = _interopRequireDefault(require("react"));
var _store = require("../redux/store");
var _recompose = require("recompose");
var _bundleCommon = require("@kineticdata/bundle-common");
var _router = require("@reach/router");
var _reactstrap = require("reactstrap");
var _react2 = require("@kineticdata/react");
var _utils = require("../utils");
var SidebarComponent = exports.SidebarComponent = function SidebarComponent(_ref) {
  var hasSettingsAccess = _ref.hasSettingsAccess,
    techBars = _ref.techBars,
    openDropdown = _ref.openDropdown,
    toggleDropdown = _ref.toggleDropdown,
    hasTechBarDisplayRole = _ref.hasTechBarDisplayRole;
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "sidebar sidebar--tech-bar"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "sidebar-group--content-wrapper"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "sidebar-group"
  }, /*#__PURE__*/_react["default"].createElement(_reactstrap.Nav, {
    vertical: true
  }, /*#__PURE__*/_react["default"].createElement(_reactstrap.NavItem, null, /*#__PURE__*/_react["default"].createElement(_router.Link, {
    to: "past",
    getProps: (0, _utils.isActiveClass)('nav-link'),
    className: "nav-link"
  }, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_react2.I18n, null, "Past Appointments"))))))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "sidebar-group sidebar-group--tech-bars"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "sidebar-group__label"
  }, /*#__PURE__*/_react["default"].createElement(_react2.I18n, null, "Tech Bars"), /*#__PURE__*/_react["default"].createElement(_router.Link, {
    to: "tech-bars",
    className: "view-all"
  }, /*#__PURE__*/_react["default"].createElement(_react2.I18n, null, "View All"))), /*#__PURE__*/_react["default"].createElement(_reactstrap.Nav, {
    vertical: true
  }, techBars.map(function (techBar) {
    return /*#__PURE__*/_react["default"].createElement(_reactstrap.NavItem, {
      key: techBar.id
    }, /*#__PURE__*/_react["default"].createElement(_router.Link, {
      to: "appointment/".concat(techBar.values['Id']),
      className: "nav-link"
    }, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_react2.I18n, null, techBar.values['Name'])))), hasTechBarDisplayRole(techBar.values['Name']) && /*#__PURE__*/_react["default"].createElement(_reactstrap.Dropdown, {
      toggle: toggleDropdown(techBar.id),
      isOpen: openDropdown === techBar.id
    }, /*#__PURE__*/_react["default"].createElement(_reactstrap.DropdownToggle, {
      color: "link",
      className: "btn-sm"
    }, /*#__PURE__*/_react["default"].createElement("span", {
      className: "fa fa-ellipsis-v fa-lg"
    })), /*#__PURE__*/_react["default"].createElement(_reactstrap.DropdownMenu, {
      right: true
    }, /*#__PURE__*/_react["default"].createElement(_router.Link, {
      to: "display/".concat(techBar.values['Id'], "/checkin"),
      onClick: toggleDropdown(techBar.id),
      className: "dropdown-item",
      target: "_blank"
    }, /*#__PURE__*/_react["default"].createElement("span", {
      className: "fa fa-fw fa-external-link mr-2"
    }), /*#__PURE__*/_react["default"].createElement("span", null, /*#__PURE__*/_react["default"].createElement(_react2.I18n, null, "Check In"))), /*#__PURE__*/_react["default"].createElement(_router.Link, {
      to: "display/".concat(techBar.values['Id'], "/feedback"),
      onClick: toggleDropdown(techBar.id),
      className: "dropdown-item",
      target: "_blank"
    }, /*#__PURE__*/_react["default"].createElement("span", {
      className: "fa fa-external-link fa-fw mr-2"
    }), /*#__PURE__*/_react["default"].createElement("span", null, /*#__PURE__*/_react["default"].createElement(_react2.I18n, null, "Feedback"))), /*#__PURE__*/_react["default"].createElement(_router.Link, {
      to: "display/".concat(techBar.values['Id'], "/checkin?crosslink"),
      onClick: toggleDropdown(techBar.id),
      className: "dropdown-item",
      target: "_blank"
    }, /*#__PURE__*/_react["default"].createElement("span", {
      className: "fa fa-external-link fa-fw mr-2"
    }), /*#__PURE__*/_react["default"].createElement("span", null, /*#__PURE__*/_react["default"].createElement(_react2.I18n, null, "Check In"), " / ", /*#__PURE__*/_react["default"].createElement(_react2.I18n, null, "Feedback"))), /*#__PURE__*/_react["default"].createElement(_router.Link, {
      to: "display/".concat(techBar.values['Id'], "/overhead"),
      onClick: toggleDropdown(techBar.id),
      className: "dropdown-item",
      target: "_blank"
    }, /*#__PURE__*/_react["default"].createElement("span", {
      className: "fa fa-external-link fa-fw mr-2"
    }), /*#__PURE__*/_react["default"].createElement("span", null, /*#__PURE__*/_react["default"].createElement(_react2.I18n, null, "Overhead"))))));
  })))), hasSettingsAccess && /*#__PURE__*/_react["default"].createElement("div", {
    className: "sidebar-group sidebar-group--settings"
  }, /*#__PURE__*/_react["default"].createElement("ul", {
    className: "nav flex-column settings-group"
  }, /*#__PURE__*/_react["default"].createElement("li", null, /*#__PURE__*/_react["default"].createElement(_router.Link, {
    to: "settings/general",
    className: "nav-link"
  }, /*#__PURE__*/_react["default"].createElement(_react2.I18n, null, "Settings"), /*#__PURE__*/_react["default"].createElement("span", {
    className: "fa fa-fw fa-angle-right"
  }))))));
};
var mapStateToProps = exports.mapStateToProps = function mapStateToProps(state) {
  return {
    techBars: state.techBarApp.schedulers.filter(function (s) {
      return s.values['Status'] === 'Active';
    }),
    hasSettingsAccess: (0, _bundleCommon.selectHasRoleSchedulerManager)(state.app.profile) || (0, _bundleCommon.selectHasRoleSchedulerAdmin)(state.app.profile) || (0, _bundleCommon.selectHasRoleSchedulerAgent)(state.app.profile),
    profile: state.app.profile
  };
};
var toggleDropdown = function toggleDropdown(_ref2) {
  var setOpenDropdown = _ref2.setOpenDropdown,
    openDropdown = _ref2.openDropdown;
  return function (dropdownSlug) {
    return function () {
      return setOpenDropdown(dropdownSlug === openDropdown ? false : dropdownSlug);
    };
  };
};
var hasTechBarDisplayRole = function hasTechBarDisplayRole(_ref3) {
  var profile = _ref3.profile;
  return function (techBarName) {
    return _bundleCommon.Utils.isMemberOf(profile, "Role::Tech Bar Display::".concat(techBarName));
  };
};
var Sidebar = exports.Sidebar = (0, _recompose.compose)((0, _store.connect)(mapStateToProps), (0, _recompose.withState)('openDropdown', 'setOpenDropdown', false), (0, _recompose.withHandlers)({
  toggleDropdown: toggleDropdown,
  hasTechBarDisplayRole: hasTechBarDisplayRole
}))(SidebarComponent);