'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 data-vula-section="gallery" id="gallery" className="py-20 bg-white">
      <div className="container mx-auto px-4 max-w-6xl">
        <h2 className="text-3xl font-bold text-center mb-12 text-[#111827]">From Our Roastery</h2>
        <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
          {items.map((item) => {
            const d = item.data as { title?: string; description?: string; image?: string }
            return (
              <div key={item.id} className="bg-white rounded-xl border border-[#e5e7eb] overflow-hidden shadow-[var(--shadow-card)] hover:shadow-[var(--shadow-lifted)] transition-shadow duration-200">
                {d.image && (
                  <div className="relative aspect-video">
                    <Image src={d.image} alt={d.title || 'Gallery image'} fill sizes="(max-width: 640px) 100vw, (max-width: 1024px) 50vw, 33vw" className="object-cover" />
                  </div>
                )}
                <div className="p-4">
                  {d.title && <h3 className="font-semibold text-[#111827]">{d.title}</h3>}
                  {d.description && <p className="text-sm text-[#4b5563] mt-1">{d.description}</p>}
                </div>
              </div>
            )
          })}
        </div>
      </div>
    </section>
  )
}