import { NextResponse, type NextRequest } from "next/server";

// PR firms / writers authenticate at the distribute platform, not here.
// Anything that looks like a WordPress login or the bare /login path
// redirects there so old bookmarks don't dead-end.
const AUTH_TARGET = "https://distribution.relevantmediaproperties.com/login";

const REDIRECT_PATHS = new Set<string>([
  "/login",
  "/wp-login",
  "/wp-login.php",
  "/wp-admin",
  "/client-login",
  "/register",
]);

export function middleware(req: NextRequest) {
  const path = req.nextUrl.pathname;
  if (
    REDIRECT_PATHS.has(path) ||
    path.startsWith("/wp-admin/") ||
    path.startsWith("/wp-login/")
  ) {
    return NextResponse.redirect(AUTH_TARGET, 301);
  }
  return NextResponse.next();
}

export const config = {
  matcher: [
    "/login",
    "/wp-login",
    "/wp-login.php",
    "/wp-admin/:path*",
    "/wp-login/:path*",
    "/client-login",
    "/register",
  ],
};
