import Image from "next/image";

import { SectionHeading } from "@/components/section-heading";
import { prisma } from "@/lib/prisma";

export async function Gallery() {
  const galleryImages = await prisma.galleryimage.findMany({
    where: {
      category: "GALLERY",
      isActive: true,
    },
    orderBy: [
      {
        sortOrder: "asc",
      },
      {
        createdAt: "desc",
      },
    ],
  });

  if (galleryImages.length === 0) {
    return null;
  }

  return (
    <section className="mx-auto max-w-7xl px-4 py-20 md:px-8 md:py-24">
      <SectionHeading
        tag="Galerie"
        title="L'expérience Happy Hours"
      />

      <p className="mx-auto mt-4 max-w-2xl text-center text-muted-foreground">
        Découvrez l'ambiance, les moments et l'univers de Happy Hours.
      </p>

      <div className="mt-10 grid grid-cols-2 gap-3 md:grid-cols-3 md:gap-4">
        {galleryImages.map((img) => (
          <div
            key={img.id}
            className="group relative aspect-[4/3] overflow-hidden rounded-2xl"
          >
            <Image
              src={img.imageUrl || "/placeholder.svg"}
              alt={img.title || "Galerie Happy Hours"}
              fill
              sizes="(max-width: 768px) 50vw, 33vw"
              className="object-cover transition-transform duration-500 group-hover:scale-105"
            />
          </div>
        ))}
      </div>
    </section>
  );
}