import { jsx } from "react/jsx-runtime";
import React from "react";
import {
  DefaultErrorTemplate
} from "./default-error-template.js";
import { getLogger } from "../../utils/micro-frontend/index.js";
import { logRecords } from "../../utils/log-records.js";
class ErrorBoundary extends React.Component {
  constructor(props) {
    super(props);
    this.state = { error: null, errorInfo: null };
  }
  componentDidCatch(error, errorInfo) {
    this.setState({
      error,
      errorInfo
    });
    const logger = getLogger();
    if (logger)
      logger.error({
        ...logRecords.UNHANDLED_ERROR,
        exception: error,
        message: error.message
      });
  }
  render() {
    const { children, errorTemplate } = this.props;
    const ErrorTemplate = errorTemplate || DefaultErrorTemplate;
    const { error, errorInfo } = this.state;
    return errorInfo ? /* @__PURE__ */ jsx(ErrorTemplate, { error, errorInfo }) : children;
  }
}
export {
  ErrorBoundary
};
