import { useEffect, createElement, Fragment } from "react";
import { ContainerSpinner, Message } from "@contember/ui";
import { useRedirect } from "../../../routing/binding/useRedirect.js";
function FeedbackRenderer({ accessorTreeState, children }) {
  const redirect = useRedirect();
  useEffect(() => {
    if (accessorTreeState.name === "error" && accessorTreeState.error.type === "unauthorized") {
      window.location.href = "/";
    }
  }, [accessorTreeState, redirect]);
  if (accessorTreeState.name === "initializing") {
    return /* @__PURE__ */ createElement(ContainerSpinner, null);
  }
  if (accessorTreeState.name === "error") {
    switch (accessorTreeState.error.type) {
      case "unauthorized":
        return null;
      case "networkError":
        return /* @__PURE__ */ createElement(Message, {
          intent: "danger"
        }, "Network error");
      case "gqlError":
        return /* @__PURE__ */ createElement(Message, {
          intent: "danger"
        }, "Unknown error");
      case "unknownError":
      default:
        return /* @__PURE__ */ createElement(Message, {
          intent: "danger"
        }, "Unknown error");
    }
  }
  return /* @__PURE__ */ createElement(Fragment, null, children);
}
export { FeedbackRenderer };
//# sourceMappingURL=FeedbackRenderer.js.map
