import { jsxDEV } from "react/jsx-dev-runtime";
import { Message, SpinnerOverlay } from "@contember/ui";
import { useEffect } from "react";
import { MiscPageLayout } from "../MiscPageLayout.js";
import { InvalidIdentityFallback } from "./InvalidIdentityFallback.js";
import { IdentityProvider as IdentityProvider$1, IdentityState } from "@contember/react-identity";
const ClearIdentityHandler = ({ onInvalidIdentity }) => {
  useEffect(() => {
    if (onInvalidIdentity) {
      onInvalidIdentity();
    } else if (window.location.pathname !== "/") {
      window.location.href = "/";
    }
  }, [onInvalidIdentity]);
  return null;
};
const IdentityProvider = ({ children, onInvalidIdentity, allowUnauthenticated }) => {
  return /* @__PURE__ */ jsxDEV(IdentityProvider$1, { children: [
    /* @__PURE__ */ jsxDEV(IdentityState, { state: "cleared", children: [
      /* @__PURE__ */ jsxDEV(ClearIdentityHandler, { onInvalidIdentity }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/components/Identity/IdentityProvider.tsx",
        lineNumber: 32,
        columnNumber: 5
      }, void 0),
      /* @__PURE__ */ jsxDEV(MiscPageLayout, { children: /* @__PURE__ */ jsxDEV(Message, { size: "large", padding: "large", display: "block", children: "Logging out…" }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/components/Identity/IdentityProvider.tsx",
        lineNumber: 34,
        columnNumber: 6
      }, void 0) }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/components/Identity/IdentityProvider.tsx",
        lineNumber: 33,
        columnNumber: 5
      }, void 0)
    ] }, void 0, true, {
      fileName: "/__w/interface/interface/packages/admin/src/components/Identity/IdentityProvider.tsx",
      lineNumber: 31,
      columnNumber: 4
    }, void 0),
    /* @__PURE__ */ jsxDEV(IdentityState, { state: "failed", children: /* @__PURE__ */ jsxDEV(InvalidIdentityFallback, {}, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/components/Identity/IdentityProvider.tsx",
      lineNumber: 38,
      columnNumber: 5
    }, void 0) }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/components/Identity/IdentityProvider.tsx",
      lineNumber: 37,
      columnNumber: 4
    }, void 0),
    /* @__PURE__ */ jsxDEV(IdentityState, { state: allowUnauthenticated ? "loading" : ["loading", "none"], children: /* @__PURE__ */ jsxDEV(SpinnerOverlay, {}, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/components/Identity/IdentityProvider.tsx",
      lineNumber: 41,
      columnNumber: 5
    }, void 0) }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/components/Identity/IdentityProvider.tsx",
      lineNumber: 40,
      columnNumber: 4
    }, void 0),
    /* @__PURE__ */ jsxDEV(IdentityState, { state: allowUnauthenticated ? ["success", "none"] : "success", children }, void 0, false, {
      fileName: "/__w/interface/interface/packages/admin/src/components/Identity/IdentityProvider.tsx",
      lineNumber: 43,
      columnNumber: 4
    }, void 0)
  ] }, void 0, true, {
    fileName: "/__w/interface/interface/packages/admin/src/components/Identity/IdentityProvider.tsx",
    lineNumber: 30,
    columnNumber: 3
  }, void 0);
};
export {
  IdentityProvider
};
//# sourceMappingURL=IdentityProvider.js.map
