import { useEffect } from "react";
import { useInitIDPRedirect } from "./useInitIDPRedirect.js";
const useIDPAutoInit = ({ onError, providers }) => {
  const onInitIDP = useInitIDPRedirect({ onError });
  useEffect(() => {
    const params = new URLSearchParams(window.location.search);
    const idp = params.get("idp");
    if (idp === null) {
      return;
    }
    const provider = providers.find((it) => it.provider === idp);
    if (provider) {
      onInitIDP(provider);
    } else {
      onError(`Undefined IdP ${idp}`);
    }
  }, [onError, onInitIDP, providers]);
};
export {
  useIDPAutoInit
};
//# sourceMappingURL=useIDPAutoInit.js.map
