"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxDevRuntime = require("react/jsx-dev-runtime");
const ReactDOM = require("react-dom");
const buffer = require("buffer");
const DevErrorManager = require("../components/Dev/DevErrorManager.cjs");
function _interopNamespaceDefault(e) {
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
  if (e) {
    for (const k in e) {
      if (k !== "default") {
        const d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: () => e[k]
        });
      }
    }
  }
  n.default = e;
  return Object.freeze(n);
}
const ReactDOM__namespace = /* @__PURE__ */ _interopNamespaceDefault(ReactDOM);
const getErrorContainer = () => {
  const errorElementId = "__contember__dev__error__container__element";
  let errorContainer = document.getElementById(errorElementId);
  if (errorContainer) {
    ReactDOM__namespace.unmountComponentAtNode(errorContainer);
  } else {
    errorContainer = document.createElement("div");
    errorContainer.id = errorElementId;
    document.body.appendChild(errorContainer);
  }
  return errorContainer;
};
const devErrorHandler = (renderer) => {
  const errorBus = new DevErrorManager.ErrorBus();
  window.Buffer = buffer.Buffer;
  window.addEventListener("error", (e) => {
    if (e.message.startsWith("ResizeObserver")) {
      return;
    }
    errorBus.handleError("Unhandled error", e.error);
  });
  window.addEventListener("unhandledrejection", (e) => errorBus.handleError("Unhandled promise rejection", e.reason));
  const origOnError = console.error;
  console.error = (...args) => {
    origOnError(...args);
    for (const arg of args) {
      if (arg instanceof Error) {
        errorBus.handleError("Logged error", arg);
      }
    }
  };
  renderer(getErrorContainer(), /* @__PURE__ */ jsxDevRuntime.jsxDEV(DevErrorManager.DevErrorManager, { bus: errorBus }, void 0, false, {
    fileName: "/__w/interface/interface/packages/admin/src/bootstrap/errorHandling.tsx",
    lineNumber: 46,
    columnNumber: 32
  }, void 0), () => {
  });
  return async (cb) => {
    try {
      await cb((e) => errorBus.handleError("Recoverable React error", e));
    } catch (e) {
      errorBus.handleError("Entrypoint crash", e);
    }
  };
};
const createErrorHandler = (renderer) => {
  {
    return devErrorHandler(renderer);
  }
};
exports.createErrorHandler = createErrorHandler;
//# sourceMappingURL=errorHandling.cjs.map
