import _omit from "lodash/fp/omit";
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 VideoPlayer from '../video-player';
import DropDown from '../questions/drop-down';
import FreeText from '../questions/free-text';
import QcmDrag from '../questions/qcm-drag';
import Qcm from '../questions/qcm';
import QcmGraphic from '../questions/qcm-graphic';
import QuestionRange from '../questions/question-range';
import Template from '../questions/template';
import Audio from '../audio';
import Provider from '../../atom/provider';
import style from './style.css';
import propTypes, { MediaViewPropTypes, TYPE_AUDIO, TYPE_IMAGE, TYPE_VIDEO } from './prop-types';
const MediaView = ({
  media
}) => {
  const {
    videoId,
    type,
    ...childProps
  } = media;
  switch (type) {
    case TYPE_IMAGE:
      return /*#__PURE__*/React.createElement("div", {
        className: style.media,
        style: {
          backgroundImage: `url(${media.url})`
        }
      });
    case TYPE_VIDEO:
      return /*#__PURE__*/React.createElement("div", {
        className: style.video
      }, /*#__PURE__*/React.createElement(VideoPlayer, _extends({}, _omit('id', childProps), {
        id: videoId,
        height: "100%",
        width: "100%"
      })));
    case TYPE_AUDIO:
      return /*#__PURE__*/React.createElement("div", {
        className: style.audio
      }, /*#__PURE__*/React.createElement(Audio, _extends({}, _omit('id', childProps), {
        height: "100%",
        width: "100%"
      })));
    default:
      return null;
  }
};
MediaView.propTypes = process.env.NODE_ENV !== "production" ? MediaViewPropTypes : {};
const Switch = ({
  model,
  help,
  question
}) => {
  const {
    type
  } = model;
  switch (type) {
    case 'qcmDrag':
      return /*#__PURE__*/React.createElement(QcmDrag, _extends({}, model, {
        help: help,
        groupAriaLabel: question
      }));
    case 'qcm':
      return /*#__PURE__*/React.createElement(Qcm, _extends({}, model, {
        groupAriaLabel: question
      }));
    case 'qcmGraphic':
      return /*#__PURE__*/React.createElement(QcmGraphic, _extends({}, model, {
        groupAriaLabel: question
      }));
    case 'freeText':
      return /*#__PURE__*/React.createElement(FreeText, model);
    case 'dropDown':
      return /*#__PURE__*/React.createElement(DropDown, _extends({}, model, {
        groupAriaLabel: question
      }));
    case 'slider':
      return /*#__PURE__*/React.createElement(QuestionRange, _extends({}, model, {
        groupAriaLabel: question
      }));
    case 'template':
      return /*#__PURE__*/React.createElement(Template, _extends({}, model, {
        groupAriaLabel: question
      }));
  }
};
Switch.propTypes = process.env.NODE_ENV !== "production" ? {
  model: propTypes.model,
  help: propTypes.help,
  question: propTypes.question
} : {};
Switch.contextTypes = {
  translate: Provider.childContextTypes.translate
};
const Answer = props => {
  const {
    model,
    media,
    help,
    question
  } = props;
  return /*#__PURE__*/React.createElement("div", {
    "data-name": "answer",
    className: style.wrapper
  }, media ? /*#__PURE__*/React.createElement(MediaView, {
    media: media
  }) : null, /*#__PURE__*/React.createElement("form", {
    className: style.formWrapper
  }, /*#__PURE__*/React.createElement(Switch, {
    model: model,
    question: question,
    help: help
  })));
};
Answer.propTypes = process.env.NODE_ENV !== "production" ? propTypes : {};
Answer.contextTypes = {
  translate: Provider.childContextTypes.translate
};
export default Answer;
//# sourceMappingURL=index.js.map