import React, { useState, useRef, memo, useEffect } from 'react';
import { useDispatch } from 'react-redux';
import { toggleTutorial } from "../../store/rom/main";
import "./style.css";

var Tutorial = function Tutorial(props) {
  var videoRef = useRef(null);

  var _useState = useState(true),
      close = _useState[0],
      setClose = _useState[1];

  var dispatch = useDispatch();

  var onSkipTutorial = function onSkipTutorial() {
    setClose(false);
    dispatch(toggleTutorial(false));
    localStorage.setItem('watchedTutorial', true);
  };

  useEffect(function () {
    videoRef.current.currentTime = 0;
    videoRef.current.load();

    videoRef.current.onended = function () {
      props.onSkipTutorial();
    };
  }, [props.onSkipTutorial]);
  return /*#__PURE__*/React.createElement("div", {
    className: "tutorial " + (close ? 'closed' : '')
  }, /*#__PURE__*/React.createElement("div", {
    className: "tutorial-container"
  }, /*#__PURE__*/React.createElement("div", {
    className: "tutorial-video " + (close ? 'closed' : '')
  }, /*#__PURE__*/React.createElement("video", {
    id: "video",
    className: "tutorial-video",
    ref: videoRef,
    autoPlay: true,
    preload: "metadata",
    src: "https://risecxlibrary.blob.core.windows.net/coach/tutorial.mp4",
    type: "video/mp4"
  }), /*#__PURE__*/React.createElement("button", {
    className: "btn-outline",
    onClick: onSkipTutorial
  }, "SKIP TUTORIAL"))));
};

export default memo(Tutorial);