"use strict";

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

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

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

var _antd = require("antd");

var _all = require("react-icons/all");

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

var _Menu = _interopRequireDefault(require("./Menu"));

var _Main = _interopRequireDefault(require("./Main"));

var _TemplateBottom = _interopRequireDefault(require("../components/TemplateBottom"));

var _TemplateTop = _interopRequireDefault(require("../components/TemplateTop"));

var _TemplateProgressBar = _interopRequireDefault(require("../components/TemplateProgressBar"));

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

require("./style.css");

var _excluded = ["redirectTo"];

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; }

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; }

var baseHeight = 130;
var baseWidth = 231.11;

var App = function App(props) {
  var dispatch = (0, _reactRedux.useDispatch)();

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

  var onResizeWindowByHeight = function onResizeWindowByHeight() {
    var width = 16 / 9 * (window.innerHeight - baseHeight);
    var height = window.innerHeight - baseHeight;
    dispatch((0, _main.updateAspectArea)({
      width: width,
      height: height
    }));
  };

  var onResizeWindowByWidth = function onResizeWindowByWidth() {
    var width = window.innerWidth - baseWidth;
    var height = 9 / 16 * (window.innerWidth - baseWidth);
    dispatch((0, _main.updateAspectArea)({
      width: width,
      height: height
    }));
  };

  var onResizeWindow = function onResizeWindow() {
    var width = window.innerWidth;
    var height = window.innerHeight;

    if (width / height >= 1.77) {
      onResizeWindowByHeight();
    } else {
      onResizeWindowByWidth();
    }
  };

  window.onresize = onResizeWindow;
  (0, _react.useEffect)(function () {
    onResizeWindow();
  }, []);
  (0, _react.useEffect)(function () {
    _axios["default"].defaults.baseURL = props.baseURL;

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

    dispatch((0, _main.updateProps)(rest));

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

  var toogleInvertCam = function toogleInvertCam() {
    dispatch((0, _main.invertCam)());
  };

  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "estimator-template",
    style: {
      width: aspectArea.width + "px",
      height: aspectArea.height + "px"
    }
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "coach-container",
    style: {
      width: aspectArea.width + "px",
      height: aspectArea.height + "px"
    }
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "overlay-container"
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "overlay-coach"
  }, /*#__PURE__*/_react["default"].createElement(_TemplateTop["default"], null, /*#__PURE__*/_react["default"].createElement(_antd.Button, {
    className: "btn-invert-cam",
    type: "primary",
    shape: "circle",
    icon: /*#__PURE__*/_react["default"].createElement(_all.MdFlipCameraAndroid, {
      size: "22px"
    }),
    size: "large",
    onClick: toogleInvertCam
  }), !props.isPhysioterapist && /*#__PURE__*/_react["default"].createElement(_TemplateProgressBar["default"], {
    progress: progress
  })), /*#__PURE__*/_react["default"].createElement(_TemplateBottom["default"], {
    title: currentExercise === null || currentExercise === void 0 ? void 0 : currentExercise.title
  }), /*#__PURE__*/_react["default"].createElement(_Menu["default"], null))), /*#__PURE__*/_react["default"].createElement(_Main["default"], null)));
};

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

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