var _excluded = ["redirectTo"];

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

import React, { useEffect, memo } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import axios from 'axios';
import Bottom from "../components/TemplateBottom";
import Top from "../components/TemplateTop";
import Menu from "./Menu";
import Main from "./Main";
import TemplateProgressBar from "../components/TemplateProgressBar";
import { fetchExercises, updateProps, fetchExercisesEffort, initSequence, invertCam } from "../store/rehab/main";
import "./style.css";

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

  var _useSelector = useSelector(function (state) {
    return state.rehab.main;
  }),
      shouldRedirect = _useSelector.shouldRedirect,
      currentExercise = _useSelector.currentExercise,
      progress = _useSelector.progress;

  useEffect(function () {
    axios.defaults.baseURL = props.baseURL;

    var redirectTo = props.redirectTo,
        rest = _objectWithoutPropertiesLoose(props, _excluded);

    dispatch(updateProps(rest));

    if (!props.isPhysioterapist) {
      dispatch(fetchExercises(props.user));
      dispatch(fetchExercisesEffort());
    }
  }, []);
  useEffect(function () {
    if (shouldRedirect && (props === null || props === void 0 ? void 0 : props.redirectTo)) {
      props.redirectTo();
      dispatch(initSequence());
    }
  }, [shouldRedirect]);

  var toogleInvertCam = function toogleInvertCam() {
    dispatch(invertCam());
  };

  return /*#__PURE__*/React.createElement("div", {
    className: "estimator-template"
  }, /*#__PURE__*/React.createElement("div", {
    className: "coach-container"
  }, /*#__PURE__*/React.createElement("div", {
    className: "overlay-container"
  }, /*#__PURE__*/React.createElement("div", {
    className: "overlay-coach"
  }, /*#__PURE__*/React.createElement(Top, {
    toogleInvertCam: toogleInvertCam
  }, !props.isPhysioterapist && /*#__PURE__*/React.createElement(TemplateProgressBar, {
    progress: progress
  })), /*#__PURE__*/React.createElement(Bottom, {
    title: currentExercise === null || currentExercise === void 0 ? void 0 : currentExercise.title
  }), /*#__PURE__*/React.createElement(Menu, null))), /*#__PURE__*/React.createElement(Main, null)));
};

export default memo(App);