'use strict';

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

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

var _reactRouter = require('react-router');

var _RecordButtonBar = require('../../components/record/RecordButtonBar');

var _RecordButtonBar2 = _interopRequireDefault(_RecordButtonBar);

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

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

var mapDispatchToProps = function mapDispatchToProps(dispatch, ownProps) {
  var csid = ownProps.csid,
      recordTypeConfig = ownProps.recordTypeConfig,
      vocabularyConfig = ownProps.vocabularyConfig,
      router = ownProps.router;


  return {
    clone: function clone() {
      var vocabPath = vocabularyConfig ? '/' + vocabularyConfig.name : '';

      router.push({
        pathname: '/record/' + recordTypeConfig.name + vocabPath,
        query: {
          clone: csid
        }
      });
    },
    revert: function revert() {
      dispatch((0, _record.revertRecord)(csid));
    },
    save: function save() {
      dispatch((0, _record.saveRecord)(recordTypeConfig, vocabularyConfig, csid, router.replace));
    }
  };
};

var ConnectedRecordButtonBar = exports.ConnectedRecordButtonBar = (0, _reactRedux.connect)(null, mapDispatchToProps)(_RecordButtonBar2.default);

exports.default = (0, _reactRouter.withRouter)(ConnectedRecordButtonBar);