'use client'
import { useVulaContent } from '@/hooks/useVulaContent'
import Image from 'next/image'

export default function CampaignSection() {
  const { items, loading } = useVulaContent('campaigns')

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

  return (
    <section id="campaigns" data-vula-section="campaign" data-vula-cms="campaigns" className="bg-[#36454F] py-20">
      <div className="mx-auto max-w-7xl px-4">
        <div className="mb-12 max-w-2xl">
          <p className="text-sm font-semibold uppercase tracking-widest text-[#ea580c]">Seasonal collections</p>
          <h2 className="mt-2 font-display text-3xl font-semibold text-white md:text-4xl">Limited runs from the Ukaya workshop</h2>
          <p className="mt-3 text-[#dee2d4]">Small-batch campaigns drop throughout the year. When a collection is gone, it is gone.</p>
        </div>
        <div className="grid grid-cols-1 gap-6 md:grid-cols-2 lg:grid-cols-3">
          {items.map((item) => {
            const d = item.data as { title?: string; headline?: string; body?: string; cta_text?: string; image?: string }
            return (
              <article key={item.id} className="group overflow-hidden rounded-2xl bg-[#1b210d] shadow-[0_12px_30px_rgba(0,0,0,0.2)]">
                <div className="relative aspect-[4/3] overflow-hidden">
                  {d.image ? (
                    <Image src={d.image} alt={d.title ?? 'Ukaya Home campaign'} fill sizes="(max-width: 768px) 100vw, 33vw" className="object-cover transition-transform duration-500 ease-out group-hover:scale-105" />
                  ) : (
                    <div className="absolute inset-0 bg-[#6b8e23]" />
                  )}
                  <div className="absolute inset-0 bg-gradient-to-t from-[#1b210d]/90 via-[#1b210d]/30 to-transparent" />
                  <div className="absolute inset-x-0 bottom-0 p-5">
                    {d.title ? <p className="text-sm font-semibold uppercase tracking-widest text-[#ea580c]">{d.title}</p> : null}
                    {d.headline ? <h3 className="mt-1 font-display text-2xl font-semibold text-white">{d.headline}</h3> : null}
                    {d.body ? <p className="mt-2 text-sm leading-relaxed text-white/80 line-clamp-3">{d.body}</p> : null}
                    {d.cta_text ? <span className="mt-3 inline-block rounded-full bg-[#ea580c] px-4 py-2 text-sm font-semibold text-white">{d.cta_text}</span> : null}
                  </div>
                </div>
              </article>
            )
          })}
        </div>
      </div>
    </section>
  )
}