"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

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

var _get = _interopRequireDefault(require("lodash/get"));

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

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

var _InvocationEditor = _interopRequireDefault(require("../../components/invocable/InvocationEditor"));

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

const mapStateToProps = state => ({
  paramData: (0, _reducers.getRecordData)(state, '')
});

const mapDispatchToProps = (dispatch, ownProps) => {
  const {
    config,
    metadata,
    recordType
  } = ownProps;
  return {
    createNewRecord: () => {
      const invocableNameGetter = (0, _get.default)(config, ['recordTypes', recordType, 'invocableName']);
      const invocableName = invocableNameGetter && invocableNameGetter(metadata);
      const paramRecordTypeConfig = invocableName ? (0, _get.default)(config, ['invocables', recordType, invocableName]) : undefined;

      if (paramRecordTypeConfig) {
        return dispatch((0, _record.createNewRecord)(config, paramRecordTypeConfig));
      }

      return undefined;
    }
  };
};

var _default = (0, _reactRedux.connect)(mapStateToProps, mapDispatchToProps)(_InvocationEditor.default);

exports.default = _default;