import { useCoreSignIn } from "../../contexts/CoreClientContext.js";
import { withCardStateProvider } from "../../elements/contexts/index.js";
import { LoadingCard } from "../../elements/LoadingCard.js";
import { withRedirectToAfterSignIn, withRedirectToSignInTask } from "../../common/withRedirect.js";
import { SignInFactorTwoAlternativeMethods } from "./SignInFactorTwoAlternativeMethods.js";
import { SignInFactorTwoEmailCodeCard } from "./SignInFactorTwoEmailCodeCard.js";
import { SignInFactorTwoEmailLinkCard } from "./SignInFactorTwoEmailLinkCard.js";
import { SignInFactorTwoPhoneCodeCard } from "./SignInFactorTwoPhoneCodeCard.js";
import { useSecondFactorSelection } from "./useSecondFactorSelection.js";
import { SignInFactorTwoBackupCodeCard } from "./SignInFactorTwoBackupCodeCard.js";
import { SignInFactorTwoTOTPCard } from "./SignInFactorTwoTOTPCard.js";
import { jsx } from "@emotion/react/jsx-runtime";

//#region src/components/SignIn/SignInFactorTwo.tsx
function SignInFactorTwoInternal() {
	const { currentFactor, factorAlreadyPrepared, handleFactorPrepare, selectFactor, showAllStrategies, toggleAllStrategies } = useSecondFactorSelection(useCoreSignIn().supportedSecondFactors);
	if (!currentFactor) return /* @__PURE__ */ jsx(LoadingCard, {});
	if (showAllStrategies) return /* @__PURE__ */ jsx(SignInFactorTwoAlternativeMethods, {
		onBackLinkClick: toggleAllStrategies,
		onFactorSelected: selectFactor
	});
	switch (currentFactor?.strategy) {
		case "phone_code": return /* @__PURE__ */ jsx(SignInFactorTwoPhoneCodeCard, {
			factorAlreadyPrepared,
			onFactorPrepare: handleFactorPrepare,
			factor: currentFactor,
			onShowAlternativeMethodsClicked: toggleAllStrategies
		});
		case "totp": return /* @__PURE__ */ jsx(SignInFactorTwoTOTPCard, {
			factorAlreadyPrepared,
			onFactorPrepare: handleFactorPrepare,
			factor: currentFactor,
			onShowAlternativeMethodsClicked: toggleAllStrategies
		});
		case "backup_code": return /* @__PURE__ */ jsx(SignInFactorTwoBackupCodeCard, { onShowAlternativeMethodsClicked: toggleAllStrategies });
		case "email_code": return /* @__PURE__ */ jsx(SignInFactorTwoEmailCodeCard, {
			factorAlreadyPrepared,
			onFactorPrepare: handleFactorPrepare,
			factor: currentFactor,
			onShowAlternativeMethodsClicked: toggleAllStrategies
		});
		case "email_link": return /* @__PURE__ */ jsx(SignInFactorTwoEmailLinkCard, {
			factorAlreadyPrepared,
			onFactorPrepare: handleFactorPrepare,
			factor: currentFactor,
			onShowAlternativeMethodsClicked: toggleAllStrategies
		});
		default: return /* @__PURE__ */ jsx(LoadingCard, {});
	}
}
const SignInFactorTwo = withRedirectToSignInTask(withRedirectToAfterSignIn(withCardStateProvider(SignInFactorTwoInternal)));

//#endregion
export { SignInFactorTwo };
//# sourceMappingURL=SignInFactorTwo.js.map