"use strict";

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

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 _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

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

var _immutable = require("immutable");

var _reduxRecord = _interopRequireDefault(require("./reduxRecord"));

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

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

var _instructureValidations = require("instructure-validations");

var _validationHelpers = require("quiz-interactions/lib/util/validationHelpers");

var Stimulus =
/*#__PURE__*/
function (_ReduxRecord) {
  (0, _inherits2.default)(Stimulus, _ReduxRecord);

  function Stimulus() {
    (0, _classCallCheck2.default)(this, Stimulus);
    return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Stimulus).apply(this, arguments));
  }

  (0, _createClass2.default)(Stimulus, [{
    key: "isLoaded",
    value: function isLoaded() {
      return this.id !== '0';
    }
  }, {
    key: "isTemporary",
    value: function isTemporary() {
      return this.id === _constants.TEMPORARY_STIMULUS_ID;
    }
  }, {
    key: "hasModifications",
    value: function hasModifications() {
      return !(0, _immutable.is)(this.getWorkingInstance(), this);
    }
  }, {
    key: "getWorkingInstance",
    value: function getWorkingInstance() {
      // The record created by .merge() somehow bypasses calling the constructor where
      // methods created by the `() => {` pattern get created/set. So we feed the result
      // through the constructor manually.
      return Stimulus.create(this.merge(this.getState().getIn(['modifications', 'stimuli', this.id])));
    }
  }, {
    key: "isImmutable",
    value: function isImmutable() {
      return this.status === 'immutable';
    }
  }, {
    key: "isStimulus",
    get: function get() {
      return true;
    }
  }]);
  return Stimulus;
}((0, _reduxRecord.default)({
  id: '0',
  stimulusType: 'text',
  title: '',
  instructions: '',
  body: '',
  sourceUrl: '',
  status: 'mutable'
}));

exports.default = Stimulus;
Stimulus.validations = {
  title: [(0, _instructureValidations.rule)('presence', {
    message: (0, _validationHelpers.presenceMessage)("Tytu\u0142")
  })],
  body: [(0, _instructureValidations.rule)('presence', {
    message: (0, _validationHelpers.presenceMessage)("Zawarto\u015B\u0107")
  })],
  onSelf: [(0, _instructureValidations.rule)('maxContent')]
};