"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const ReactDOM = require("react-dom");
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 prodErrorHandler = (renderer) => {
  const renderError = () => {
    renderer(getErrorContainer(), /* @__PURE__ */ jsxRuntime.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);
  }
};
exports.createErrorHandler = createErrorHandler;
//# sourceMappingURL=errorHandling.cjs.map
