'use client'

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

export default function ExclusiveRetreatOffersSection() {
  const { items, loading } = useEmDashContent('offers')

  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 text-[#f5f5dc]" />
      </div>
    )
  }

  if (items.length === 0) return null

  return (
    <section
      id="exclusive-offers"
      data-vula-section="exclusiveretreatoffers"
      data-vula-cms="offers"
      className="py-24 bg-[#17170f]"
    >
      <div className="max-w-7xl mx-auto px-6">
        {/* Eyebrow */}
        <div className="flex items-center justify-center gap-4 mb-4">
          <div className="w-14 h-px bg-[#f5f5dc]" />
          <span className="text-[#6b8e23] font-sans uppercase tracking-[0.15em] text-sm">
            Curated Escapes
          </span>
          <div className="w-14 h-px bg-[#f5f5dc]" />
        </div>
        <h2 className="text-4xl md:text-5xl font-light text-[#eeeee7] text-center mb-4 font-serif">
          Lasting Impressions, Timely Invitations
        </h2>
        <p className="text-[#eeeee7]/80 text-center max-w-2xl mx-auto mb-12 font-sans text-sm leading-relaxed">
          Hand‑picked packages for those who seek the extraordinary.
        </p>

        <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
          {items.map((item) => {
            const d = item.data as {
              title?: string
              description?: string
              price?: string
              duration?: string
              valid_until?: string
              image?: string
            }
            return (
              <div
                key={item.id}
                className="group rounded-[8px] border border-white/10 bg-[#17170f] overflow-hidden hover:border-[#f5f5dc]/30 transition-all duration-200"
              >
                <div className="relative aspect-video overflow-hidden">
                  {d.image && (
                    <Image
                      src={d.image}
                      alt={d.title ?? 'Retreat offer'}
                      fill
                      sizes="(max-width: 768px) 100vw, 33vw"
                      className="object-cover transition-transform duration-500 ease-out group-hover:scale-105"
                    />
                  )}
                </div>
                <div className="p-5">
                  <h3 className="text-xl font-serif font-light text-[#eeeee7] mb-2">{d.title}</h3>
                  <p className="text-sm text-[#eeeee7]/70 mb-3 font-sans leading-relaxed">{d.description}</p>
                  <div className="flex items-center justify-between text-sm">
                    {d.price && (
                      <span className="text-[#f5f5dc] font-semibold font-sans">{d.price}</span>
                    )}
                    {d.duration && (
                      <span className="text-[#6b8e23] font-sans uppercase tracking-wider text-xs">
                        {d.duration}
                      </span>
                    )}
                  </div>
                  {d.valid_until && (
                    <p className="text-xs text-[#eeeee7]/50 mt-2 font-sans">
                      Valid until {d.valid_until}
                    </p>
                  )}
                  <Button variant="default" size="sm" className="mt-4 w-full">
                    Reserve Now
                  </Button>
                </div>
              </div>
            )
          })}
        </div>
      </div>
    </section>
  )
}
