"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf3 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _react = _interopRequireWildcard(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _reactImmutableProptypes = _interopRequireDefault(require("react-immutable-proptypes"));

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

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

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

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

var _RichContentRenderer = _interopRequireDefault(require("@instructure/quiz-rce/lib/components/RichContentRenderer"));

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

var _formatMessage = _interopRequireDefault(require("@instructure/quiz-i18n/lib/format-message"));

var _Modal = _interopRequireWildcard(require("@instructure/quiz-common/lib/components/Modal"));

var _theme = _interopRequireDefault(require("./theme"));

var _constants = require("@instructure/quiz-common/lib/constants");

var _dec, _class, _class2, _temp;

var styles = {
  componentId: 'esPWW',
  template: function template(theme) {
    return "\n\n.esPWW_hRNi{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}\n\n.esPWW_eCKf{font-size:".concat(theme.feedbackLabelFontSize || 'inherit', "}");
  },
  'itemStem': 'esPWW_hRNi',
  'feedbackLabel': 'esPWW_eCKf'
};

var _ref2 =
/*#__PURE__*/
_react.default.createElement("br", null);

var ItemFeedbackModal = (_dec = (0, _lib.default)(_theme.default, styles), _dec(_class = (_temp = _class2 =
/*#__PURE__*/
function (_Component) {
  (0, _inherits2.default)(ItemFeedbackModal, _Component);

  function ItemFeedbackModal() {
    var _getPrototypeOf2;

    var _this;

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

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

    _this = (0, _possibleConstructorReturn2.default)(this, (_getPrototypeOf2 = (0, _getPrototypeOf3.default)(ItemFeedbackModal)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _this.onFeedbackChange = function (e, _ref) {
      var editorContent = _ref.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.props.modalTrigger && _this.props.modalTrigger.focus();

      _this.props.closeModal();
    };

    _this.returnToFeedback = function () {
      _this.props.openModal(_constants.ITEM_FEEDBACK_MODAL, {
        modalTrigger: _this.props.modalTrigger
      });
    };

    return _this;
  }

  (0, _createClass2.default)(ItemFeedbackModal, [{
    key: "cancelButton",
    value: function cancelButton() {
      return _react.default.createElement(_Button.default, {
        onClick: this.closeAction,
        margin: _constants.XSMALL_SIDE_MARGIN
      }, "\u0625\u0644\u063A\u0627\u0621");
    }
  }, {
    key: "doneButton",
    value: function doneButton() {
      return _react.default.createElement(_Button.default, {
        variant: "primary",
        onClick: this.continueAction,
        margin: _constants.XSMALL_SIDE_MARGIN
      }, "\u062A\u0645");
    }
  }, {
    key: "renderRichContentInput",
    value: function renderRichContentInput(key, label) {
      return _react.default.createElement("div", null, _ref2, _react.default.createElement("label", {
        className: styles.feedbackLabel,
        htmlFor: key
      }, label), _react.default.createElement(_RichContentInput.default, {
        label: "",
        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 _react.default.createElement("div", null, _react.default.createElement(_RichContentRenderer.default, {
        customStyles: styles.itemStem,
        content: this.props.item.itemBody
      }), this.renderRichContentInput('correct', "\u0644\u0625\u062C\u0627\u0628\u0629 \u0635\u062D\u064A\u062D\u0629"), this.renderRichContentInput('incorrect', "\u0644\u0625\u062C\u0627\u0628\u0629 \u062E\u0627\u0637\u0626\u0629"), this.renderRichContentInput('neutral', "\u062A\u0648\u0641\u064A\u0631 \u0645\u0644\u0627\u062D\u0638\u0627\u062A \u0639\u0627\u0645\u0629 (\u0628\u063A\u0636 \u0627\u0644\u0646\u0638\u0631 \u0639\u0646 \u0627\u0644\u0625\u062C\u0627\u0628\u0629)"));
    }
  }, {
    key: "render",
    value: function render() {
      return _react.default.createElement("div", null, _react.default.createElement(_Modal.default, {
        open: this.props.modalOpen || this.props.importModalOpen,
        onClose: this.closeAction,
        size: "large",
        label: "\u0645\u0644\u0627\u062D\u0638\u0627\u062A \u0627\u0644\u0637\u0627\u0644\u0628",
        shouldCloseOnDocumentClick: false // must be false to allow interacting with RCE modals (such as embed media)
        ,
        shouldReturnFocus: false
      }, _react.default.createElement(_Modal.ModalHeader, null, _react.default.createElement(_Heading.default, {
        level: "reset",
        as: "h2"
      }, "\u0645\u0644\u0627\u062D\u0638\u0627\u062A \u0627\u0644\u0637\u0627\u0644\u0628"), _react.default.createElement(_CloseButton.default, {
        onClick: this.closeAction,
        placement: "end",
        offset: "medium",
        variant: "icon"
      }, "\u0625\u063A\u0644\u0627\u0642")), _react.default.createElement(_Modal.ModalBody, null, this.renderContent()), _react.default.createElement(_Modal.ModalFooter, null, this.cancelButton(), this.doneButton())));
    }
  }]);
  ItemFeedbackModal.displayName = "ItemFeedbackModal";
  return ItemFeedbackModal;
}(_react.Component), _class2.propTypes = {
  changeItemFeedback: _propTypes.default.func.isRequired,
  closeModal: _propTypes.default.func.isRequired,
  feedback: _reactImmutableProptypes.default.map.isRequired,
  importModalOpen: _propTypes.default.bool.isRequired,
  item: _reactImmutableProptypes.default.record.isRequired,
  modalOpen: _propTypes.default.bool.isRequired,
  openModal: _propTypes.default.func.isRequired,
  parentId: _propTypes.default.string.isRequired,
  parentType: _propTypes.default.string.isRequired,
  setUi: _propTypes.default.func.isRequired,
  modalTrigger: _propTypes.default.instanceOf(_react.Component)
}, _class2.defaultProps = {
  modalTrigger: null
}, _temp)) || _class);
exports.default = ItemFeedbackModal;