import type { Metadata } from "next";
import { getServerSession } from "api/auth/[...nextauth]/auth";
import { Error } from "_components/Error";
import Navbar from "(app)/_components/Navbar";
import { Audio } from "_components/Audio/Audio";
import { Connection } from "./_components/navbar/Connection";
import { Settings } from "./_components/navbar/Settings";

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

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

	if (!session?.user.permissions.includes("PILOT"))
		return (
			<Error
				title=" Fehlende Berechtigung"
				description="Du hast nicht die erforderlichen Berechtigungen, dich als Pilot anzumelden. Du kannst in HUB Kurse abschließen um die Berechtigung zu erhalten."
				statusCode={403}
			/>
		);

	return (
		<>
			<Navbar>
				<Audio />
				<Connection />
				<Settings />
			</Navbar>
			{children}
		</>
	);
}
