import { Connection } from "./_components/Connection";
import { Audio } from "../../../../_components/Audio/Audio";
import { ExitIcon, ExternalLinkIcon } from "@radix-ui/react-icons";
import Link from "next/link";
import { Settings } from "./_components/Settings";
import AdminPanel from "_components/navbar/AdminPanel";
import { getServerSession } from "api/auth/[...nextauth]/auth";
import { WarningAlert } from "_components/navbar/PageAlert";
import { Radar } from "lucide-react";
import { ChangelogWrapper } from "_components/navbar/ChangelogWrapper";
import { prisma } from "@repo/db";

export default async function Navbar() {
	const session = await getServerSession();
	const latestChangelog = await prisma.changelog.findFirst({
		orderBy: {
			createdAt: "desc",
		},
	});

	return (
		<div className="navbar bg-base-100 flex justify-between gap-5 shadow-sm">
			<div className="flex items-center gap-2">
				<div>
					<p className="text-xl font-semibold normal-case">VAR Leitstelle</p>
					<ChangelogWrapper latestChangelog={latestChangelog} />
				</div>
				{session?.user.permissions.includes("ADMIN_KICK") && <AdminPanel />}
			</div>
			<WarningAlert />
			<div className="flex items-center gap-5">
				<div className="flex items-center gap-2">
					<Audio />
				</div>
				<div className="flex items-center">
					<Connection />
				</div>
				<div className="flex items-center">
					<Settings />
					<Link href={"/tracker"} target="_blank" rel="noopener noreferrer">
						<button className="btn btn-ghost">
							<Radar size={19} /> Tracker
						</button>
					</Link>
					<Link
						href={process.env.NEXT_PUBLIC_HUB_URL || "#!"}
						target="_blank"
						rel="noopener noreferrer"
					>
						<button className="btn btn-ghost">
							<ExternalLinkIcon className="h-4 w-4" /> HUB
						</button>
					</Link>
					<Link href={"/logout"}>
						<button className="btn btn-ghost">
							<ExitIcon className="h-4 w-4" />
						</button>
					</Link>
				</div>
			</div>
		</div>
	);
}
