'use client';

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

const WhyUsSection = () => {
  let { translations, dir } = useTranslator();
  const fallbackCards = [
    {
      title: translations['location_one_title'],
      description: translations['makeYourGroup'],
    },
    {
      title: translations['location_one_title'],
      description: translations['makeYourGroup'],
    },
    {
      title: translations['location_one_title'],
      description: translations['makeYourGroup'],
    },
  ];
  const cards = translations?.security_page?.why_us?.cards || fallbackCards;
  const cardIcons = [
    '/images/icon/security.svg',
    '/images/icon/firewall.svg',
    '/images/icon/malware-protection.svg',
  ];
  const title = translations?.security_page?.why_us?.title || translations['why_choose_us_title'];
  const subtitle = translations?.security_page?.why_us?.subtitle || translations['why_choose_us_subtitle'];
  const fallbackItems = [
    'اكتشاف التهديدات المتقدمة والاستجابة لها.',
    'حماية البريد الإلكتروني والأرشفة.',
    'التعافي من الكوارث المستند إلى السحابة.',
    'إدارة ومراقبة مركزية.',
    'إدارة ومراقبة مركزية.',
    'إدارة ومراقبة مركزية.',
  ];
  const items = translations?.security_page?.why_us?.items || fallbackItems;

  return (
    <section className='relative bg-white pt-0 pb-12 md:pb-16 -mt-10 md:-mt-16 w-full' dir={dir} style={{overflowX:'unset'}}>
   
       {/* Background Graphic on Sides - Pulled up to be opposite the title */}
      <div className='absolute inset-x-0 top-[-20%] h-[800px] pointer-events-none z-0'>
        <img 
          src='/images/right-black-graphic1.svg' 
          alt='bg-left' 
          className='absolute left-0 top-0 h-full w-auto opacity-40 transform scale-x-[-1]'
        />
        <img 
          src='/images/right-black-graphic1.svg' 
          alt='bg-right' 
          className='absolute right-0 top-0 h-full w-auto opacity-40'
        />
      </div>

      <div className='container mx-auto px-4 sm:px-6 lg:px-8 relative z-10'>
        {/* العنوان والوصف - أنيميشن المحتوى */}
        <motion.div
          className='py-6 md:py-8 text-center'
          initial={{ opacity: 0, y: 24 }}
          whileInView={{ opacity: 1, y: 0, transition: { duration: 0.5, ease: 'easeOut' } }}
          viewport={{ once: true }}>
          <p className='text-2xl sm:text-3xl md:text-4xl font-bold text-[#2B1F51] mb-3 md:mb-4'>
            {title}
          </p>
          <p className='text-sm sm:text-base md:text-lg font-medium text-[#2B1F51] pt-3 md:pt-4 px-4 max-w-3xl mx-auto'>
            {subtitle}
          </p>
        </motion.div>

        {/* الكروت */}
        <div className='grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 sm:gap-6 md:gap-8 w-full pt-6 md:pt-8 items-stretch'>
          {cards.map((card, index) => (
            <motion.div
              initial={{ opacity: 0, y: 100 }}
              whileInView={{
                opacity: 1,
                y: 0,
                transition: { duration: 0.4, ease: 'easeOut' },
              }}
              viewport={{ once: true }}
              key={index}
              className='bg-white rounded-xl sm:rounded-2xl border border-gray-200 shadow-md hover:shadow-lg transition-all duration-300 p-4 sm:p-6 h-full flex flex-col justify-between'>
              <div className='flex flex-col gap-3 sm:gap-4 flex-grow'>
                <img
                  src={cardIcons[index % cardIcons.length]}
                  alt={card.title || 'Security feature'}
                  width={50}
                  height={50}
                  className='w-12 h-12 sm:w-14 sm:h-14 md:w-16 md:h-16 object-contain self-center'
                />
                <p className='font-bold text-base sm:text-lg text-center text-[#092346]'>{card.title}</p>
                <p className='font-normal text-xs sm:text-sm text-gray-600 text-justify leading-relaxed'>
                  {card.description}
                </p>
              </div>
            </motion.div>
          ))}
        </div>

        {/* قائمة التفاصيل - بعد الكروت - أنيميشن المحتوى */}
        <motion.div
          className='mt-8 md:mt-12'
          initial={{ opacity: 0, y: 20 }}
          whileInView={{ opacity: 1, y: 0, transition: { duration: 0.5, ease: 'easeOut' } }}
          viewport={{ once: true }}>
          <div className='grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 md:gap-6 max-w-5xl mx-auto'>
            {items.map((item, index) => (
              <div
                key={index}
                className='flex items-start gap-3'>
                <svg
                  className='w-5 h-5 text-black flex-shrink-0 mt-0.5'
                  fill='none'
                  stroke='currentColor'
                  strokeWidth='2'
                  viewBox='0 0 24 24'>
                  <circle cx='12' cy='12' r='10' stroke='currentColor' strokeWidth='2' />
                  <path
                    d='M9 12l2 2 4-4'
                    stroke='currentColor'
                    strokeWidth='2'
                    strokeLinecap='round'
                    strokeLinejoin='round'
                  />
                </svg>
                <span className='text-sm md:text-base text-gray-800 font-medium leading-relaxed'>
                  {item}
                </span>
              </div>
            ))}
          </div>
        </motion.div>
      </div>
    </section>
  );
};

export default WhyUsSection;
