import React, { useEffect, useRef, memo, useState } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import InstructionFrame from "../../components/TemplateInstruction";
import { invertVideo } from "../../store/rehab/main";
import "./style.css"; // const startIn = 0;

var InstructionalVideo = function InstructionalVideo(props) {
  var _currentExercise$reha, _currentExercise$reha2;

  var videoRef = useRef(null);

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

  var dispatch = useDispatch();
  useEffect(function () {
    videoRef.current.load();
  }, [currentExercise]);

  var toogleInvertVideo = function toogleInvertVideo() {
    dispatch(invertVideo());
  };

  return /*#__PURE__*/React.createElement("div", {
    className: "overlay-content"
  }, /*#__PURE__*/React.createElement(InstructionFrame, {
    currentExercise: currentExercise === null || currentExercise === void 0 ? void 0 : currentExercise.rehabExerciseLibraryId,
    toogleInvertVideo: toogleInvertVideo
  }, /*#__PURE__*/React.createElement("video", {
    id: "video",
    audio: "true",
    className: isInvertVideo ? 'instruction-video inverted' : 'instruction-video',
    ref: videoRef,
    autoPlay: true,
    loop: true,
    muted: true,
    preload: "metadata",
    key: currentExercise === null || currentExercise === void 0 ? void 0 : (_currentExercise$reha = currentExercise.rehabExerciseLibraryId) === null || _currentExercise$reha === void 0 ? void 0 : _currentExercise$reha.videoUrl,
    src: currentExercise === null || currentExercise === void 0 ? void 0 : (_currentExercise$reha2 = currentExercise.rehabExerciseLibraryId) === null || _currentExercise$reha2 === void 0 ? void 0 : _currentExercise$reha2.videoUrl,
    type: "video/mp4"
  })));
};

export default memo(InstructionalVideo);