import React from 'react';
import Link from 'next/link';
import Image from 'next/image';
import { Article } from '@/types';

interface FeaturedGridProps {
  articles: Article[];
}

export default function FeaturedGrid({ articles }: FeaturedGridProps) {
  if (articles.length === 0) return null;

  const main = articles[0];
  const side = articles.slice(1, 5);

  return (
    <section className="grid grid-cols-1 lg:grid-cols-4 gap-4 mb-12">
      {/* Main Feature - CLS önleme için bg-gray-100 */}
      <Link
        href={`/haber/${main.slug}`}
        className="lg:col-span-2 relative group cursor-pointer overflow-hidden rounded-2xl h-[400px] lg:h-[500px] block bg-gray-100"
      >
        <Image
          src={main.imageUrl || '/images/placeholder.jpg'}
          alt={main.title}
          fill
          className="object-cover transition-transform duration-700 group-hover:scale-105"
          sizes="(max-width: 1024px) 100vw, 50vw"
          priority
          placeholder="blur"
          blurDataURL="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAAIAAoDASIAAhEBAxEB/8QAFgABAQEAAAAAAAAAAAAAAAAAAAUH/8QAIhAAAgEDAwUBAAAAAAAAAAAAAQIDAAQRBRIhBhMxQVFh/8QAFQEBAQAAAAAAAAAAAAAAAAAAAAX/xAAZEQACAwEAAAAAAAAAAAAAAAABAgADESH/2gAMAwEAAhEDEQA/AKuo9V6jqNy1zdXssk0m0O7EZbaMDOPQwB+UpSq1szDSCxm5Z//Z"
        />
        <div className="absolute inset-0 bg-gradient-to-t from-black/90 via-black/30 to-transparent" />
        <div className="absolute bottom-0 left-0 p-6">
          <span className="bg-red-600 text-white text-[10px] font-bold px-2 py-1 rounded mb-3 inline-block uppercase tracking-wider">
            Sürmanşet
          </span>
          <h2 className="text-2xl md:text-3xl font-extrabold text-white leading-tight">
            {main.title}
          </h2>
        </div>
      </Link>

      {/* Side Features */}
      <div className="lg:col-span-2 grid grid-cols-2 gap-4">
        {side.map((article) => (
          <Link
            key={article.id}
            href={`/haber/${article.slug}`}
            className="relative group cursor-pointer overflow-hidden rounded-xl h-[192px] lg:h-[242px] block bg-gray-100"
          >
            <Image
              src={article.imageUrl || '/images/placeholder.jpg'}
              alt={article.title}
              fill
              className="object-cover transition-transform duration-700 group-hover:scale-105"
              sizes="(max-width: 1024px) 50vw, 25vw"
              placeholder="blur"
              blurDataURL="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMCUoKSj/2wBDAQcHBwoIChMKChMoGhYaKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCj/wAARCAAIAAoDASIAAhEBAxEB/8QAFgABAQEAAAAAAAAAAAAAAAAAAAUH/8QAIhAAAgEDAwUBAAAAAAAAAAAAAQIDAAQRBRIhBhMxQVFh/8QAFQEBAQAAAAAAAAAAAAAAAAAAAAX/xAAZEQACAwEAAAAAAAAAAAAAAAABAgADESH/2gAMAwEAAhEDEQA/AKuo9V6jqNy1zdXssk0m0O7EZbaMDOPQwB+UpSq1szDSCxm5Z//Z"
            />
            <div className="absolute inset-0 bg-gradient-to-t from-black/80 via-transparent to-transparent" />
            <div className="absolute bottom-0 left-0 p-4">
              <span className="text-red-500 text-[9px] font-bold uppercase mb-1 block tracking-widest">
                {article.category}
              </span>
              <h3 className="text-sm font-bold text-white leading-snug line-clamp-2">
                {article.title}
              </h3>
            </div>
          </Link>
        ))}
      </div>
    </section>
  );
}
