"use strict";

exports.__esModule = true;
exports.updateVideoOnObjectToSave = exports.updateSingleSettings = exports.updateRecordConsult = exports.updateProps = exports.updateObjectToSave = exports.updateNewExercise = exports.updateGeneralSettings = exports.updateAspectArea = exports.toggleMenu = exports.startAsUser = exports.shouldRedirectTo = exports.shouldHideMenu = exports.setSelectedVideoId = exports.setRehabPeriod = exports.setPainLevel = exports.setMobility = exports.setFacingMode = exports.savePhysioterapistVideoToPatient = exports.savePhysioterapistVideo = exports.savePatientVideo = exports.savePatientEvaluation = exports.recoverySession = exports.nextSequence = exports.nextExercise = exports.main = exports.invertVideo = exports.invertCam = exports.initSequence = exports.goToExercise = exports.getVideoFromLibrary = exports.fetchExercisesEffort = exports.fetchExercises = exports.deleteVideoFromLibrary = exports["default"] = exports.cleanErrorMessage = exports.addVideoToLibrary = void 0;

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

var _toolkit = require("@reduxjs/toolkit");

var _axios = _interopRequireDefault(require("axios"));

var _uuid = require("uuid");

var _services = require("../../services");

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

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

var CancelToken = _axios["default"].CancelToken;
var cancel;
var savePhysioterapistVideo = (0, _toolkit.createAsyncThunk)('rehab/savePhysioterapistVideo', /*#__PURE__*/function () {
  var _ref = _asyncToGenerator( /*#__PURE__*/_regenerator["default"].mark(function _callee(body) {
    var _yield$axios$post, data;

    return _regenerator["default"].wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            _context.prev = 0;
            _context.next = 3;
            return _axios["default"].post('/coach/rehab/exercises/formdata', body, {
              headers: {
                'Content-Type': 'multipart/form-data'
              },
              onUploadProgress: function onUploadProgress(progressEvent) {
                _services.EventEmitter.emit('UPLOAD_PROGRESS', Math.floor(100 * (progressEvent.loaded / progressEvent.total)));
              }
            });

          case 3:
            _yield$axios$post = _context.sent;
            data = _yield$axios$post.data;
            return _context.abrupt("return", data);

          case 8:
            _context.prev = 8;
            _context.t0 = _context["catch"](0);
            return _context.abrupt("return", _context.t0.response);

          case 11:
          case "end":
            return _context.stop();
        }
      }
    }, _callee, null, [[0, 8]]);
  }));

  return function (_x) {
    return _ref.apply(this, arguments);
  };
}());
exports.savePhysioterapistVideo = savePhysioterapistVideo;
var savePhysioterapistVideoToPatient = (0, _toolkit.createAsyncThunk)('rehab/savePhysioterapistVideo1', /*#__PURE__*/function () {
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regenerator["default"].mark(function _callee2(body) {
    var _yield$axios$post2, data;

    return _regenerator["default"].wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            _context2.prev = 0;
            _context2.next = 3;
            return _axios["default"].post('/coach/rehab/exercises', body);

          case 3:
            _yield$axios$post2 = _context2.sent;
            data = _yield$axios$post2.data;
            return _context2.abrupt("return", data);

          case 8:
            _context2.prev = 8;
            _context2.t0 = _context2["catch"](0);
            return _context2.abrupt("return", _context2.t0.response);

          case 11:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2, null, [[0, 8]]);
  }));

  return function (_x2) {
    return _ref2.apply(this, arguments);
  };
}());
exports.savePhysioterapistVideoToPatient = savePhysioterapistVideoToPatient;
var savePatientVideo = (0, _toolkit.createAsyncThunk)('rehab/savePatientVideo', /*#__PURE__*/function () {
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regenerator["default"].mark(function _callee3(body) {
    var _yield$axios$post3, data;

    return _regenerator["default"].wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            _context3.prev = 0;
            _context3.next = 3;
            return _axios["default"].post('/coach/rehab/exercises/patient', body, {
              headers: {
                'Content-Type': 'multipart/form-data'
              },
              onUploadProgress: function onUploadProgress(progressEvent) {
                _services.EventEmitter.emit('UPLOAD_PROGRESS', Math.floor(100 * (progressEvent.loaded / progressEvent.total)));
              }
            });

          case 3:
            _yield$axios$post3 = _context3.sent;
            data = _yield$axios$post3.data;
            return _context3.abrupt("return", data);

          case 8:
            _context3.prev = 8;
            _context3.t0 = _context3["catch"](0);
            return _context3.abrupt("return", _context3.t0.response);

          case 11:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3, null, [[0, 8]]);
  }));

  return function (_x3) {
    return _ref3.apply(this, arguments);
  };
}());
exports.savePatientVideo = savePatientVideo;
var savePatientEvaluation = (0, _toolkit.createAsyncThunk)('rehab/savePatientEvaluation', /*#__PURE__*/function () {
  var _ref4 = _asyncToGenerator( /*#__PURE__*/_regenerator["default"].mark(function _callee4(body) {
    var _yield$axios$post4, data;

    return _regenerator["default"].wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            _context4.prev = 0;
            _context4.next = 3;
            return _axios["default"].post('/coach/rehab/evaluations', body);

          case 3:
            _yield$axios$post4 = _context4.sent;
            data = _yield$axios$post4.data;
            return _context4.abrupt("return", data);

          case 8:
            _context4.prev = 8;
            _context4.t0 = _context4["catch"](0);
            return _context4.abrupt("return", _context4.t0.response);

          case 11:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4, null, [[0, 8]]);
  }));

  return function (_x4) {
    return _ref4.apply(this, arguments);
  };
}());
exports.savePatientEvaluation = savePatientEvaluation;
var fetchExercises = (0, _toolkit.createAsyncThunk)('fetchExercises', /*#__PURE__*/function () {
  var _ref5 = _asyncToGenerator( /*#__PURE__*/_regenerator["default"].mark(function _callee5(user) {
    var _yield$axios$get, data;

    return _regenerator["default"].wrap(function _callee5$(_context5) {
      while (1) {
        switch (_context5.prev = _context5.next) {
          case 0:
            _context5.prev = 0;
            _context5.next = 3;
            return _axios["default"].get("/coach/rehab/" + user + "/exercises/list");

          case 3:
            _yield$axios$get = _context5.sent;
            data = _yield$axios$get.data;
            return _context5.abrupt("return", data);

          case 8:
            _context5.prev = 8;
            _context5.t0 = _context5["catch"](0);
            return _context5.abrupt("return", _context5.t0.response);

          case 11:
          case "end":
            return _context5.stop();
        }
      }
    }, _callee5, null, [[0, 8]]);
  }));

  return function (_x5) {
    return _ref5.apply(this, arguments);
  };
}());
exports.fetchExercises = fetchExercises;
var fetchExercisesEffort = (0, _toolkit.createAsyncThunk)('fetchExercisesEffort', /*#__PURE__*/function () {
  var _ref6 = _asyncToGenerator( /*#__PURE__*/_regenerator["default"].mark(function _callee6(user) {
    var _yield$axios$get2, data;

    return _regenerator["default"].wrap(function _callee6$(_context6) {
      while (1) {
        switch (_context6.prev = _context6.next) {
          case 0:
            _context6.prev = 0;
            _context6.next = 3;
            return _axios["default"].get('/coach/exercises-effort');

          case 3:
            _yield$axios$get2 = _context6.sent;
            data = _yield$axios$get2.data;
            return _context6.abrupt("return", data);

          case 8:
            _context6.prev = 8;
            _context6.t0 = _context6["catch"](0);
            return _context6.abrupt("return", _context6.t0.response);

          case 11:
          case "end":
            return _context6.stop();
        }
      }
    }, _callee6, null, [[0, 8]]);
  }));

  return function (_x6) {
    return _ref6.apply(this, arguments);
  };
}());
exports.fetchExercisesEffort = fetchExercisesEffort;
var addVideoToLibrary = (0, _toolkit.createAsyncThunk)('rehab/addVideoToLibrary', /*#__PURE__*/function () {
  var _ref7 = _asyncToGenerator( /*#__PURE__*/_regenerator["default"].mark(function _callee7(body) {
    var _yield$axios$post5, data;

    return _regenerator["default"].wrap(function _callee7$(_context7) {
      while (1) {
        switch (_context7.prev = _context7.next) {
          case 0:
            _context7.prev = 0;
            _context7.next = 3;
            return _axios["default"].post('/coach/rehab/library', body, {
              headers: {
                'Content-Type': 'multipart/form-data'
              },
              onUploadProgress: function onUploadProgress(progressEvent) {
                _services.EventEmitter.emit('UPLOAD_PROGRESS', Math.floor(100 * (progressEvent.loaded / progressEvent.total)));
              }
            });

          case 3:
            _yield$axios$post5 = _context7.sent;
            data = _yield$axios$post5.data;
            return _context7.abrupt("return", data);

          case 8:
            _context7.prev = 8;
            _context7.t0 = _context7["catch"](0);
            return _context7.abrupt("return", _context7.t0.response);

          case 11:
          case "end":
            return _context7.stop();
        }
      }
    }, _callee7, null, [[0, 8]]);
  }));

  return function (_x7) {
    return _ref7.apply(this, arguments);
  };
}());
exports.addVideoToLibrary = addVideoToLibrary;
var getVideoFromLibrary = (0, _toolkit.createAsyncThunk)('rehab/getVideoFromLibrary', /*#__PURE__*/function () {
  var _ref8 = _asyncToGenerator( /*#__PURE__*/_regenerator["default"].mark(function _callee8(params) {
    var _yield$axios$get3, data;

    return _regenerator["default"].wrap(function _callee8$(_context8) {
      while (1) {
        switch (_context8.prev = _context8.next) {
          case 0:
            _context8.prev = 0;
            if (cancel) cancel('Operation canceled to save a new redux state');
            _context8.next = 4;
            return _axios["default"].get("coach/rehab/library/" + params, {
              cancelToken: new CancelToken(function executor(c) {
                cancel = c;
              })
            });

          case 4:
            _yield$axios$get3 = _context8.sent;
            data = _yield$axios$get3.data;
            return _context8.abrupt("return", data);

          case 9:
            _context8.prev = 9;
            _context8.t0 = _context8["catch"](0);
            return _context8.abrupt("return", _context8.t0.response);

          case 12:
          case "end":
            return _context8.stop();
        }
      }
    }, _callee8, null, [[0, 9]]);
  }));

  return function (_x8) {
    return _ref8.apply(this, arguments);
  };
}());
exports.getVideoFromLibrary = getVideoFromLibrary;
var deleteVideoFromLibrary = (0, _toolkit.createAsyncThunk)('rehab/deleteVideoFromLibrary', /*#__PURE__*/function () {
  var _ref9 = _asyncToGenerator( /*#__PURE__*/_regenerator["default"].mark(function _callee9(id) {
    var _yield$axios$delete, data;

    return _regenerator["default"].wrap(function _callee9$(_context9) {
      while (1) {
        switch (_context9.prev = _context9.next) {
          case 0:
            _context9.prev = 0;
            _context9.next = 3;
            return _axios["default"]["delete"]("/coach/rehab/library/" + id);

          case 3:
            _yield$axios$delete = _context9.sent;
            data = _yield$axios$delete.data;
            return _context9.abrupt("return", data);

          case 8:
            _context9.prev = 8;
            _context9.t0 = _context9["catch"](0);
            return _context9.abrupt("return", _context9.t0.response);

          case 11:
          case "end":
            return _context9.stop();
        }
      }
    }, _callee9, null, [[0, 8]]);
  }));

  return function (_x9) {
    return _ref9.apply(this, arguments);
  };
}());
exports.deleteVideoFromLibrary = deleteVideoFromLibrary;
var recoverySession = (0, _toolkit.createAsyncThunk)('recoverySession', /*#__PURE__*/function () {
  var _ref10 = _asyncToGenerator( /*#__PURE__*/_regenerator["default"].mark(function _callee10(user) {
    var _yield$axios$get4, data;

    return _regenerator["default"].wrap(function _callee10$(_context10) {
      while (1) {
        switch (_context10.prev = _context10.next) {
          case 0:
            _context10.prev = 0;
            _context10.next = 3;
            return _axios["default"].get("/coach/rehab/recovery/session/" + user);

          case 3:
            _yield$axios$get4 = _context10.sent;
            data = _yield$axios$get4.data;
            return _context10.abrupt("return", data);

          case 8:
            _context10.prev = 8;
            _context10.t0 = _context10["catch"](0);
            return _context10.abrupt("return", _context10.t0.response);

          case 11:
          case "end":
            return _context10.stop();
        }
      }
    }, _callee10, null, [[0, 8]]);
  }));

  return function (_x10) {
    return _ref10.apply(this, arguments);
  };
}());
exports.recoverySession = recoverySession;
var sequenceListPhysioretapist = ['recordConsult', 'library', 'recordVideo', 'resultRecordScreen'];
var sequenceListPatient = ['recordVideo', 'evaluationAssessment'];

