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 v2: Pilot",
	description: "Die neue VAR Leitstelle.",
};

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

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

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