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

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

	if (mainMessage?.showUntilActive && new Date(mainMessage.showUntil) < new Date()) {
		return <></>;
	}

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

	if ((mainMessage?.message == "" && !mainMessage?.wartungsmodus) || !mainMessage) {
		return <></>;
	} else {
		return (
			<div role="alert" className={msgColor}>
				<MessageCircleWarning />
				<span className="font-bold m-0">
					{mainMessage?.wartungsmodus ? "Wartungsmodus aktiv!" : 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. */
