'use strict';

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

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 _get = require('lodash/get');

var _get2 = _interopRequireDefault(_get);

var _Notification = require('./Notification');

var _Notification2 = _interopRequireDefault(_Notification);

var _ValidationErrorMessage = require('./ValidationErrorMessage');

var _ValidationErrorMessage2 = _interopRequireDefault(_ValidationErrorMessage);

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

const propTypes = {
  errors: _propTypes2.default.instanceOf(_immutable2.default.Map),
  recordType: _propTypes2.default.string
};

const contextTypes = {
  config: _propTypes2.default.object
};

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


  if (!errors) {
    return null;
  }

  const config = context.config;


  const fieldDescriptor = (0, _get2.default)(config, ['recordTypes', recordType, 'fields']);

  return _react2.default.createElement(
    _Notification2.default,
    props,
    _react2.default.createElement(_ValidationErrorMessage2.default, { errors: errors, fieldDescriptor: fieldDescriptor })
  );
}

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