'use client'

import { useVulaContent } from '@/hooks/useVulaContent'
import { Card, CardContent } from '@/components/ui/Card'
import { Heart, MessageCircle } from 'lucide-react'
import Image from 'next/image'

export default function KasiLoveSection() {
  const { items, loading } = useVulaContent('posts')
  if (loading) return <div className="flex justify-center py-16"><div className="w-8 h-8 rounded-full border-2 border-[#d4af37] border-t-transparent animate-spin" /></div>
  if (items.length === 0) return null

  return (
    <section id="kasi-love" data-vula-section="kasilove" data-vula-cms="posts" className="py-20 bg-[#d4af37] text-[#101418]">
      <div className="max-w-7xl mx-auto px-4">
        <div className="flex items-center gap-3 mb-10">
          <Heart className="w-6 h-6 text-[#dc2626]" />
          <h2 className="text-4xl md:text-5xl font-black uppercase tracking-tight">
            Kasi Love
          </h2>
        </div>
        <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
          {items.slice(0, 6).map((item) => {
            const d = item.data as { title?: string; excerpt?: string; author?: string; category?: string; image?: string }
            return (
              <Card key={item.id} className="border-2 border-[#18181b] shadow-[6px_6px_0_0_#18181b] rounded-none bg-white">
                <div className="relative h-40 w-full">
                  {d.image && (
                    <Image src={d.image} alt={d.title || ''} fill className="object-cover" sizes="(max-width: 768px) 100vw, 33vw" />
                  )}
                </div>
                <CardContent className="p-5 space-y-2">
                  <div className="flex items-center gap-2 text-xs uppercase tracking-wider text-[#dc2626]">
                    <MessageCircle className="w-3 h-3" />
                    <span>{d.category || 'Community'}</span>
                  </div>
                  <h3 className="text-lg font-black uppercase">{d.title}</h3>
                  <p className="text-sm text-gray-600">{d.excerpt}</p>
                  <p className="text-xs font-semibold uppercase tracking-wide text-[#d4af37]">— {d.author}</p>
                </CardContent>
              </Card>
            )
          })}
        </div>
      </div>
    </section>
  )
}
