'use client';

import { motion } from 'framer-motion';
import { useTranslator } from '@/contexts/TranslatorContext';
import Image from 'next/image';

const SpeedAdvantage = () => {
  const { translations, dir } = useTranslator();

  const ICON_BASE = '/images/icon';
  
  const fallbackItems = [
    {
      icon: `${ICON_BASE}/performance-boost.svg`,
      alt: 'تعزيز الأداء',
      title: 'تعزيز الأداء',
      description: 'تحسين أداء موقعك بسرعة فائقة',
    },
    {
      icon: `${ICON_BASE}/CDN.svg`,
      alt: 'شبكة CDN',
      title: 'شبكة CDN',
      description: 'توزيع المحتوى عالمياً لسرعة فائقة',
    },
    {
      icon: `${ICON_BASE}/ssd-storage.svg`,
      alt: 'تخزين SSD',
      title: 'تخزين SSD',
      description: 'تخزين سريع وموثوق لبياناتك',
    },
    {
      icon: `${ICON_BASE}/server-monitoring.svg`,
      alt: 'مراقبة فورية',
      title: 'مراقبة فورية',
      description: 'تنبيهات ذكية وتحليلات لحظية',
    },
    {
      icon: `${ICON_BASE}/security.svg`,
      alt: 'طبقات حماية',
      title: 'طبقات حماية',
      description: 'حماية متقدمة دون التأثير على السرعة',
    },
    {
      icon: `${ICON_BASE}/speed.svg`,
      alt: 'شبكة عالية السرعة',
      title: 'شبكة عالية السرعة',
      description: 'اتصال سريع بزمن استجابة منخفض',
    },
  ];

  const advantages = translations?.fast_page?.speed_advantage?.items?.length
    ? translations.fast_page.speed_advantage.items
    : fallbackItems;

  return (
    <section className='bg-white w-full -mt-28 md:-mt-36 lg:-mt-44 pt-0' dir={dir}>
      <div className='container mx-auto px-4 sm:px-6 lg:px-8 xl:px-12 py-8 md:py-12'>
        {/* العنوان - أنيميشن المحتوى */}
        <motion.div
          className='mb-6 md:mb-8 relative z-10'
          initial={{ opacity: 0, y: 24 }}
          whileInView={{ opacity: 1, y: 0, transition: { duration: 0.5, ease: 'easeOut' } }}
          viewport={{ once: true }}>
          <h2 className='text-center text-2xl md:text-3xl lg:text-4xl font-semibold text-gray-900 leading-tight relative z-10'>
            {translations?.fast_page?.speed_advantage?.title || 'ما الذي يميزنا'}
          </h2>
        </motion.div>

        {/* الكروت - شبكة 3x2 */}
        <div className='grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 md:gap-6'>
          {advantages.map((item, index) => (
            <motion.div
              key={`adv-${index}`}
              initial={{ opacity: 0, y: 50 }}
              whileInView={{
                opacity: 1,
                y: 0,
                transition: { duration: 0.4, ease: 'easeOut', delay: index * 0.08 },
              }}
              viewport={{ once: true }}
              className='bg-white rounded-lg border border-gray-200 shadow-md hover:shadow-lg transition-shadow p-4 md:p-6 flex flex-col items-center text-center'>
              <div className='mb-4'>
                <Image
                  src={item.icon}
                  alt={item.alt}
                  width={60}
                  height={60}
                  className={`object-contain ${index % 3 === 0 ? 'animate-icon-pulse' : index % 3 === 1 ? 'animate-icon-pulse animate-icon-pulse-delay-1' : 'animate-icon-pulse animate-icon-pulse-delay-2'}`}
                />
              </div>
              <h3 className='text-sm md:text-base font-semibold text-gray-900 mb-2'>
                {item.title}
              </h3>
              <p className='text-xs md:text-sm text-gray-600 leading-relaxed'>
                {item.description}
              </p>
            </motion.div>
          ))}
        </div>
      </div>
    </section>
  );
};

export default SpeedAdvantage;
