"use strict";

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

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

var _messageBox = require("../design-system/molecules/message-box");

var _designSystem = require("../design-system");

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

class ErrorBoundary extends _react.default.Component {
  constructor(props) {
    super(props);
    this.state = {
      error: null
    };
  }

  componentDidCatch(error) {
    this.setState({
      error
    });
  }

  render() {
    const {
      children
    } = this.props;
    const {
      error
    } = this.state;

    if (error !== null) {
      return _react.default.createElement(_messageBox.MessageBox, {
        m: "xxl",
        variant: "danger",
        message: "Javascript Error"
      }, _react.default.createElement(_designSystem.Text, null, error.toString()), _react.default.createElement(_designSystem.Text, {
        mt: "default"
      }, "See development console for more details..."));
    }

    return children || null;
  }

}

var _default = ErrorBoundary;
exports.default = _default;