import type { Metadata } from "next";
import Navbar from "./_components/navbar/Navbar";
import { redirect } from "next/navigation";
import { getServerSession } from "../api/auth/[...nextauth]/auth";
import { Error } from "_components/Error";

export const metadata: Metadata = {
	title: "VAR: Disponent",
	description: "Die neue VAR Leitstelle.",
};

export default async function RootLayout({
	children,
}: Readonly<{
	children: React.ReactNode;
}>) {
	const session = await getServerSession();

	if (!session || !session.user) {
		redirect("/login");
	}

	if (!session.user.emailVerified)
		return <Error title="E-Mail-Adresse nicht verifiziert" statusCode={403} />;

	if (!session.user.permissions.includes("DISPO"))
		return <Error title="Zugriff verweigert" statusCode={403} />;
	return (
		<>
			<Navbar />
			{children}
		</>
	);
}
