"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _element = require("@wordpress/element");
var _i18n = require("@wordpress/i18n");
var _hooks = require("@wordpress/hooks");
var _warning = _interopRequireDefault(require("./warning"));
var _jsxRuntime = require("react/jsx-runtime");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

class ErrorBoundary extends _element.Component {
  constructor() {
    super(...arguments);
    this.state = {
      error: null
    };
  }
  componentDidCatch(error) {
    (0, _hooks.doAction)('editor.ErrorBoundary.errorLogged', error);
  }
  static getDerivedStateFromError(error) {
    return {
      error
    };
  }
  render() {
    if (!this.state.error) {
      return this.props.children;
    }
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_warning.default, {
      message: (0, _i18n.__)('The editor has encountered an unexpected error.'),
      error: this.state.error
    });
  }
}
exports.default = ErrorBoundary;
//# sourceMappingURL=index.js.map