import { jsx } from "react/jsx-runtime";
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 = (renderer) => {
  const renderError = () => {
    renderer(getErrorContainer(), /* @__PURE__ */ jsx("h1", { children: "Fatal error" }), () => {
    });
  };
  window.addEventListener("error", renderError);
  window.addEventListener("unhandledrejection", renderError);
  return async (cb) => {
    try {
      await cb((e) => {
        console.warn(e);
      });
    } catch (e) {
      console.error(e);
      renderError();
    }
  };
};
const createErrorHandler = (renderer) => {
  {
    return prodErrorHandler(renderer);
  }
};
export {
  createErrorHandler
};
//# sourceMappingURL=errorHandling.js.map
