import type { Metadata } from "next";
import Link from "@/components/Link";
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 { forgotPasswordHref, formEndpoint, signupHref, supportEmail } from "@/lib/site";

export const metadata: Metadata = pageMeta({
  title: "Log in",
  description: "Log in to your Advertising.net account to plan, launch and report on campaigns across every channel.",
  path: "/login",
  noindex: true,
});

/** Only reached when no white-labeled DSP is configured; next.config.ts redirects /login otherwise. */
export default function LoginPage() {
  return (
    <>
      <PageJsonLd path="/login" 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">Log in to Advertising.net</h1>
              <p className="an-muted">Access your advertiser account to manage campaigns and reporting.</p>
              <FormAlerts serviceTitle="We couldn’t log you in." serviceText="Please check the details you entered and try again." />
              <form className="an-form" id="login-form" data-form="login" data-endpoint={formEndpoint.login} method="post" action={formEndpoint.login} 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-field">
                  <div className="an-auth__row">
                    <label htmlFor="password">Password</label>
                    <a className="an-link" href={forgotPasswordHref}>Forgot password?</a>
                  </div>
                  <div className="an-pw">
                    <input className="an-input" id="password" name="password" type="password" autoComplete="current-password" required data-msg-required="Enter your password" />
                    <button type="button" className="an-pw__toggle" data-pw-toggle="" aria-pressed="false">Show</button>
                  </div>
                </div>
                <label className="an-consent">
                  <input type="checkbox" name="remember" value="1" />
                  <span>Keep me logged in on this device</span>
                </label>
                <div className="an-actions"><button className="an-btn an-btn--primary an-btn--block" type="submit" data-submit="">Log in</button></div>
              </form>
              <p className="an-auth__help">New here? <a href={signupHref} data-track="signup_click" data-track-location="login">Sign up to advertise</a></p>
            </div>
            <div className="an-success" data-success="" hidden tabIndex={-1}>
              <span className="an-success__icon"><Icon name="check" size={28} /></span>
              <h2 className="an-h3">Login received</h2>
              <p className="an-muted">We recorded your attempt. The advertiser platform isn’t connected to this site yet. Passwords are not stored here.</p>
            </div>
          </div>
          <p className="an-auth__help">Trouble logging in? Email <a href={`mailto:${supportEmail}`}>{supportEmail}</a></p>
        </div>
      </section>
      <FormRuntimeGate />
      <SiteEffects />
    </>
  );
}
