import { useRouter } from "../../router/RouteContext.js";
import { SignInContext } from "../../contexts/components/SignIn.js";
import { useSignUpContext } from "../../contexts/components/SignUp.js";
import { VerificationCodeCard } from "../../elements/VerificationCodeCard.js";
import { completeSignUpFlow } from "./util.js";
import React from "react";
import { forwardClerkQueryParams } from "@clerk/shared/internal/clerk-js/queryParams";
import { useClerk } from "@clerk/shared/react";
import { jsx } from "@emotion/react/jsx-runtime";

//#region src/components/SignUp/SignUpVerificationCodeForm.tsx
const SignUpVerificationCodeForm = (props) => {
	const { afterSignUpUrl, navigateOnSetActive, isCombinedFlow: _isCombinedFlow } = useSignUpContext();
	const { setActive } = useClerk();
	const { navigate } = useRouter();
	const isCombinedFlow = !!(!!React.useContext(SignInContext) && _isCombinedFlow);
	const goBack = () => {
		const params = forwardClerkQueryParams();
		return navigate(isCombinedFlow ? "../../" : "../", { searchParams: params });
	};
	const action = (code, resolve, reject) => {
		props.attempt(code).then(async (res) => {
			await resolve();
			return completeSignUpFlow({
				signUp: res,
				verifyEmailPath: "../verify-email-address",
				verifyPhonePath: "../verify-phone-number",
				continuePath: "../continue",
				handleComplete: () => setActive({
					session: res.createdSessionId,
					navigate: async ({ session }) => {
						await navigateOnSetActive({
							session,
							redirectUrl: afterSignUpUrl
						});
					}
				}),
				navigate
			});
		}).catch((err) => {
			return reject(err);
		});
	};
	return /* @__PURE__ */ jsx(VerificationCodeCard, {
		cardTitle: props.cardTitle,
		cardSubtitle: props.cardSubtitle,
		resendButton: props.resendButton,
		onCodeEntryFinishedAction: action,
		onResendCodeClicked: props.prepare,
		safeIdentifier: props.safeIdentifier,
		onIdentityPreviewEditClicked: goBack,
		alternativeMethodsLabel: props.alternativeMethodsLabel,
		onShowAlternativeMethodsClicked: props.onShowAlternativeMethodsClicked,
		showAlternativeMethods: props.showAlternativeMethods
	});
};

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