import { prisma } from "@repo/db";
import { MessageCircleWarning } from "lucide-react";
const fetchMainMessage = async () => {
	return await prisma.notam.findFirst({
		where: {
			active: true,
			isMainMsg: true,
		},
	});
};

export const WarningAlert = async () => {
	const mainMessage = await fetchMainMessage();

	let msgColor;
	switch (mainMessage?.color) {
		case "WARNING":
			msgColor = "alert alert-warning ml-3";
			break;
		case "INFO":
			msgColor = "alert alert-info ml-3";
			break;
		case "SUCCESS":
			msgColor = "alert alert-success ml-3";
			break;
		case "ERROR":
			msgColor = "alert alert-error ml-3";
			break;
		default:
			msgColor = "alert ml-3";
	}

	if (mainMessage?.message == "" || !mainMessage) {
		return <></>;
	} else {
		return (
			<div role="alert" className={msgColor}>
				<MessageCircleWarning />
				<span className="font-bold">{mainMessage?.message}</span>
			</div>
		);
	}
};

/* ACHTUNG! Wir führen am kommenden Samstag Wartungsarbeiten am Server
				durch, von 19:00 Uhr bis 19:30 Uhr wird das HUB nicht erreichbar sein. */
