"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _errorBoundaryBody = _interopRequireDefault(require("./error-boundary-body"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
/**
 * ErrorBoundary is a class component that should wrap Suspense tags to catch errors thrown.
 * It is a simple class component that implements the componentDidCatch and
 * static getDerivedStateFromError methods, and renders a fallback when it encounters an error.
 */
class ErrorBoundary extends _react.Component {
  constructor(props) {
    super(props);
    this.state = {
      hasError: false
    };
  }
  static getDerivedStateFromError() {
    return {
      hasError: true
    };
  }
  componentDidCatch(error, errorInfo) {
    const {
      onCatch
    } = this.props;
    if (onCatch) {
      onCatch(error, errorInfo);
    }
  }
  render() {
    if (this.state.hasError) {
      const {
        fallback
      } = this.props;
      if (fallback) {
        return fallback;
      }
      return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: "error-boundary-message-container",
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_errorBoundaryBody.default, {
          defaultFallbackText: this.props.defaultFallbackText
        })
      });
    }
    return this.props.children;
  }
}
exports.default = ErrorBoundary;