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); }
import React from 'react';
import Loader from '../../atom/loader';
import VideoIframe from '../video-iframe';
import JWPlayer from './jwplayer';
import Vimeo from './vimeo';
import style from './style.css';
import propTypes from './prop-types';
class VideoPlayer extends React.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.createElement(Vimeo, _extends({}, this.props, {
          key: id,
          width: width,
          height: height,
          video: id,
          className: style.wrapper,
          onPlay: this.handleOnPlay
        }));
      case 'application/youtube':
      case 'application/uptale':
      case 'application/h5p':
      case 'application/omniPlayer':
      case 'application/faurecia-vr':
        return /*#__PURE__*/React.createElement(VideoIframe, {
          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.createElement(Loader, null) : /*#__PURE__*/React.createElement(JWPlayer, _extends({}, otherProps, {
            disableAutostart: disableAutostart,
            jwpOptions: jwpOptions,
            onPlay: this.handleOnPlay,
            key: id
          }));
        }
    }
  };
  render() {
    const {
      id
    } = this.props;
    return /*#__PURE__*/React.createElement("div", {
      "data-name": "video-player",
      className: style.wrapper,
      key: id
    }, this.renderPlayer());
  }
}
VideoPlayer.propTypes = process.env.NODE_ENV !== "production" ? propTypes : {};
export default VideoPlayer;
//# sourceMappingURL=index.js.map