'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _immutable = require('immutable');

var _immutable2 = _interopRequireDefault(_immutable);

var _reactIntl = require('react-intl');

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

var _get2 = _interopRequireDefault(_get);

var _invocationHelpers = require('../../helpers/invocationHelpers');

var _RecordFormContainer = require('../../containers/record/RecordFormContainer');

var _RecordFormContainer2 = _interopRequireDefault(_RecordFormContainer);

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

const propTypes = {
  config: _propTypes2.default.object,
  data: _propTypes2.default.instanceOf(_immutable2.default.Map),
  invocationItem: _propTypes2.default.instanceOf(_immutable2.default.Map),
  promptMessage: _propTypes2.default.object,
  type: _propTypes2.default.string,
  createNewRecord: _propTypes2.default.func
};

class InvocationEditor extends _react.Component {
  componentDidMount() {
    this.initRecord();
  }

  initRecord() {
    const createNewRecord = this.props.createNewRecord;


    createNewRecord();
  }

  render() {
    var _props = this.props;
    const config = _props.config,
          data = _props.data,
          invocationItem = _props.invocationItem,
          promptMessage = _props.promptMessage,
          type = _props.type;


    const invocableName = type === 'report' ? (0, _invocationHelpers.getReportName)(invocationItem) : (0, _invocationHelpers.getBatchName)(invocationItem);

    const recordTypeConfig = (0, _get2.default)(config, ['invocables', type, invocableName]);

    if (!recordTypeConfig) {
      return _react2.default.createElement(_reactIntl.FormattedMessage, promptMessage);
    }

    return _react2.default.createElement(
      'div',
      null,
      _react2.default.createElement(_RecordFormContainer2.default, {
        config: config,
        csid: '',
        data: data,
        recordTypeConfig: recordTypeConfig,
        recordType: 'invocable'
      })
    );
  }
}

exports.default = InvocationEditor;
InvocationEditor.propTypes = propTypes;