import type { Metadata } from "next";
import { HorizontalNav, VerticalNav } from "../_components/Nav";
import { redirect } from "next/navigation";
import { getServerSession } from "../api/auth/[...nextauth]/auth";
import { EmailVerification } from "_components/EmailVerification";
import { FirstPath } from "./_components/FirstPath";
import { Penalty } from "_components/Penalty";

import { Footer } from "(app)/_components/Footer";

export const metadata: Metadata = {
	title: "VAR: Hub",
	description: "Virtual Air Rescue Hub",
};

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

	if (!session) redirect(`/login`);

	return (
		<div
			className="hero min-h-screen"
			style={{
				backgroundImage: "url('/bg.png')",
			}}
		>
			<div className="hero-overlay bg-opacity-30"></div>
			{/* Card */}
			<div className="hero-content text-neutral-content text-center w-full max-w-full h-full m-10">
				<div className="card bg-base-100 shadow-2xl w-full min-h-full h-full max-h-[calc(100vh-13rem)] p-4 flex flex-col mr-24 ml-24">
					{/* Top Navbar */}
					<HorizontalNav />

					{/* Hauptlayout: Sidebar + Content (nimmt Resthöhe ein) */}
					<div className="flex grow overflow-hidden">
						{/* Linke Sidebar */}
						<VerticalNav />

						{/* Scrollbarer Content-Bereich */}
						<div className="flex-grow bg-base-100 px-6 rounded-lg shadow-md ml-4 overflow-auto h-full max-w-full w-full">
							<Penalty />
							{!session?.user.emailVerified && (
								<div className="mb-4">
									<EmailVerification />
								</div>
							)}
							{!session.user.pathSelected && <FirstPath />}
							{children}
						</div>
					</div>

					<Footer />
				</div>
			</div>
		</div>
	);
}
