'use strict';

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

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);

exports.default = function (schema) {
  return function (_BaseRecord) {
    (0, _inherits3.default)(ReduxRecord, _BaseRecord);

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

    (0, _createClass3.default)(ReduxRecord, [{
      key: 'stateHelper',

      // =====================
      // =====================
      // REDUX & RELATIONSHIPS
      // =====================
      // =====================

      value: function stateHelper() {
        return _stateHelper3.default;
      }
    }, {
      key: 'getState',
      value: function getState() {
        return _reduxStore2.default.getAppState();
      }
    }, {
      key: 'getRelationList',
      value: function getRelationList(relationName, relatedItemFinder) {
        return this[relationName].reduce(function (relatedItemsFromState, id) {
          var currChoice = _stateHelper3.default[relatedItemFinder](id);
          if (currChoice) {
            return relatedItemsFromState.push(currChoice);
          }
          return relatedItemsFromState;
        }, (0, _immutable.List)());
      }
    }]);
    return ReduxRecord;
  }((0, _baseRecord2.default)(schema));
};

var _immutable = require('immutable');

var _baseRecord = require('./baseRecord');

var _baseRecord2 = _interopRequireDefault(_baseRecord);

var _reduxStore = require('../../reduxStore');

var _reduxStore2 = _interopRequireDefault(_reduxStore);

var _stateHelper2 = require('../util/stateHelper');

var _stateHelper3 = _interopRequireDefault(_stateHelper2);

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