"use strict";

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

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

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

var _TransistionResults = _interopRequireDefault(require("../components/TransistionResults"));

var _TransistionSingleResult = _interopRequireDefault(require("../components/TransistionSingleResult"));

var _TransistionReadySetGo = _interopRequireDefault(require("../components/TransistionReadySetGo"));

var _TransistionOpenning = _interopRequireDefault(require("../components/TransistionOpenning"));

var _TransistionClosing = _interopRequireDefault(require("../components/TransistionClosing"));

var _InstructionalVideo = _interopRequireDefault(require("./InstructionalVideo"));

var _Tutorial = _interopRequireDefault(require("./Tutorial"));

var _SplashPage = _interopRequireDefault(require("./SplashPage"));

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

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

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 Main = function Main(props) {
  var dispatch = (0, _reactRedux.useDispatch)();

  var _useSelector = (0, _reactRedux.useSelector)(function (state) {
    return {
      user: state.rom.main.user,
      tutorial: state.rom.main.tutorial,
      splash: state.rom.main.splash,
      currentExercise: state.rom.main.currentExercise,
      currentTransition: state.rom.main.currentTransition,
      finishedExercises: state.rom.main.finishedExercises,
      resultsExercises: state.rom.main.resultsExercises,
      exercises: state.rom.main.exercises,
      paused: state.rom.main.paused,
      pose: state.rom.main.pose,
      identifier: state.rom.main.identifier,
      session: state.rom.main.session,
      gallery: state.rom.main.gallery,
      assessment: state.rom.main.assessment
    };
  }),
      user = _useSelector.user,
      tutorial = _useSelector.tutorial,
      splash = _useSelector.splash,
      currentExercise = _useSelector.currentExercise,
      currentTransition = _useSelector.currentTransition,
      finishedExercises = _useSelector.finishedExercises,
      resultsExercises = _useSelector.resultsExercises,
      exercises = _useSelector.exercises,
      paused = _useSelector.paused,
      pose = _useSelector.pose,
      identifier = _useSelector.identifier,
      gallery = _useSelector.gallery,
      assessment = _useSelector.assessment,
      session = _useSelector.session;

  var onNextTransition = function onNextTransition() {
    dispatch((0, _main.nextTransition)());
  };

  var onResetResultExercises = function onResetResultExercises() {
    dispatch((0, _main.resetResultsExercises)());
  };

  var onSavePhysicalAssessmentsMetrics = function onSavePhysicalAssessmentsMetrics() {
    dispatch((0, _main.savePhysicalAssessmentsMetrics)({
      session: session.id,
      identifier: identifier,
      user: user,
      anonymous: true,
      metrics: {
        exercise: currentExercise._id,
        value: pose.angleResult,
        printscreen: (0, _main.getPrintScreen)()
      }
    }));
  };

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

  (0, _react.useEffect)(function () {
    if (!splash.isOpened && !tutorial.isOpened && !paused && !gallery.isOpened && !assessment.isOpened && currentTransition === -1 && exercises.length > 0) {
      dispatch((0, _main.nextExercise)());
      onNextTransition();
    }
  }, [onNextTransition, tutorial, currentTransition, finishedExercises.finished, paused]);
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, tutorial.isOpened && /*#__PURE__*/_react["default"].createElement(_Tutorial["default"], null), splash.isOpened && /*#__PURE__*/_react["default"].createElement(_SplashPage["default"], {
    onNextTransition: onNextTransition
  }), (currentTransition === 0 || currentTransition === 1) && /*#__PURE__*/_react["default"].createElement(_InstructionalVideo["default"], {
    onNextTransition: onNextTransition
  }), currentTransition === 1 && /*#__PURE__*/_react["default"].createElement(_TransistionReadySetGo["default"], {
    isPaused: paused,
    onNextTransition: onNextTransition,
    onSavePhysicalAssessmentsMetrics: onSavePhysicalAssessmentsMetrics
  }), currentTransition === 2 && /*#__PURE__*/_react["default"].createElement(_TransistionClosing["default"], {
    isPaused: paused,
    onNextTransition: onNextTransition
  }), currentTransition === 3 && /*#__PURE__*/_react["default"].createElement(_TransistionSingleResult["default"], {
    isPaused: paused,
    onNextTransition: onNextTransition,
    exercise: currentExercise,
    resultsExercises: resultsExercises
  }), currentTransition === 4 && /*#__PURE__*/_react["default"].createElement(_TransistionOpenning["default"], {
    isPaused: paused,
    onNextTransition: onNextTransition
  }), finishedExercises.isOpened && finishedExercises.finished && /*#__PURE__*/_react["default"].createElement(_TransistionResults["default"], {
    resultsExercises: resultsExercises,
    onResetResultExercises: onResetResultExercises,
    onWeeklyAssessment: onWeeklyAssessment
  }), props.children);
};

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

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