var linkedList = function linkedList(arr) {
  return arr.reduceRight(function (next, value) {
    return {
      value: value,
      next: next
    };
  }, null);
};

var initialState = {
  user: null,
  users: [],
  sequence: null,
  recordConsult: {
    title: '',
    description: '',
    repetitions: null,
    setsPerSessions: null,
    setsPerDay: null,
    frequencyPerWeek: null,
    visible: false
  },
  completed: false,
  physioterapist: null,
  isPhysioterapist: false,
  exercises: [],
  exercisesEffort: [],
  exercisesCompleted: [],
  painLevel: 0,
  mobility: 0,
  currentExercise: null,
  isMenuOpened: false,
  isHiddenMenu: true,
  identifier: (0, _uuid.v4)(),
  shouldRedirect: false,
  isInvertVideo: false,
  isInvertCam: false,
  progress: {
    total: 0,
    // numero de exercícios
    completed: 0,
    current: 0
  },
  aspectArea: {
    width: 1280,
    height: 720
  },
  libraryVideos: {
    docs: []
  },
  objectToSave: {
    users: [],
    physioterapist: '',
    videos: [],
    settings: {
      description: '',
      repetitions: null,
      setsPerSessions: null,
      setsPerDay: null,
      frequencyPerWeek: null
    }
  },
  recordVideoToLibrary: {
    title: '',
    physioterapist: '',
    description: '',
    repetitions: null,
    setsPerSessions: null,
    setsPerDay: null,
    frequencyPerWeek: null,
    visible: null
  },
  selectedVideoId: null,
  facingMode: 'user',
  // environment
  continueWhereLeftOff: false,
  errorMessage: null
};
var main = (0, _toolkit.createSlice)({
  name: 'main',
  initialState: initialState,
  reducers: {
    initSequence: function initSequence(state, action) {
      state.sequence = linkedList(state.isPhysioterapist ? sequenceListPhysioretapist : sequenceListPatient);
      state.recordConsult = initialState.recordConsult;
      state.completed = initialState.completed;
      state.exercisesCompleted = initialState.exercisesCompleted;
      state.currentExercise = initialState.currentExercise;
      state.shouldRedirect = initialState.shouldRedirect;
      state.identifier = (0, _uuid.v4)();
      state.continueWhereLeftOff = initialState.continueWhereLeftOff;
    },
    nextSequence: function nextSequence(state, action) {
      state.sequence = action.payload;
    },
    updateProps: function updateProps(state, action) {
      var _action$payload;

      state.user = action.payload.user;
      state.users = action.payload.users;
      state.physioterapist = (_action$payload = action.payload) === null || _action$payload === void 0 ? void 0 : _action$payload.physioterapist;
      state.isPhysioterapist = action.payload.isPhysioterapist;
      state.sequence = linkedList(action.payload.isPhysioterapist ? sequenceListPhysioretapist : sequenceListPatient);
      state.objectToSave.users = action.payload.users;
      state.objectToSave.physioterapist = action.payload.physioterapist;
    },
    goToExercise: function goToExercise(state, action) {
      state.currentExercise = action.payload;
    },
    setPainLevel: function setPainLevel(state, action) {
      state.painLevel = action.payload;
    },
    setMobility: function setMobility(state, action) {
      state.mobility = action.payload;
    },
    nextExercise: function nextExercise(state) {
      var arr1 = state.exercises.map(function (exer) {
        return exer._id;
      });
      var arr2 = state.exercisesCompleted.map(function (exer) {
        return exer.exercise;
      });
      var diff = arr1.filter(function (x) {
        return !arr2.includes(x);
      });

      if (diff.length > 0) {
        var exerciseIndex = state.exercises.findIndex(function (elm) {
          return state.currentExercise ? elm._id === state.currentExercise : elm._id === diff[0];
        });
        state.currentExercise = _extends({}, state.exercises[exerciseIndex]);
        state.progress.current = arr1.length - diff.length;
        state.progress.completed = state.progress.current * 100 / state.progress.total;
        return;
      }

      state.currentExercise = null;
    },
    updateRecordConsult: function updateRecordConsult(state, action) {
      state.recordConsult = action.payload;
    },
    toggleMenu: function toggleMenu(state, action) {
      state.isMenuOpened = !state.isMenuOpened;
    },
    invertVideo: function invertVideo(state, action) {
      state.isInvertVideo = !state.isInvertVideo;
    },
    invertCam: function invertCam(state, action) {
      state.isInvertCam = !state.isInvertCam;
    },
    shouldHideMenu: function shouldHideMenu(state, action) {
      state.isHiddenMenu = action.payload;
    },
    shouldRedirectTo: function shouldRedirectTo(state, action) {
      state.shouldRedirect = true;
    },
    updateAspectArea: function updateAspectArea(state, action) {
      state.aspectArea = _extends({}, state.aspectArea, action.payload);
    },
    updateObjectToSave: function updateObjectToSave(state, action) {},
    updateVideoOnObjectToSave: function updateVideoOnObjectToSave(state, action) {
      state.objectToSave.videos = action.payload.checked ? [].concat(state.objectToSave.videos, [action.payload.values]) : state.objectToSave.videos.filter(function (video) {
        return video.rehabLibraryId !== action.payload.values.rehabLibraryId;
      });
    },
    setRehabPeriod: function setRehabPeriod(state, action) {
      state.objectToSave.settings.startDate = action.payload.startDate;
      state.objectToSave.settings.finalDate = action.payload.finalDate;
    },
    updateGeneralSettings: function updateGeneralSettings(state, action) {
      var _action$payload2, _action$payload3, _action$payload4, _action$payload5, _action$payload6;

      state.objectToSave.settings.description = (_action$payload2 = action.payload) === null || _action$payload2 === void 0 ? void 0 : _action$payload2.description;
      state.objectToSave.settings.repetitions = (_action$payload3 = action.payload) === null || _action$payload3 === void 0 ? void 0 : _action$payload3.repetitions;
      state.objectToSave.settings.setsPerSessions = (_action$payload4 = action.payload) === null || _action$payload4 === void 0 ? void 0 : _action$payload4.setsPerSessions;
      state.objectToSave.settings.setsPerDay = (_action$payload5 = action.payload) === null || _action$payload5 === void 0 ? void 0 : _action$payload5.setsPerDay;
      state.objectToSave.settings.frequencyPerWeek = (_action$payload6 = action.payload) === null || _action$payload6 === void 0 ? void 0 : _action$payload6.frequencyPerWeek;
    },
    updateSingleSettings: function updateSingleSettings(state, action) {
      state.objectToSave.videos = state.objectToSave.videos.map(function (video) {
        if (video.rehabLibraryId === action.payload.rehabLibraryId) video = _extends({}, video, action.payload);
        return video;
      });
    },
    updateNewExercise: function updateNewExercise(state, action) {
      state.recordVideoToLibrary = action.payload;
    },
    setSelectedVideoId: function setSelectedVideoId(state, action) {
      state.selectedVideoId = action.payload;
    },
    setFacingMode: function setFacingMode(state, action) {
      state.facingMode = state.facingMode === 'user' ? 'environment' : 'user';
    },
    cleanErrorMessage: function cleanErrorMessage(state, action) {
      state.errorMessage = null;
    },
    startAsUser: function startAsUser(state, action) {
      state.isPhysioterapist = false;
      state.sequence = linkedList(sequenceListPatient);
      state.identifier = (0, _uuid.v4)();
    }
  },
  extraReducers: function extraReducers(builder) {
    builder.addCase(savePhysioterapistVideo.fulfilled, function (state, action) {
      state.completed = true;
    });
    builder.addCase(savePhysioterapistVideoToPatient.fulfilled, function (state, action) {
      var _action$payload7;

      if (((_action$payload7 = action.payload) === null || _action$payload7 === void 0 ? void 0 : _action$payload7.status) === 400) {
        state.errorMessage = action.payload.data;
        state.objectToSave.videos = initialState.objectToSave.videos;
      } else {
        state.completed = true;
      }
    });
    builder.addCase(savePatientVideo.fulfilled, function (state, action) {
      state.exercisesCompleted = [].concat(state.exercisesCompleted, [action.payload]);
      state.completed = state.exercises.length === state.exercisesCompleted.length;
      state.isHiddenMenu = false;
      if (!state.completed) state.currentExercise = null;
    });
    builder.addCase(fetchExercises.fulfilled, function (state, action) {
      state.exercises = [].concat(action.payload);
      state.currentExercise = state.exercises[0];
      state.exercisesCompleted = [];
      state.isHiddenMenu = state.exercises.length === 0 ? true : false;
      state.progress.total = state.exercises.length;
    });
    builder.addCase(fetchExercisesEffort.fulfilled, function (state, action) {
      state.exercisesEffort = [].concat(action.payload);
    });
    builder.addCase(savePatientEvaluation.fulfilled, function (state, action) {
      state.shouldRedirect = true;
    });
    builder.addCase(addVideoToLibrary.fulfilled, function (state, action) {
      state.completed = true;
      state.libraryVideos.docs = [].concat(state.libraryVideos.docs, [action.payload]);
    });
    builder.addCase(getVideoFromLibrary.fulfilled, function (state, action) {
      state.libraryVideos = action.payload;
    });
    builder.addCase(deleteVideoFromLibrary.fulfilled, function (state, action) {
      state.libraryVideos.docs = state.libraryVideos.docs.filter(function (x) {
        return action.payload._id !== x._id;
      });
    });
    builder.addCase(recoverySession.fulfilled, function (state, action) {
      if (action.payload && Object.keys(action.payload).length > 0) {
        state.identifier = action.payload.identifier;

        if (state.exercises.length === action.payload.exercises.length) {
          // isso significa que falta o evaluation final e por isso chamo a próxima sequencia
          state.sequence = state.sequence.next;
        } else {
          state.exercisesCompleted = [].concat(action.payload.exercises);
          var arr1 = state.exercises.map(function (exer) {
            return exer._id;
          });
          var arr2 = state.exercisesCompleted.map(function (exer) {
            return exer._id;
          });
          var diff = arr1.filter(function (x) {
            return !arr2.includes(x);
          });

          if (diff.length > 0) {
            var exerciseIndex = state.exercises.findIndex(function (elm) {
              return elm._id === diff[0];
            });
            state.currentExercise = _extends({}, state.exercises[exerciseIndex]);
            state.progress.current = arr1.length - diff.length;
            state.progress.completed = state.progress.current * 100 / state.progress.total;
          }
        }

        state.continueWhereLeftOff = true;
      }
    });
  }
});
exports.main = main;
var _main$actions = main.actions,
    initSequence = _main$actions.initSequence,
    nextSequence = _main$actions.nextSequence,
    updateProps = _main$actions.updateProps,
    updateRecordConsult = _main$actions.updateRecordConsult,
    toggleMenu = _main$actions.toggleMenu,
    goToExercise = _main$actions.goToExercise,
    nextExercise = _main$actions.nextExercise,
    shouldHideMenu = _main$actions.shouldHideMenu,
    shouldRedirectTo = _main$actions.shouldRedirectTo,
    invertVideo = _main$actions.invertVideo,
    invertCam = _main$actions.invertCam,
    updateAspectArea = _main$actions.updateAspectArea,
    setPainLevel = _main$actions.setPainLevel,
    setMobility = _main$actions.setMobility,
    setRehabPeriod = _main$actions.setRehabPeriod,
    updateObjectToSave = _main$actions.updateObjectToSave,
    updateGeneralSettings = _main$actions.updateGeneralSettings,
    updateSingleSettings = _main$actions.updateSingleSettings,
    updateVideoOnObjectToSave = _main$actions.updateVideoOnObjectToSave,
    updateNewExercise = _main$actions.updateNewExercise,
    setSelectedVideoId = _main$actions.setSelectedVideoId,
    setFacingMode = _main$actions.setFacingMode,
    cleanErrorMessage = _main$actions.cleanErrorMessage,
    startAsUser = _main$actions.startAsUser;
exports.startAsUser = startAsUser;
exports.cleanErrorMessage = cleanErrorMessage;
exports.setFacingMode = setFacingMode;
exports.setSelectedVideoId = setSelectedVideoId;
exports.updateNewExercise = updateNewExercise;
exports.updateVideoOnObjectToSave = updateVideoOnObjectToSave;
exports.updateSingleSettings = updateSingleSettings;
exports.updateGeneralSettings = updateGeneralSettings;
exports.updateObjectToSave = updateObjectToSave;
exports.setRehabPeriod = setRehabPeriod;
exports.setMobility = setMobility;
exports.setPainLevel = setPainLevel;
exports.updateAspectArea = updateAspectArea;
exports.invertCam = invertCam;
exports.invertVideo = invertVideo;
exports.shouldRedirectTo = shouldRedirectTo;
exports.shouldHideMenu = shouldHideMenu;
exports.nextExercise = nextExercise;
exports.goToExercise = goToExercise;
exports.toggleMenu = toggleMenu;
exports.updateRecordConsult = updateRecordConsult;
exports.updateProps = updateProps;
exports.nextSequence = nextSequence;
exports.initSequence = initSequence;
var _default = main.reducer;
exports["default"] = _default;