"use client";

import { useTranslation } from "react-i18next";
import CoverImage from "@/components/ui/CoverImage";

interface LearnServeCoverGalleryProps {
  id: string;
  galleryId?: string;
  coverImages: Array<{ id?: number; image?: string }>;
  /** Alt text and lightbox caption — the opportunity's own title. */
  coverGalleryTitle: string;
}

/** Inline gallery below the description, matching volunteer detail thumbnails. */
export default function LearnServeCoverGallery({
  id,
  galleryId,
  coverImages,
  coverGalleryTitle,
}: LearnServeCoverGalleryProps) {
  const { t } = useTranslation();
  if (!coverImages.length) return null;

  return (
    <div className="pt-6">
      <h2 className="mb-3 text-base font-bold text-primary-5">
        {t("COMMON.GALLERY")}
      </h2>
      <div className="grid grid-cols-2 gap-4 sm:grid-cols-3 lg:grid-cols-4 2xl:grid-cols-5">
        {coverImages.filter((img) => img.image).map((img, index) => (
          <a
            key={img.id ?? index}
            href={img.image}
            data-fancybox={galleryId ?? `opportunity-cover-${id}`}
            data-caption={coverGalleryTitle}
            className="relative block aspect-square w-full cursor-zoom-in overflow-hidden rounded-lg"
            title={t("COMMON.CLICK_TO_VIEW")}
          >
            <CoverImage
              src={img.image}
              alt={coverGalleryTitle}
              className="object-cover transition-transform duration-200 hover:scale-105"
              sizes="(min-width: 1024px) 15vw, 40vw"
            />
          </a>
        ))}
      </div>
    </div>
  );
}
