"use strict";

exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _loader = _interopRequireDefault(require("../../atom/loader"));
var _videoIframe = _interopRequireDefault(require("../video-iframe"));
var _jwplayer = _interopRequireDefault(require("./jwplayer"));
var _vimeo = _interopRequireDefault(require("./vimeo"));
var _style = _interopRequireDefault(require("./style.css"));
var _propTypes = _interopRequireDefault(require("./prop-types"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
class VideoPlayer extends _react.default.Component {
  static getDerivedStateFromProps(props, state) {
    if (props.id === state.id) return null;
    return {
      id: props.id,
      played: false
    };
  }
  constructor(props) {
    super(props);
    this.state = {
      played: false,
      id: props.id
    };
  }
  handleOnPlay = e => {
    const {
      played
    } = this.state;
    const {
      onResume,
      onPlay
    } = this.props;
    if (played) {
      if (onResume) onResume(e);
    } else if (onPlay) onPlay(e);
    this.setState({
      played: true
    });
  };
  renderPlayer = () => {
    const {
      mimeType,
      id,
      url,
      onPause,
      onEnded,
      width = '100%',
      height = '343px'
    } = this.props;
    switch (mimeType) {
      case 'application/vimeo':
        return /*#__PURE__*/_react.default.createElement(_vimeo.default, _extends({}, this.props, {
          key: id,
          width: width,
          height: height,
          video: id,
          className: _style.default.wrapper,
          onPlay: this.handleOnPlay
        }));
      case 'application/youtube':
      case 'application/uptale':
      case 'application/h5p':
      case 'application/omniPlayer':
      case 'application/faurecia-vr':
        return /*#__PURE__*/_react.default.createElement(_videoIframe.default, {
          key: id,
          type: mimeType.split('application/')[1],
          id: id,
          url: url,
          width: width,
          height: height,
          frameBorder: 0,
          allowFullScreen: true,
          onPlay: this.handleOnPlay,
          onPause: onPause,
          onEnded: onEnded
        });
      case 'application/kontiki':
      case 'application/jwplayer':
      case 'video/mp4':
        {
          const {
            loading = false,
            disableAutostart,
            jwpOptions,
            ...otherProps
          } = this.props;
          return loading ? /*#__PURE__*/_react.default.createElement(_loader.default, null) : /*#__PURE__*/_react.default.createElement(_jwplayer.default, _extends({}, otherProps, {
            disableAutostart: disableAutostart,
            jwpOptions: jwpOptions,
            onPlay: this.handleOnPlay,
            key: id
          }));
        }
    }
  };
  render() {
    const {
      id
    } = this.props;
    return /*#__PURE__*/_react.default.createElement("div", {
      "data-name": "video-player",
      className: _style.default.wrapper,
      key: id
    }, this.renderPlayer());
  }
}
VideoPlayer.propTypes = process.env.NODE_ENV !== "production" ? _propTypes.default : {};
var _default = exports.default = VideoPlayer;
//# sourceMappingURL=index.js.map