"use strict";

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

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _immutable = _interopRequireDefault(require("immutable"));

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

var _Notification = _interopRequireDefault(require("./Notification"));

var _ValidationErrorMessage = _interopRequireDefault(require("./ValidationErrorMessage"));

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

const propTypes = {
  errors: _propTypes.default.instanceOf(_immutable.default.Map),
  recordType: _propTypes.default.string
};
const contextTypes = {
  config: _propTypes.default.object
};

function ValidationErrorNotification(props, context) {
  const {
    errors,
    recordType
  } = props;

  if (!errors) {
    return null;
  }

  const {
    config
  } = context;
  const recordTypeConfig = (0, _get.default)(config, ['recordTypes', recordType]) || (0, _get.default)(config, ['invocables', 'report', recordType]) || (0, _get.default)(config, ['invocables', 'batch', recordType]);
  const fieldDescriptor = (0, _get.default)(recordTypeConfig, 'fields');
  return _react.default.createElement(_Notification.default, props, _react.default.createElement(_ValidationErrorMessage.default, {
    errors: errors,
    fieldDescriptor: fieldDescriptor
  }));
}

ValidationErrorNotification.propTypes = propTypes;
ValidationErrorNotification.contextTypes = contextTypes;