import React, { memo, useCallback } from 'react';
import { MdMenu, MdCheck } from 'react-icons/md';
import { useSelector, useDispatch } from 'react-redux';
import { goToExercise, toggleMenu } from "../../store/rom/main";

var Menu = function Menu(props) {
  var dispatch = useDispatch();

  var _useSelector = 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(toggleMenu());
  };

  var onClickMenu = useCallback(function (e, exercise) {
    e.stopPropagation();
    showSidebar();
    dispatch(goToExercise(exercise));
  });
  return !isPhysioterapist && !isHiddenMenu && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
    className: "btn-icon btn-menu",
    onClick: showSidebar
  }, /*#__PURE__*/React.createElement(MdMenu, {
    className: "md-icon",
    color: "#FFF",
    size: "26px"
  })), /*#__PURE__*/React.createElement("div", {
    className: isMenuOpened ? 'overlay-menu active' : 'overlay-menu',
    onClick: showSidebar
  }), /*#__PURE__*/React.createElement("div", {
    className: isMenuOpened ? 'main-menu active' : 'main-menu'
  }, /*#__PURE__*/React.createElement("ul", {
    className: "exercise-list"
  }, /*#__PURE__*/React.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.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.createElement("div", {
      className: "actions-menu"
    }, /*#__PURE__*/React.createElement(MdCheck, {
      className: "exercise-check md-icon",
      size: "24px"
    })));
  }))));
};

export default memo(Menu);