import type { Metadata } from "next";
import LoginClient from "./LoginClient";

const BASE_URL = process.env.NEXT_PUBLIC_SITE_URL ?? "https://routecommerce.com";

export const metadata: Metadata = {
  title: "Sign In — Route Commerce",
  description: "Sign in to your Route Commerce account. Access your admin dashboard, manage orders, stops, and communications.",
  keywords: ["sign in", "login", "admin", "account", "Route Commerce"],
  openGraph: {
    title: "Sign In — Route Commerce",
    description: "Sign in to your Route Commerce account.",
    url: `${BASE_URL}/login`,
    siteName: "Route Commerce",
    locale: "en_US",
    type: "website",
  },
  robots: {
    index: false,
    follow: false,
  },
};

type SearchParams = { error?: string; redirect?: string };

export default async function LoginPage({
  searchParams,
}: {
  searchParams: Promise<SearchParams>;
}) {
  const params = await searchParams;
  const error =
    params?.error === "SignInFailed"
      ? "Sign-in failed. Please check your email and password."
      : params?.error === "MissingCredentials"
        ? "Email and password are required."
        : params?.error
          ? "Sign-in failed. Please try again."
          : null;

  return (
    <LoginClient
      error={error}
    />
  );
}
