'use client'

import Image from 'next/image'
import { useVulaContent } from '@/hooks/useVulaContent'
import { ArrowRight } from 'lucide-react'

interface CampaignItemData {
  title?: string
  headline?: string
  body?: string
  cta_text?: string
  image?: string
}

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

  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="campaign-lookbook" data-vula-section="campaignlookbook" data-vula-cms="campaigns" className="bg-[#18181b] py-20">
      <div className="mx-auto max-w-7xl px-4">
        <div className="mb-10 flex flex-col gap-4 border-l-4 border-[#fbbf24] pl-4">
          <p className="text-sm font-bold uppercase tracking-[0.3em] text-[#fbbf24]">Lookbook / Durban</p>
          <h2 className="max-w-2xl text-4xl font-black uppercase text-white md:text-6xl">Shoots that <span className="text-[#fbbf24]">hit</span> different.</h2>
        </div>
        <div className="grid gap-8 md:grid-cols-2">
          {items.slice(0, 4).map((item) => {
            const d = (item.data ?? {}) as CampaignItemData
            return (
              <article key={item.id} className="group border-2 border-white bg-white shadow-[6px_6px_0_0_#fbbf24] transition-all duration-200 ease-out hover:-translate-x-1 hover:-translate-y-1">
                <div className="relative h-72 overflow-hidden border-b-2 border-white md:h-80">
                  {d.image ? (
                    <Image src={d.image} alt={d.title ?? 'Kasi Drip campaign'} fill sizes="(max-width: 768px) 100vw, 50vw" className="object-cover transition-transform duration-500 ease-out group-hover:scale-105" />
                  ) : (
                    <div className="flex h-full items-center justify-center bg-[#fbbf24] text-4xl font-black text-black">KD</div>
                  )}
                </div>
                <div className="p-5">
                  {d.headline ? <p className="text-sm font-bold uppercase tracking-widest text-[#ea580c]">{d.headline}</p> : null}
                  {d.title ? <h3 className="mt-1 text-2xl font-black uppercase text-black">{d.title}</h3> : null}
                  {d.body ? <p className="mt-2 text-sm text-zinc-700">{d.body}</p> : null}
                  {d.cta_text ? <span className="mt-4 inline-flex items-center gap-2 bg-[#18181b] px-4 py-2 text-sm font-bold uppercase text-[#fbbf24]">{d.cta_text} <ArrowRight className="h-4 w-4" /></span> : null}
                </div>
              </article>
            )
          })}
        </div>
      </div>
    </section>
  )
}