import { CreateUserForm } from "@/components/users/CreateUserForm";
import { auth } from "@/lib/auth";
import { headers } from "next/headers";
import { redirect } from "next/navigation";

export default async function NewUserPage() {
  const session = await auth.api.getSession({ headers: await headers() });
  const role = (session as any)?.user?.role;

  if (!session) redirect("/login");
  if (role !== "admin") redirect("/");

  return (
    <div className="mx-auto max-w-md p-6">
      <h1 className="text-xl font-semibold">Create user</h1>
      <p className="mt-1 text-sm text-muted-foreground">
        Create a new user account (registration is disabled publicly).
      </p>
      <div className="mt-6">
        <CreateUserForm />
      </div>
    </div>
  );
}
