import type { Metadata } from "next";
import { notFound, redirect } from "next/navigation";
import Admin from "@/components/hub/Admin";
import { currentUser } from "@/lib/auth";
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: "Staff | Monetize.com",
  description: "Monetize.com staff dashboard.",
  path: "/admin",
  noindex: true,
});

/* Staff only. Signed-out visitors go to the Hub login; signed-in publishers get a 404 (the page isn't advertised). */
export default async function AdminPage() {
  const user = await currentUser();
  if (!user) redirect("/hub-login?next=/admin");
  if (user.role !== "ADMIN") notFound();
  return (
    <section className="page-sec hub-page">
      <Admin />
    </section>
  );
}
