import { AdminSidebar } from "@/app/admin/admin-sidebar";
import { validateRequest } from "@/server/auth";
import { UserRole } from "@/server/auth/permissions";
import { IS_NOT, guard } from "@/utils/guard";
import { redirect } from "next/navigation";

interface AdminLayoutProps {
	children: React.ReactNode;
}

export const dynamic = "force-dynamic";

export default async function AdminLayout(props: AdminLayoutProps) {
	const { children } = props;
	const { user } = await validateRequest();

	if (guard(user, IS_NOT, UserRole.ADMIN)) {
		redirect("/");
	}

	return (
		<main className="flex flex-1 flex-col gap-4">
			<div className="mx-auto grid w-full gap-2">
				<h1 className="text-3xl font-semibold">Admin</h1>
			</div>
			<div className="mx-auto grid w-full items-start gap-4 md:gap-6 md:grid-cols-[180px_1fr] lg:grid-cols-[250px_1fr]">
				<nav className="grid gap-4 text-sm">
					<AdminSidebar />
				</nav>
				<div>{children}</div>
			</div>
		</main>
	);
}
