'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 _immutable = require('immutable');

var _reduxRecord = require('./reduxRecord');

var _reduxRecord2 = _interopRequireDefault(_reduxRecord);

var _Item2 = require('./Item');

var _Item3 = _interopRequireDefault(_Item2);

var _Stimulus2 = require('./Stimulus');

var _Stimulus3 = _interopRequireDefault(_Stimulus2);

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

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

var BankEntry = function (_ReduxRecord) {
  (0, _inherits3.default)(BankEntry, _ReduxRecord);

  function BankEntry() {
    (0, _classCallCheck3.default)(this, BankEntry);
    return (0, _possibleConstructorReturn3.default)(this, (BankEntry.__proto__ || Object.getPrototypeOf(BankEntry)).apply(this, arguments));
  }

  (0, _createClass3.default)(BankEntry, [{
    key: 'getEntry',
    value: function getEntry() {
      var _this2 = this;

      if (this.entry === _constants.TEMPORARY_ITEM_ID) {
        return _Item3.default.create(this.getState().getIn(['modifications', 'items', _constants.TEMPORARY_ITEM_ID]));
      }
      if (this.entry === _constants.TEMPORARY_STIMULUS_ID) {
        return _Stimulus3.default.create(this.getState().getIn(['modifications', 'stimuli', _constants.TEMPORARY_STIMULUS_ID]));
      }

      var entryCreator = {
        Item: function Item() {
          return _Item3.default.create(_this2.getState().getIn(['items', _this2.entry.get('id')]));
        },
        Stimulus: function Stimulus() {
          return _Stimulus3.default.create(_this2.getState().getIn(['stimuli', _this2.entry.get('id')]));
        }
      }[this.entryType];
      if (entryCreator) return entryCreator();
    }
  }, {
    key: 'getNestedEntries',
    value: function getNestedEntries() {
      var entry = this.getEntry();
      var getNestedEntriesFunction = {
        Item: function Item() {
          return [entry];
        }
      }[this.entryType];
      if (getNestedEntriesFunction) return getNestedEntriesFunction();
    }
  }, {
    key: 'getWorkingInstance',
    value: function getWorkingInstance() {
      return this.merge(this.getState().getIn(['modifications', 'bankEntries', this.id]));
    }
  }, {
    key: 'isStimulus',
    get: function get() {
      return this.entryType === 'Stimulus';
    }
  }]);
  return BankEntry;
}((0, _reduxRecord2.default)({
  id: '0',
  entry: (0, _immutable.Map)(),
  bankId: '0',
  archived: false,
  entryType: null,
  createdAt: null,
  updatedAt: null
}));

exports.default = BankEntry;