'use strict';

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

var _reactRedux = require('react-redux');

var _reactIntl = require('react-intl');

var _get = require('lodash/get');

var _get2 = _interopRequireDefault(_get);

var _MiniView = require('../../components/record/MiniView');

var _MiniView2 = _interopRequireDefault(_MiniView);

var _reducers = require('../../reducers');

var _record = require('../../actions/record');

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

const mapStateToProps = (state, ownProps) => {
  const csid = ownProps.csid;


  const data = (0, _reducers.getRecordData)(state, csid);

  return {
    data
  };
};

const mapDispatchToProps = (dispatch, ownProps) => {
  const config = ownProps.config,
        csid = ownProps.csid,
        recordType = ownProps.recordType,
        vocabulary = ownProps.vocabulary;


  const recordTypeConfig = (0, _get2.default)(config, ['recordTypes', recordType]);

  const vocabularyConfig = vocabulary ? (0, _get2.default)(recordTypeConfig, ['vocabularies', vocabulary]) : undefined;

  return {
    readRecord: () => {
      dispatch((0, _record.readRecord)(config, recordTypeConfig, vocabularyConfig, csid));
    }
  };
};

const ConnectedMiniView = exports.ConnectedMiniView = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(_MiniView2.default);

const InitializedConnectedMiniView = (0, _reactIntl.injectIntl)(ConnectedMiniView);

exports.default = InitializedConnectedMiniView;