'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 _class, _temp2;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _platform = require('platform');

var platform = _interopRequireWildcard(_platform);

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

var _reactImmutableProptypes2 = _interopRequireDefault(_reactImmutableProptypes);

var _first = require('lodash/first');

var _first2 = _interopRequireDefault(_first);

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 _formatMessage = require('../../../common/format-message');

var _formatMessage2 = _interopRequireDefault(_formatMessage);

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

var _InteractionTypes = require('../../../common/components/shared/InteractionTypes');

var _InteractionTypes2 = _interopRequireDefault(_InteractionTypes);

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

var _Modal2 = _interopRequireDefault(_Modal);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

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

var AddBankEntryModal = (_temp2 = _class = function (_Component) {
  (0, _inherits3.default)(AddBankEntryModal, _Component);

  function AddBankEntryModal() {
    var _ref;

    var _temp, _this, _ret;

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

    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 = AddBankEntryModal.__proto__ || Object.getPrototypeOf(AddBankEntryModal)).call.apply(_ref, [this].concat(args))), _this), _this.addItem = function (interactionTypeData) {
      var defaultInteractionData = interactionTypeData.getDefaultInteractionData();
      var scoringData = interactionTypeData.getDefaultScoringData(defaultInteractionData);
      var itemProps = {
        id: interactionTypeData.id,
        interactionData: defaultInteractionData,
        itemBody: interactionTypeData.itemBody,
        properties: interactionTypeData.defaultProperties,
        scoringAlgorithm: (0, _first2.default)(interactionTypeData.scoringAlgorithmOptions),
        scoringData: scoringData,
        userResponseType: (0, _first2.default)(interactionTypeData.userResponseTypeOptions)
      };
      _this.props.createBankItem(_this.props.bankId, 'Item', itemProps);
      _this.closeAction();
      _this.props.navigateToBankEntry('new', _this.props.bankId);
    }, _this.addStimulus = function () {
      _this.props.createBankItem(_this.props.bankId, 'Stimulus');
      _this.closeAction();
      _this.props.navigateToBankEntry('new', _this.props.bankId);
    }, _this.closeAction = function () {
      if (_this.props.modalTrigger) {
        _this.props.modalTrigger.focus();
      }
      _this.props.closeModal();
    }, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret);
  }

  (0, _createClass3.default)(AddBankEntryModal, [{
    key: 'componentDidMount',
    value: function componentDidMount() {
      this.props.getInteractionTypes();
    }
  }, {
    key: 'cancelButton',
    value: function cancelButton() {
      return _react2.default.createElement(
        _Button2.default,
        { onClick: this.closeAction, margin: _constants.XSMALL_SIDE_MARGIN },
        '\u0625\u063A\u0644\u0627\u0642'
      );
    }
  }, {
    key: 'render',
    value: function render() {
      // For some reason, there's obscure behavior on IE11 that makes Modal size='auto'
      // behave poorly with instui Grid; see https://instructure.atlassian.net/browse/QUIZ-4100.
      // This is just a simple workaround.
      var size = platform.name === 'IE' && platform.version === '11.0' ? 'medium' : 'auto';

      return _react2.default.createElement(
        _Modal2.default,
        {
          open: this.props.modalOpen,
          onDismiss: this.closeAction,
          size: size,
          label: '\u0639\u0646\u0635\u0631 \u062C\u062F\u064A\u062F'
        },
        _react2.default.createElement(
          _Modal.ModalHeader,
          null,
          _react2.default.createElement(
            _Heading2.default,
            { level: 'reset', as: 'h2' },
            '\u0639\u0646\u0635\u0631 \u062C\u062F\u064A\u062F'
          ),
          _react2.default.createElement(_CloseButton2.default, {
            onClick: this.closeAction,
            placement: 'end',
            offset: 'medium',
            variant: 'icon'
          })
        ),
        _react2.default.createElement(
          _Modal.ModalBody,
          null,
          _react2.default.createElement(_InteractionTypes2.default, {
            columns: 3,
            addItem: this.addItem,
            addStimulus: this.addStimulus,
            allowStimulusCreation: this.props.stimulusBankingOn,
            types: this.props.interactionTypes
          })
        ),
        _react2.default.createElement(
          _Modal.ModalFooter,
          null,
          this.cancelButton()
        )
      );
    }
  }]);
  AddBankEntryModal.displayName = 'AddBankEntryModal'
  ;
  return AddBankEntryModal;
}(_react.Component), _class.propTypes = {
  modalOpen: _propTypes2.default.bool.isRequired,
  closeModal: _propTypes2.default.func.isRequired,
  modalTrigger: _propTypes2.default.instanceOf(Element),
  createBankItem: _propTypes2.default.func.isRequired,
  navigateToBankEntry: _propTypes2.default.func.isRequired,
  bankId: _propTypes2.default.string.isRequired,
  getInteractionTypes: _propTypes2.default.func.isRequired,
  interactionTypes: _reactImmutableProptypes2.default.list.isRequired,
  stimulusBankingOn: _propTypes2.default.bool.isRequired
}, _class.defaultProps = {
  modalTrigger: null
}, _temp2);
exports.default = AddBankEntryModal;