'use client';

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

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

  const ICON_BASE = '/images/icon';
  const features = [
    {
      icon: `${ICON_BASE}/cloud-hosting.svg`,
      label: translations.cloudTigers?.virtualServices || 'مخدمات افتراضية',
    },
    {
      icon: `${ICON_BASE}/ssd-storage.svg`,
      label: translations.cloudTigers?.storageVolumes || 'أحجام تخزين',
    },
    {
      icon: `${ICON_BASE}/network-1gbps.svg`,
      label: translations.cloudTigers?.networks || 'شبكات',
    },
    {
      icon: `${ICON_BASE}/scalability.svg`,
      label: translations.cloudTigers?.loadBalancers || 'موازين الأحمال',
    },
  ];

  const containerVariants = {
    hidden: { opacity: 0 },
    visible: {
      opacity: 1,
      transition: {
        staggerChildren: 0.1,
      },
    },
  };

  const itemVariants = {
    hidden: { opacity: 0, y: 30 },
    visible: {
      opacity: 1,
      y: 0,
      transition: { duration: 0.5, ease: 'easeOut' },
    },
  };

  return (
    <section
      className='relative pt-20 pb-16 md:pt-28 md:pb-20 mt-8 md:-mt-16 bg-white overflow-hidden'
      dir={dir}
      style={{
        backgroundImage: `url('/images/pages/clouds-graph 1.svg')`,
        backgroundSize: 'cover',
        backgroundPosition: 'center top',
        backgroundRepeat: 'no-repeat',
      }}>

      <div className='container mx-auto px-4 md:px-6 text-center'>
        <motion.h2
          className='text-2xl md:text-3xl lg:text-[32px] font-bold mb-4 text-[#1a1a2e]'
          initial={{ opacity: 0, y: 30 }}
          whileInView={{ opacity: 1, y: 0 }}
          viewport={{ once: true }}
          transition={{ duration: 0.6 }}>
          {translations.cloudTigers?.featuresTitle ||
            'بنية تحتية مرنة، سهلة الإدارة وقابلة للتوسع'}
        </motion.h2>

        <motion.p
          className='text-sm md:text-base text-gray-500 max-w-2xl mx-auto mb-10 leading-relaxed'
          initial={{ opacity: 0, y: 20 }}
          whileInView={{ opacity: 1, y: 0 }}
          viewport={{ once: true }}
          transition={{ duration: 0.5, delay: 0.2 }}>
          {translations.cloudTigers?.featuresDescription ||
            'تجمع سحابة العنكبوت Cloud LS كلا من موارد الحوسبة، التخزين والشبكات إضافة إلى أدوات التحليلات والمراقبة المتقدمة في منصة سحابية واحدة سهلة الاستخدام.'}
        </motion.p>

        <motion.h3
          className='text-lg md:text-xl font-semibold mb-10 text-[#1a1a2e]'
          initial={{ opacity: 0, y: 20 }}
          whileInView={{ opacity: 1, y: 0 }}
          viewport={{ once: true }}
          transition={{ duration: 0.5, delay: 0.3 }}>
          {translations.cloudTigers?.resourcesTitle ||
            'موارد سحابية يمكن تثبيتها في دقائق'}
        </motion.h3>

        <motion.div
          className='flex flex-wrap justify-center gap-12 md:gap-16 lg:gap-20 max-w-4xl mx-auto'
          initial='hidden'
          whileInView='visible'
          viewport={{ once: true }}
          variants={containerVariants}>
          {features.map((feature, index) => (
            <motion.div
              key={index}
              className='flex flex-col items-center text-center'
              variants={itemVariants}
              whileHover={{ scale: 1.05, transition: { duration: 0.2 } }}>
              <div className='w-16 h-16 md:w-20 md:h-20 flex items-center justify-center mb-3'>
                <img
                  src={feature.icon}
                  alt={feature.label}
                  className='w-full h-full object-contain'
                />
              </div>
              <p className='text-sm md:text-base font-medium text-[#1a1a2e]'>
                {feature.label}
              </p>
            </motion.div>
          ))}
        </motion.div>
      </div>
    </section>
  );
};

export default CloudFeaturesSection;
