"use client";

import { Suspense } from "react";
import { useSearchParams } from "next/navigation";

import EmailVerificationForm from "@/features/auth/components/EmailVerificationForm";
import { asOtpType } from "@/features/auth/services/authApi";

/**
 * The `/email-verification` route's client half — see `LoginRoute` for why the
 * search-param read is split out of the page file.
 */
function EmailVerificationRouteContent() {
  const searchParams = useSearchParams();

  return (
    <EmailVerificationForm
      email={searchParams.get("email") || ""}
      /* Narrowed at the boundary: an arbitrary `?otp_type=` used to be
         forwarded to an endpoint that validates `in:register,password`. */
      otp_type={asOtpType(searchParams.get("otp_type"))}
    />
  );
}

export default function EmailVerificationRoute() {
  return (
    <Suspense fallback={null}>
      <EmailVerificationRouteContent />
    </Suspense>
  );
}
