import { createElement } from "react";
import * as ReactDOM from "react-dom";
const getErrorContainer = () => {
  const errorElementId = "__contember__dev__error__container__element";
  let errorContainer = document.getElementById(errorElementId);
  if (errorContainer) {
    ReactDOM.unmountComponentAtNode(errorContainer);
  } else {
    errorContainer = document.createElement("div");
    errorContainer.id = errorElementId;
    document.body.appendChild(errorContainer);
  }
  return errorContainer;
};
const prodErrorHandler = () => {
  const renderError = () => {
    ReactDOM.render(/* @__PURE__ */ createElement("h1", null, "Fatal error"), getErrorContainer());
  };
  window.addEventListener("error", renderError);
  window.addEventListener("unhandledrejection", renderError);
  return async (cb) => {
    try {
      await cb();
    } catch (e) {
      console.error(e);
      renderError();
    }
  };
};
const createErrorHandler = () => {
  {
    return prodErrorHandler();
  }
};
export { createErrorHandler };
//# sourceMappingURL=errorHandling.js.map
