import type { Metadata } from "next";
import FormAlerts from "@/components/FormAlerts";
import FormRuntimeGate from "@/components/FormRuntimeGate";
import Icon from "@/components/Icon";
import SiteEffects from "@/components/SiteEffects";
import { PageJsonLd, pageMeta } from "@/lib/seo";
import { formEndpoint, loginHref, supportEmail } from "@/lib/site";

export const metadata: Metadata = pageMeta({
  title: "Reset your password",
  description: "Forgot your password? Enter your email and we’ll send a secure link to reset your Advertising.net account password.",
  path: "/forgot-password",
  noindex: true,
});

/** Only reached when no white-labeled DSP is configured; next.config.ts redirects /forgot-password otherwise. */
export default function ForgotPasswordPage() {
  return (
    <>
      <PageJsonLd path="/forgot-password" meta={metadata} />
      <section className="an-auth">
        <div className="an-wrap an-auth__inner">
          <div className="an-formcard">
            <div data-form-wrap="">
              <h1 className="an-h3">Forgot your password?</h1>
              <p className="an-muted">Enter the email you use for Advertising.net and we’ll send you a link to reset it.</p>
              <FormAlerts serviceTitle="We couldn’t send the reset link." serviceText="Something went wrong on our side. Please try again in a moment." />
              <form className="an-form" id="password-reset-form" data-form="password_reset" data-endpoint={formEndpoint.password_reset} method="post" action={formEndpoint.password_reset} data-hs-do-not-collect="true" noValidate>
                <div className="an-field">
                  <label htmlFor="email">Work email</label>
                  <input className="an-input" id="email" name="email" type="email" autoComplete="username" inputMode="email" required data-msg-required="Enter your email" />
                </div>
                <div className="an-actions"><button className="an-btn an-btn--primary an-btn--block" type="submit" data-submit="">Send reset link</button></div>
              </form>
              <p className="an-auth__help">Remembered it? <a href={loginHref}>Log in</a></p>
            </div>
            <div className="an-success" data-success="" hidden tabIndex={-1}>
              <span className="an-success__icon"><Icon name="mail" size={28} /></span>
              <h2 className="an-h3">Reset request saved</h2>
              <p className="an-muted">We recorded a reset request for <strong data-success-email="">that email</strong>. Reset emails aren’t sent from this site yet. Need to get back in now? Email <a href={`mailto:${supportEmail}`}>{supportEmail}</a> and we’ll help you.</p>
              <a className="an-btn an-btn--ghost" href={loginHref}>Back to log in</a>
            </div>
          </div>
        </div>
      </section>
      <FormRuntimeGate />
      <SiteEffects />
    </>
  );
}
