import React, { Component } from 'react';
import ErrorBoundaryBody from './error-boundary-body';
import { jsx as _jsx } from "react/jsx-runtime";
/**
 * 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.
 */
export default class ErrorBoundary extends 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__*/_jsx("div", {
        className: "error-boundary-message-container",
        children: /*#__PURE__*/_jsx(ErrorBoundaryBody, {
          defaultFallbackText: this.props.defaultFallbackText
        })
      });
    }
    return this.props.children;
  }
}