import { jsx } from "react/jsx-runtime";
import { useCallback } from "react";
import { SpinnerOverlay, ErrorList } from "@contember/ui";
import { useHandleIDPResponse } from "./useHandleIDPResponse.js";
const useResponseHandlerFeedback = ({ onLogin }) => {
  const responseState = useHandleIDPResponse({
    onLogin,
    onError: 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__ */ jsx(ErrorList, { errors: [{ message: error }] });
    default:
      return /* @__PURE__ */ jsx(SpinnerOverlay, {});
  }
};
const IDPResponseHandler = ({ onLogin }) => {
  return useResponseHandlerFeedback({ onLogin });
};
export {
  IDPResponseHandler,
  useResponseHandlerFeedback
};
//# sourceMappingURL=IDPResponseHandler.js.map
