import type { Metadata } from "next";
import Link from "next/link";
import { ForgotForm, ResetForm } from "@/components/hub/AuthForms";
import { HubShell } from "@/components/hub/HubShell";
import { pageMetadata } from "@/lib/seo";

/* Depends on the visitor's session: never prerendered or cached. */
export const dynamic = "force-dynamic";

export const metadata: Metadata = pageMetadata({
  title: "Recover Your Password | Monetize Hub",
  description: "Recover the password for your Monetize Hub account.",
  path: "/hub-reset",
  noindex: true,
});

/* /hub-reset asks for the email; /hub-reset?token=… (the emailed link, for Hub accounts) sets a new password. */
export default async function HubResetPage({ searchParams }: { searchParams: Promise<{ token?: string }> }) {
  const token = (await searchParams).token ?? "";
  return (
    <HubShell eyebrow="Monetize Hub" title={token ? "Reset your" : "Recover your"} accent="password" lede={token ? "For your security, this link works once and only for an hour." : "We'll email your sign-in details to the address on your account."}>
      <h2>{token ? "Choose a new password" : "Recover your password"}</h2>
      <p className="login__sub">
        {token ? "This signs you out everywhere else." : "Enter the email on your account."} <Link className="mz-link" href="/hub-login">Back to sign in</Link>
      </p>
      {token ? <ResetForm token={token} /> : <ForgotForm />}
    </HubShell>
  );
}
