'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = undefined;

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _dec, _class, _class2, _temp2;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _reactImmutableProptypes = require('react-immutable-proptypes');

var _reactImmutableProptypes2 = _interopRequireDefault(_reactImmutableProptypes);

var _Button = require('@instructure/ui-buttons/lib/components/Button');

var _Button2 = _interopRequireDefault(_Button);

var _CloseButton = require('@instructure/ui-buttons/lib/components/CloseButton');

var _CloseButton2 = _interopRequireDefault(_CloseButton);

var _Heading = require('@instructure/ui-elements/lib/components/Heading');

var _Heading2 = _interopRequireDefault(_Heading);

var _lib = require('@instructure/ui-themeable/lib');

var _lib2 = _interopRequireDefault(_lib);

var _RichContentRenderer = require('quiz-interactions/lib/components/common/components/rce/RichContentRenderer');

var _RichContentRenderer2 = _interopRequireDefault(_RichContentRenderer);

var _RichContentInput = require('../../../../common/components/RichContentInput');

var _RichContentInput2 = _interopRequireDefault(_RichContentInput);

var _formatMessage = require('../../../../common/format-message');

var _formatMessage2 = _interopRequireDefault(_formatMessage);

var _Modal = require('../../../../common/components/Modal');

var _Modal2 = _interopRequireDefault(_Modal);

var _theme = require('./theme');

var _theme2 = _interopRequireDefault(_theme);

var _constants = require('../../../../constants');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var styles = {
  template: function template(theme) {
    return '/*  imported from styles.css  */\n\n.ItemFeedbackModal__styles__itemStem {\n  white-space: nowrap;\n  overflow: hidden;\n  text-overflow: ellipsis;\n}\n\n.ItemFeedbackModal__styles__feedbackLabel {\n  font-size: ' + theme.feedbackLabelFontSize + ';\n}\n';
  },
  'itemStem': 'ItemFeedbackModal__styles__itemStem',
  'feedbackLabel': 'ItemFeedbackModal__styles__feedbackLabel'
};
var ItemFeedbackModal = (_dec = (0, _lib2.default)(_theme2.default, styles), _dec(_class = (_temp2 = _class2 = function (_Component) {
  (0, _inherits3.default)(ItemFeedbackModal, _Component);

  function ItemFeedbackModal() {
    var _ref;

    var _temp, _this, _ret;

    (0, _classCallCheck3.default)(this, ItemFeedbackModal);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = ItemFeedbackModal.__proto__ || Object.getPrototypeOf(ItemFeedbackModal)).call.apply(_ref, [this].concat(args))), _this), _this.onFeedbackChange = function (e, _ref2) {
      var editorContent = _ref2.editorContent;

      var key = e.target.id;
      var newFeedback = _this.props.feedback.set(key, editorContent);
      _this.props.setUi(_constants.ITEM_FEEDBACK_MODAL_FEEDBACK, newFeedback);
    }, _this.continueAction = function () {
      _this.props.changeItemFeedback(_this.props.item.id, _this.props.feedback);
      _this.closeAction();
    }, _this.closeAction = function () {
      _this.modalTrigger && _this.modalTrigger.focus();
      delete _this.modalTrigger;
      _this.props.closeModal();
    }, _this.returnToFeedback = function () {
      _this.props.openModal(_constants.ITEM_FEEDBACK_MODAL, { modalTrigger: _this.modalTrigger });
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  (0, _createClass3.default)(ItemFeedbackModal, [{
    key: 'componentWillReceiveProps',
    value: function componentWillReceiveProps(nextProps) {
      if (nextProps.modalTrigger) {
        this.modalTrigger = nextProps.modalTrigger;
      }
    }
  }, {
    key: 'cancelButton',
    value: function cancelButton() {
      return _react2.default.createElement(
        _Button2.default,
        { onClick: this.closeAction, margin: _constants.XSMALL_SIDE_MARGIN },
        'Annuleren'
      );
    }
  }, {
    key: 'doneButton',
    value: function doneButton() {
      return _react2.default.createElement(
        _Button2.default,
        {
          variant: 'primary',
          onClick: this.continueAction,
          margin: _constants.XSMALL_SIDE_MARGIN
        },
        'Gereed'
      );
    }
  }, {
    key: 'renderRichContentInput',
    value: function renderRichContentInput(key, label) {
      return _react2.default.createElement(
        'div',
        null,
        _react2.default.createElement('br', null),
        _react2.default.createElement(
          'label',
          { className: styles.feedbackLabel, htmlFor: key },
          label
        ),
        _react2.default.createElement(_RichContentInput2.default, {
          textareaId: key,
          defaultContent: this.props.feedback.get(key),
          onChange: this.onFeedbackChange,
          parentType: this.props.parentType,
          parentId: this.props.parentId,
          importModalCloseOverride: this.returnToFeedback
        })
      );
    }
  }, {
    key: 'renderContent',
    value: function renderContent() {
      return _react2.default.createElement(
        'div',
        null,
        _react2.default.createElement(_RichContentRenderer2.default, {
          customStyles: styles.itemStem,
          content: this.props.item.itemBody
        }),
        this.renderRichContentInput('correct', 'Voor een juist antwoord'),
        this.renderRichContentInput('incorrect', 'Voor een onjuist antwoord'),
        this.renderRichContentInput('neutral', 'Geef algemene feedback (los van het antwoord)')
      );
    }
  }, {
    key: 'render',
    value: function render() {
      return _react2.default.createElement(
        'div',
        null,
        _react2.default.createElement(
          _Modal2.default,
          {
            open: this.props.modalOpen || this.props.importModalOpen,
            onDismiss: this.closeAction,
            size: 'large',
            label: 'Feedback van cursist',
            shouldCloseOnDocumentClick: false // must be false to allow interacting with RCE modals (such as embed media)
          },
          _react2.default.createElement(
            _Modal.ModalHeader,
            null,
            _react2.default.createElement(
              _Heading2.default,
              { level: 'reset', as: 'h2' },
              'Feedback van cursist'
            ),
            _react2.default.createElement(_CloseButton2.default, {
              onClick: this.closeAction,
              placement: 'end',
              offset: 'medium',
              variant: 'icon'
            })
          ),
          _react2.default.createElement(
            _Modal.ModalBody,
            null,
            this.renderContent()
          ),
          _react2.default.createElement(
            _Modal.ModalFooter,
            null,
            this.cancelButton(),
            this.doneButton()
          )
        )
      );
    }
  }]);
  ItemFeedbackModal.displayName = 'ItemFeedbackModal'
  ;
  return ItemFeedbackModal;
}(_react.Component), _class2.propTypes = {
  changeItemFeedback: _propTypes2.default.func.isRequired,
  closeModal: _propTypes2.default.func.isRequired,
  feedback: _reactImmutableProptypes2.default.map.isRequired,
  importModalOpen: _propTypes2.default.bool.isRequired,
  item: _reactImmutableProptypes2.default.record.isRequired,
  modalOpen: _propTypes2.default.bool.isRequired,
  openModal: _propTypes2.default.func.isRequired,
  parentId: _propTypes2.default.string.isRequired,
  parentType: _propTypes2.default.string.isRequired,
  setUi: _propTypes2.default.func.isRequired,
  modalTrigger: _propTypes2.default.element
}, _class2.defaultProps = {
  modalTrigger: null
}, _temp2)) || _class);
exports.default = ItemFeedbackModal;