"use strict";

exports.__esModule = true;
exports.default = void 0;
var _includes2 = _interopRequireDefault(require("lodash/fp/includes"));
var _noop2 = _interopRequireDefault(require("lodash/fp/noop"));
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _qs = _interopRequireDefault(require("qs"));
var _provider = _interopRequireDefault(require("../../atom/provider"));
var _proptypes = require("../../util/proptypes");
var _style = _interopRequireDefault(require("./style.css"));
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); }
const getUrl = ({
  url,
  type,
  id,
  query = {},
  opts = {}
}) => {
  switch (type) {
    case 'youtube':
      return `https://www.youtube.com/embed/${id}?${_qs.default.stringify({
        ...query,
        ...opts
      })}`;
    case 'uptale':
      return `https://my.uptale.io/Experience/Launch?id=${id}`;
    case 'omniPlayer':
      return `https://mms.myomni.live/${id}`;
    case 'jwplayer':
      return `https://content.jwplatform.com/players/${id}-7IMa4DCK.html`;
    default:
      return url;
  }
};
class VideoIframe extends _react.default.Component {
  static contextTypes = {
    Vimeo: _provider.default.childContextTypes.Vimeo
  };
  componentDidMount() {
    const {
      type
    } = this.props;
    if (type === 'kontiki') {
      const {
        onPlay = _noop2.default
      } = this.props;
      onPlay();
    }
  }
  render() {
    const {
      type,
      id,
      url,
      autoplay = false,
      width = '100%',
      height = '400px'
    } = this.props;
    const src = getUrl({
      url,
      type,
      id,
      autoplay
    });
    const properties = {
      allow: (0, _includes2.default)(type, ['faurecia-vr']) ? 'xr-spatial-tracking;fullscreen' : null,
      allowFullScreen: true,
      allowvr: (0, _includes2.default)(type, ['uptale', 'faurecia-vr']) ? 'yes' : null,
      scrolling: (0, _includes2.default)(type, ['uptale', 'faurecia-vr']) ? 'no' : null,
      frameBorder: '0'
    };
    return /*#__PURE__*/_react.default.createElement("iframe", _extends({}, properties, {
      src: src,
      width: width,
      height: height,
      className: _style.default.iframe
    }));
  }
}
VideoIframe.propTypes = process.env.NODE_ENV !== "production" ? {
  type: _propTypes.default.oneOf(['youtube', 'uptale', 'kontiki', 'jwplayer', 'omniPlayer', 'h5p', 'faurecia-vr']),
  width: _propTypes.default.string,
  height: _propTypes.default.string,
  url: _proptypes.SrcPropType,
  id: _propTypes.default.string,
  autoplay: _propTypes.default.bool,
  onPlay: _propTypes.default.func
} : {};
var _default = exports.default = VideoIframe;
//# sourceMappingURL=index.js.map