"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.ConnectedMiniView = void 0;
var _reactRedux = require("react-redux");
var _reactIntl = require("react-intl");
var _get = _interopRequireDefault(require("lodash/get"));
var _MiniView = _interopRequireDefault(require("../../components/record/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;
  const data = (0, _reducers.getRecordData)(state, csid);
  return {
    data
  };
};
const mapDispatchToProps = (dispatch, ownProps) => {
  const {
    config,
    csid,
    recordType,
    vocabulary
  } = ownProps;
  const recordTypeConfig = (0, _get.default)(config, ['recordTypes', recordType]);
  const vocabularyConfig = vocabulary ? (0, _get.default)(recordTypeConfig, ['vocabularies', vocabulary]) : undefined;
  return {
    readRecord: () => {
      dispatch((0, _record.readRecord)(config, recordTypeConfig, vocabularyConfig, csid));
    }
  };
};
const ConnectedMiniView = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(_MiniView.default);
exports.ConnectedMiniView = ConnectedMiniView;
const InitializedConnectedMiniView = (0, _reactIntl.injectIntl)(ConnectedMiniView);
var _default = InitializedConnectedMiniView;
exports.default = _default;