'use client'

import { useEmDashContent } from '@/hooks/useEmDashContent'
import Image from 'next/image'
import Link from 'next/link'
import Button from '@/components/ui/Button'

export default function IthubaSpecialsSection() {
  const { items, loading } = useEmDashContent('promotions')

  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="ithubaspecials"
      data-vula-section="ithubaspecials"
      data-vula-cms="promotions"
      className="py-20 bg-[#f9f7f4]"
    >
      <div className="max-w-7xl mx-auto px-4">
        <h2 className="text-4xl font-semibold text-[#211c0d] mb-2 text-center">
          Exclusive Bush Retreat Offers
        </h2>
        <p className="text-lg text-[#211c0d]/70 mb-12 text-center max-w-2xl mx-auto">
          Seasonal packages designed for discovery and indulgence, crafted to make your Zulu escape unforgettable.
        </p>
        <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
          {items.map((item) => {
            const d = item.data as {
              title?: string
              description?: string
              price?: string
              image?: string
            }
            return (
              <div
                key={item.id}
                className="group bg-white rounded-xl shadow-lg overflow-hidden border border-[#e2dfd4]"
              >
                <div className="relative h-56 overflow-hidden">
                  <Image
                    src={d.image ?? '/placeholder.jpg'}
                    alt={d.title ?? 'Special offer'}
                    fill
                    sizes="(max-width: 768px) 100vw, (max-width: 1024px) 50vw, 33vw"
                    className="object-cover group-hover:scale-105 transition-transform duration-500 ease-out"
                  />
                </div>
                <div className="p-6">
                  <h3 className="text-xl font-bold text-[#211c0d] mb-2">{d.title}</h3>
                  <p className="text-[#211c0d]/70 mb-3 line-clamp-3">{d.description}</p>
                  {d.price && (
                    <p className="text-lg font-semibold text-[#d4af37] mb-4">{d.price}</p>
                  )}
                  <Button variant="default" size="md" className="w-full">
                    <Link href="/booking">Enquire Now</Link>
                  </Button>
                </div>
              </div>
            )
          })}
        </div>
      </div>
    </section>
  )
}
