import { prisma } from "@repo/db";
import { TriangleAlert } from "lucide-react";
import { getServerSession } from "next-auth";

export const Penalty = async () => {
	const session = await getServerSession();
	const openPenaltys = await prisma.penalty.findMany({
		where: {
			userId: session?.user.id,
			until: {
				gte: new Date(),
			},
			type: "TIME_BAN",
		},
	});
	if (!openPenaltys[0]) {
		return null;
	}

	return (
		<div className="card bg-base-200 shadow-xl mb-4 col-span-6 xl:col-span-3">
			<div className="card-body">
				<h2 className="card-title text-3xl text-center text-error">
					<TriangleAlert />
					Aktive Strafe
				</h2>
				<p>Du hast eine aktive Strafe, die dich daran hindert, an Flügen teilzunehmen.</p>
				<p>Strafe: {openPenaltys[0].reason}</p>
				{openPenaltys[0].until && (
					<p>Bis: {new Date(openPenaltys[0].until).toLocaleDateString()}</p>
				)}
			</div>
		</div>
	);
};
