"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxDevRuntime = require("react/jsx-dev-runtime");
const ui = require("@contember/ui");
const react = require("react");
const MiscPageLayout = require("../MiscPageLayout.cjs");
const InvalidIdentityFallback = require("./InvalidIdentityFallback.cjs");
const reactIdentity = require("@contember/react-identity");
const ClearIdentityHandler = ({ onInvalidIdentity }) => {
  react.useEffect(() => {
    if (onInvalidIdentity) {
      onInvalidIdentity();
    } else if (window.location.pathname !== "/") {
      window.location.href = "/";
    }
  }, [onInvalidIdentity]);
  return null;
};
const IdentityProvider = ({ children, onInvalidIdentity, allowUnauthenticated }) => {
  return /* @__PURE__ */ jsxDevRuntime.jsxDEV(reactIdentity.IdentityProvider, { children: [
    /* @__PURE__ */ jsxDevRuntime.jsxDEV(reactIdentity.IdentityState, { state: "cleared", children: [
      /* @__PURE__ */ jsxDevRuntime.jsxDEV(ClearIdentityHandler, { onInvalidIdentity }, void 0, false, {
        fileName: "/__w/interface/interface/packages/admin/src/components/Identity/IdentityProvider.tsx",
        lineNumber: 32,
        columnNumber: 5
      }, void 0),
      /* @__PURE__ */ jsxDevRuntime.jsxDEV(MiscPageLayout.MiscPageLayout, { children: /* @__PURE__ */ jsxDevRuntime.jsxDEV(ui.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__ */ jsxDevRuntime.jsxDEV(reactIdentity.IdentityState, { state: "failed", children: /* @__PURE__ */ jsxDevRuntime.jsxDEV(InvalidIdentityFallback.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__ */ jsxDevRuntime.jsxDEV(reactIdentity.IdentityState, { state: allowUnauthenticated ? "loading" : ["loading", "none"], children: /* @__PURE__ */ jsxDevRuntime.jsxDEV(ui.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__ */ jsxDevRuntime.jsxDEV(reactIdentity.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);
};
exports.IdentityProvider = IdentityProvider;
//# sourceMappingURL=IdentityProvider.cjs.map
