"use strict";

exports.__esModule = true;
exports["default"] = void 0;

var _react = _interopRequireWildcard(require("react"));

var _md = require("react-icons/md");

var _reactRedux = require("react-redux");

var _main = require("../../store/rom/main");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

var Menu = function Menu(props) {
  var dispatch = (0, _reactRedux.useDispatch)();

  var _useSelector = (0, _reactRedux.useSelector)(function (state) {
    return state.rehab.main;
  }),
      exercises = _useSelector.exercises,
      isMenuOpened = _useSelector.isMenuOpened,
      exercisesCompleted = _useSelector.exercisesCompleted,
      isPhysioterapist = _useSelector.isPhysioterapist,
      isHiddenMenu = _useSelector.isHiddenMenu;

  var showSidebar = function showSidebar() {
    dispatch((0, _main.toggleMenu)());
  };

  var onClickMenu = (0, _react.useCallback)(function (e, exercise) {
    e.stopPropagation();
    showSidebar();
    dispatch((0, _main.goToExercise)(exercise));
  });
  return !isPhysioterapist && !isHiddenMenu && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("button", {
    className: "btn-icon btn-menu",
    onClick: showSidebar
  }, /*#__PURE__*/_react["default"].createElement(_md.MdMenu, {
    className: "md-icon",
    color: "#FFF",
    size: "26px"
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: isMenuOpened ? 'overlay-menu active' : 'overlay-menu',
    onClick: showSidebar
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: isMenuOpened ? 'main-menu active' : 'main-menu'
  }, /*#__PURE__*/_react["default"].createElement("ul", {
    className: "exercise-list"
  }, /*#__PURE__*/_react["default"].createElement("li", {
    className: "menu-subtitle"
  }, "EXERCISES"), exercises.length > 0 && exercises.map(function (exercise, index) {
    var _exercise$title;

    var isDone = exercisesCompleted.find(function (exer) {
      return exer.exercise === exercise._id;
    });
    return /*#__PURE__*/_react["default"].createElement("li", {
      onClick: function onClick(e) {
        return onClickMenu(e, exercise);
      },
      key: (exercise === null || exercise === void 0 ? void 0 : exercise.title) + "_" + index,
      className: isDone ? 'done' : ''
    }, exercise === null || exercise === void 0 ? void 0 : (_exercise$title = exercise.title) === null || _exercise$title === void 0 ? void 0 : _exercise$title.toUpperCase(), isDone && /*#__PURE__*/_react["default"].createElement("div", {
      className: "actions-menu"
    }, /*#__PURE__*/_react["default"].createElement(_md.MdCheck, {
      className: "exercise-check md-icon",
      size: "24px"
    })));
  }))));
};

var _default = (0, _react.memo)(Menu);

exports["default"] = _default;
module.exports = exports.default;