'use strict';

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

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

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

var _get2 = _interopRequireDefault(_get);

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

var _RecordForm = require('../../components/record/RecordForm');

var _RecordForm2 = _interopRequireDefault(_RecordForm);

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

var mapDispatchToProps = function mapDispatchToProps(dispatch, ownProps) {
  var config = ownProps.config,
      csid = ownProps.csid,
      recordType = ownProps.recordType;


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

  return {
    onAddInstance: function onAddInstance(path, position) {
      dispatch((0, _record.addFieldInstance)(recordTypeConfig, csid, path, position));
    },
    onCommit: function onCommit(path, value) {
      dispatch((0, _record.setFieldValue)(recordTypeConfig, csid, path, value));
    },
    onMoveInstance: function onMoveInstance(path, newPosition) {
      dispatch((0, _record.moveFieldValue)(recordTypeConfig, csid, path, newPosition));
    },
    onRemoveInstance: function onRemoveInstance(path) {
      dispatch((0, _record.deleteFieldValue)(recordTypeConfig, csid, path));
    },
    onSortInstances: function onSortInstances(path, byField) {
      dispatch((0, _record.sortFieldInstances)(recordTypeConfig, csid, path, byField));
    }
  };
};

exports.default = (0, _reactRedux.connect)(undefined, mapDispatchToProps)(_RecordForm2.default);