"use strict";

exports.__esModule = true;
exports.default = void 0;
var _omit2 = _interopRequireDefault(require("lodash/fp/omit"));
var _react = _interopRequireDefault(require("react"));
var _videoPlayer = _interopRequireDefault(require("../video-player"));
var _dropDown = _interopRequireDefault(require("../questions/drop-down"));
var _freeText = _interopRequireDefault(require("../questions/free-text"));
var _qcmDrag = _interopRequireDefault(require("../questions/qcm-drag"));
var _qcm = _interopRequireDefault(require("../questions/qcm"));
var _qcmGraphic = _interopRequireDefault(require("../questions/qcm-graphic"));
var _questionRange = _interopRequireDefault(require("../questions/question-range"));
var _template = _interopRequireDefault(require("../questions/template"));
var _audio = _interopRequireDefault(require("../audio"));
var _provider = _interopRequireDefault(require("../../atom/provider"));
var _style = _interopRequireDefault(require("./style.css"));
var _propTypes = _interopRequireWildcard(require("./prop-types"));
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
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 MediaView = ({
  media
}) => {
  const {
    videoId,
    type,
    ...childProps
  } = media;
  switch (type) {
    case _propTypes.TYPE_IMAGE:
      return /*#__PURE__*/_react.default.createElement("div", {
        className: _style.default.media,
        style: {
          backgroundImage: `url(${media.url})`
        }
      });
    case _propTypes.TYPE_VIDEO:
      return /*#__PURE__*/_react.default.createElement("div", {
        className: _style.default.video
      }, /*#__PURE__*/_react.default.createElement(_videoPlayer.default, _extends({}, (0, _omit2.default)('id', childProps), {
        id: videoId,
        height: "100%",
        width: "100%"
      })));
    case _propTypes.TYPE_AUDIO:
      return /*#__PURE__*/_react.default.createElement("div", {
        className: _style.default.audio
      }, /*#__PURE__*/_react.default.createElement(_audio.default, _extends({}, (0, _omit2.default)('id', childProps), {
        height: "100%",
        width: "100%"
      })));
    default:
      return null;
  }
};
MediaView.propTypes = process.env.NODE_ENV !== "production" ? _propTypes.MediaViewPropTypes : {};
const Switch = ({
  model,
  help,
  question
}) => {
  const {
    type
  } = model;
  switch (type) {
    case 'qcmDrag':
      return /*#__PURE__*/_react.default.createElement(_qcmDrag.default, _extends({}, model, {
        help: help,
        groupAriaLabel: question
      }));
    case 'qcm':
      return /*#__PURE__*/_react.default.createElement(_qcm.default, _extends({}, model, {
        groupAriaLabel: question
      }));
    case 'qcmGraphic':
      return /*#__PURE__*/_react.default.createElement(_qcmGraphic.default, _extends({}, model, {
        groupAriaLabel: question
      }));
    case 'freeText':
      return /*#__PURE__*/_react.default.createElement(_freeText.default, model);
    case 'dropDown':
      return /*#__PURE__*/_react.default.createElement(_dropDown.default, _extends({}, model, {
        groupAriaLabel: question
      }));
    case 'slider':
      return /*#__PURE__*/_react.default.createElement(_questionRange.default, _extends({}, model, {
        groupAriaLabel: question
      }));
    case 'template':
      return /*#__PURE__*/_react.default.createElement(_template.default, _extends({}, model, {
        groupAriaLabel: question
      }));
  }
};
Switch.propTypes = process.env.NODE_ENV !== "production" ? {
  model: _propTypes.default.model,
  help: _propTypes.default.help,
  question: _propTypes.default.question
} : {};
Switch.contextTypes = {
  translate: _provider.default.childContextTypes.translate
};
const Answer = props => {
  const {
    model,
    media,
    help,
    question
  } = props;
  return /*#__PURE__*/_react.default.createElement("div", {
    "data-name": "answer",
    className: _style.default.wrapper
  }, media ? /*#__PURE__*/_react.default.createElement(MediaView, {
    media: media
  }) : null, /*#__PURE__*/_react.default.createElement("form", {
    className: _style.default.formWrapper
  }, /*#__PURE__*/_react.default.createElement(Switch, {
    model: model,
    question: question,
    help: help
  })));
};
Answer.propTypes = process.env.NODE_ENV !== "production" ? _propTypes.default : {};
Answer.contextTypes = {
  translate: _provider.default.childContextTypes.translate
};
var _default = exports.default = Answer;
//# sourceMappingURL=index.js.map