"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const react = require("react");
const ui = require("@contember/ui");
const useHandleIDPResponse = require("./useHandleIDPResponse.cjs");
const useResponseHandlerFeedback = ({ onLogin }) => {
  const responseState = useHandleIDPResponse.useHandleIDPResponse({
    onLogin,
    onError: react.useCallback(() => {
      window.history.pushState({}, document.title, "/");
    }, [])
  });
  switch (responseState.type) {
    case "nothing":
      return null;
    case "failed":
      const error = {
        INVALID_IDP_RESPONSE: "Login failed",
        IDP_VALIDATION_FAILED: "Login failed",
        INVALID_LOCAL_STATE: "Login failed",
        PERSON_NOT_FOUND: "User not found"
      }[responseState.error];
      return /* @__PURE__ */ jsxRuntime.jsx(ui.ErrorList, { errors: [{ message: error }] });
    default:
      return /* @__PURE__ */ jsxRuntime.jsx(ui.SpinnerOverlay, {});
  }
};
const IDPResponseHandler = ({ onLogin }) => {
  return useResponseHandlerFeedback({ onLogin });
};
exports.IDPResponseHandler = IDPResponseHandler;
exports.useResponseHandlerFeedback = useResponseHandlerFeedback;
//# sourceMappingURL=IDPResponseHandler.cjs.map
