import { UsersTable } from "@/components/users/UsersTable";
import { auth } from "@/lib/auth";
import type { SessionWithRole } from "@/types/auth";
import { headers } from "next/headers";
import { redirect } from "next/navigation";

// Admin users list page.
export default async function UsersPage() {
  const session = await auth.api.getSession({ headers: await headers() });
  const role = (session as SessionWithRole)?.user?.role;

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

  return (
    <div className="mx-auto max-w-5xl p-6 space-y-6">
      <div className="flex items-end justify-between gap-4">
        <div className="space-y-1">
          <h1 className="text-2xl font-semibold tracking-tight">Users</h1>
          <p className="text-sm text-muted-foreground">
            Manage admin accounts and staff users.
          </p>
        </div>
      </div>

      <UsersTable />
    </div>
  );
}
