"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = Subrecord;
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _get = _interopRequireDefault(require("lodash/get"));
var _warning = _interopRequireDefault(require("warning"));
var _SubrecordEditorContainer = _interopRequireDefault(require("../../containers/record/SubrecordEditorContainer"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const propTypes = {
  name: _propTypes.default.string,
  showDetachButton: _propTypes.default.bool,
  template: _propTypes.default.string
};
const contextTypes = {
  config: _propTypes.default.shape({
    recordTypes: _propTypes.default.object
  }),
  csid: _propTypes.default.string,
  recordType: _propTypes.default.string,
  readOnly: _propTypes.default.bool
};
function Subrecord(props, context) {
  const {
    config,
    csid,
    recordType,
    readOnly
  } = context;
  const {
    name,
    template,
    showDetachButton
  } = props;
  const subrecordConfig = (0, _get.default)(config, ['recordTypes', recordType, 'subrecords', name]);
  process.env.NODE_ENV !== "production" ? (0, _warning.default)(subrecordConfig, `No subrecord is configured with name ${name} for the record type ${recordType}.`) : void 0;
  if (!subrecordConfig) {
    return null;
  }
  return /*#__PURE__*/_react.default.createElement(_SubrecordEditorContainer.default, {
    containerCsid: csid,
    name: name,
    config: config,
    subrecordConfig: subrecordConfig,
    formName: template,
    showDetachButton: showDetachButton,
    readOnly: readOnly
  });
}
Subrecord.propTypes = propTypes;
Subrecord.contextTypes = contextTypes;