import Link from "next/link";
import { logoutAction } from "@/actions/auth";
import { requireUser } from "@/lib/auth/dal";
import { countCommentsByStatus } from "@/lib/services/comments";
import { getSettings } from "@/lib/services/settings";
// Belt to robots.txt's suspenders: even a stray crawler that reaches an
// admin URL is told not to index it.
export const metadata = { robots: { index: false, follow: false } };
const navLinkClasses =
"rounded-md px-2.5 py-1.5 text-sm font-medium text-ink transition-colors hover:bg-background hover:text-ink-strong";
/**
* Every route in this group is server-guarded: the layout redirects
* anonymous visitors, each page calls requireAdmin() again (defense in
* depth), and every mutating server action re-checks on its own.
*/
export default async function AdminLayout({ children }: { children: React.ReactNode }) {
const user = await requireUser();
const isAdmin = user.role === "admin";
const canModerate = user.permissions.approveComments;
const [settings, commentCounts] = await Promise.all([
getSettings(),
canModerate
? countCommentsByStatus(isAdmin ? undefined : { postAuthorId: user.id })
: { pending: 0, approved: 0 },
]);
return (
<>