"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 _coach = require("../../store/coach");

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 {
      menu: state.coach.menu,
      exercises: state.coach.exercises,
      resultsExercises: state.coach.resultsExercises
    };
  }),
      exercises = _useSelector.exercises,
      menu = _useSelector.menu,
      resultsExercises = _useSelector.resultsExercises;

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

  var onToggleTutorial = (0, _react.useCallback)(function (e) {
    showSidebar(false);
    dispatch((0, _coach.toggleTutorial)(true));
  }, [dispatch, showSidebar]);
  var onClickMenu = (0, _react.useCallback)(function (e, exercise) {
    e.stopPropagation();
    showSidebar();
    dispatch((0, _coach.goToExercise)(exercise));
  });
  var onToggleGalley = (0, _react.useCallback)(function (e, exercise) {
    e.stopPropagation();
    showSidebar();
    dispatch((0, _coach.goToGallery)({
      isOpened: true,
      exercise: exercise
    }));
  });

  var onPreAssessment = function onPreAssessment() {
    showSidebar();
    dispatch((0, _coach.goToAssessment)());
  };

  var onWeeklyAssessment = function onWeeklyAssessment() {
    showSidebar();
    dispatch((0, _coach.goToWeeklyAssessment)());
  };

  return /*#__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: menu.isOpened ? "overlay-menu active" : "overlay-menu",
    onClick: showSidebar
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: menu.isOpened ? "main-menu active" : "main-menu"
  }, /*#__PURE__*/_react["default"].createElement("ul", {
    className: "exercise-list"
  }, /*#__PURE__*/_react["default"].createElement("li", {
    className: "primary-links",
    onClick: onToggleTutorial
  }, /*#__PURE__*/_react["default"].createElement(_md.MdOutlinePlayCircle, {
    className: "md-icon",
    size: "24px"
  }), "Tutorial"), /*#__PURE__*/_react["default"].createElement("li", {
    className: "primary-links",
    onClick: onPreAssessment
  }, /*#__PURE__*/_react["default"].createElement(_md.MdOutlineQuiz, {
    className: "md-icon",
    size: "24px"
  }), "PAIN-ASSESSMENT"), /*#__PURE__*/_react["default"].createElement("li", {
    className: "primary-links",
    onClick: onWeeklyAssessment
  }, /*#__PURE__*/_react["default"].createElement(_md.MdOutlineQuiz, {
    className: "md-icon",
    size: "24px"
  }), "WEEKLY ASSESSMENT"), /*#__PURE__*/_react["default"].createElement("li", {
    className: "menu-subtitle"
  }, "EXERCISES"), exercises.length > 0 && exercises.map(function (exercise) {
    var _resultsExercises$fin;

    return /*#__PURE__*/_react["default"].createElement("li", {
      onClick: function onClick(e) {
        return onClickMenu(e, exercise);
      },
      key: exercise.label,
      className: resultsExercises.find(function (exer) {
        return exer._id === exercise._id;
      }) ? "done" : ""
    }, exercise.label.toUpperCase(), /*#__PURE__*/_react["default"].createElement("div", {
      className: "actions-menu"
    }, /*#__PURE__*/_react["default"].createElement(_md.MdOutlinePhotoLibrary, {
      onClick: function onClick(e) {
        return onToggleGalley(e, exercise);
      },
      className: "compare-icon md-icon",
      size: "24px"
    }), (_resultsExercises$fin = resultsExercises.find(function (exer) {
      return exer._id === exercise._id;
    })) === null || _resultsExercises$fin === void 0 ? void 0 : _resultsExercises$fin.result));
  }))));
};

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

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