'use client'

import { useEmDashContent } from '@/hooks/useEmDashContent'
import Image from 'next/image'

export default function GallerySection() {
  const { items, loading } = useEmDashContent('gallery')

  if (loading) return <div className="flex justify-center py-16"><div className="w-8 h-8 rounded-full border-2 border-current border-t-transparent animate-spin" /></div>
  if (items.length === 0) return null

  return (
    <section id="gallery" data-vula-section="gallery" data-vula-cms="gallery" className="bg-[#1a1a2e] py-20 px-6">
      <div className="max-w-6xl mx-auto">
        <h2 className="text-3xl lg:text-4xl font-bold text-[#F5F5F5] mb-4">Street Gallery</h2>
        <p className="text-[#F5F5F5]/70 mb-12 max-w-2xl">Capturing S.A.W. in its natural habitat — Durban's urban landscape.</p>
        <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
          {items.map((item) => {
            const d = item.data as { title?: string; description?: string; image?: string }
            return (
              <div key={item.id} className="group rounded-xl overflow-hidden bg-white shadow-md hover:shadow-[var(--shadow-lifted)] transition-all duration-200 ease-out">
                {d.image && (
                  <div className="relative aspect-[4/3] w-full overflow-hidden">
                    <Image src={d.image} alt={d.title ?? ''} fill className="object-cover group-hover:scale-105 transition-transform duration-500 ease-out" sizes="(max-width: 768px) 100vw, (max-width: 1024px) 50vw, 33vw" />
                  </div>
                )}
                <div className="p-4">
                  {d.title && <h3 className="text-sm font-semibold text-gray-900 mb-1">{d.title}</h3>}
                  {d.description && <p className="text-xs text-gray-500 line-clamp-2">{d.description}</p>}
                </div>
              </div>
            )
          })}
        </div>
      </div>
    </section>
  )
}
