import { jsxs as t, jsx as e } from "@emotion/react/jsx-runtime";
import { Component as i } from "react";
import { reportMFIsolationRuntimeError as n } from "./runtimeErrors.js";
class m extends i {
  state = {
    hasError: !1
  };
  /**
   * Switch the isolation shell into its fallback state after a runtime render failure.
   */
  static getDerivedStateFromError(r) {
    return {
      error: r,
      hasError: !0
    };
  }
  /**
   * Forward the caught isolation runtime error to the registered app-owned handler, if any.
   */
  componentDidCatch(r, o) {
    n({
      moduleId: this.props.moduleId,
      error: r,
      componentStack: o.componentStack ?? void 0,
      runtimeMode: "isolation"
    });
  }
  /**
   * Render the wrapped isolation tree or a safe fallback after a caught crash.
   */
  render() {
    if (this.state.hasError) {
      const { error: r } = this.state;
      return /* @__PURE__ */ t("div", { role: "alert", "data-testid": "mf-isolation-runtime-error-fallback", children: [
        /* @__PURE__ */ e("p", { children: "This microfrontend could not be rendered in isolation." }),
        r ? /* @__PURE__ */ t("div", { children: [
          /* @__PURE__ */ t("p", { "data-testid": "mf-isolation-runtime-error-message", children: [
            r.name,
            ": ",
            r.message
          ] }),
          r.stack ? /* @__PURE__ */ e("pre", { "data-testid": "mf-isolation-runtime-error-stack", children: r.stack }) : null
        ] }) : null
      ] });
    }
    return this.props.children;
  }
}
export {
  m as MFIsolationAppErrorBoundary
};
