'use strict';

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

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

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

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

var _RecordEditor = require('../../components/record/RecordEditor');

var _RecordEditor2 = _interopRequireDefault(_RecordEditor);

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

var mapStateToProps = function mapStateToProps(state, ownProps) {
  var csid = ownProps.csid;


  return {
    data: (0, _reducers.getRecordData)(state, csid),
    isModified: (0, _reducers.isRecordModified)(state, csid),
    isSavePending: (0, _reducers.isRecordSavePending)(state, csid)
  };
};

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


  return {
    onAddInstance: function onAddInstance(path) {
      var recordTypeConfig = config.recordTypes[recordType];

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

exports.default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(_RecordEditor2.default);