"use client";

import { useTranslations, useLocale } from 'next-intl';
import Link from 'next/link';
import { motion } from 'framer-motion';
import { useModal } from '@/context/ModalContext';
import Image from 'next/image';
import { usePathname, useRouter } from 'next/navigation';

export default function Footer() {
  const t = useTranslations('footer');
  const locale = useLocale();
  const { openModal } = useModal();
  const pathname = usePathname();
  const router = useRouter();

  // Link oluşturma helper'ı (mevcut dil için)
  const createLocalizedHref = (path: string) => `/${locale}${path}`;

  // Sayfa içi bağlantı yardımcı fonksiyonu
  const handleScrollToSection = (e: React.MouseEvent<HTMLAnchorElement>, sectionId: string) => {
    e.preventDefault();
    
    // Ana sayfa dışındaysa ana sayfaya git, sonra o bölüme kaydır
    if (pathname !== `/${locale}`) {
      router.push(`/${locale}/#${sectionId.replace('#', '')}`);
    } else {
      // Aynı sayfadaysa direkt olarak o bölüme kaydır
      const section = document.getElementById(sectionId.replace('#', ''));
      if (section) {
        section.scrollIntoView({ behavior: 'smooth' });
      }
    }
  };

  // Sosyal medya bağlantıları
  const socialLinks = [
    {
      name: 'Twitter',
      href: 'https://twitter.com/gencmusiad',
      icon: (
        <svg className="w-5 h-5" fill="currentColor" viewBox="0 0 24 24" aria-hidden="true">
          <path d="M8.29 20.251c7.547 0 11.675-6.253 11.675-11.675 0-.178 0-.355-.012-.53A8.348 8.348 0 0022 5.92a8.19 8.19 0 01-2.357.646 4.118 4.118 0 001.804-2.27 8.224 8.224 0 01-2.605.996 4.107 4.107 0 00-6.993 3.743 11.65 11.65 0 01-8.457-4.287 4.106 4.106 0 001.27 5.477A4.072 4.072 0 012.8 9.713v.052a4.105 4.105 0 003.292 4.022 4.095 4.095 0 01-1.853.07 4.108 4.108 0 003.834 2.85A8.233 8.233 0 012 18.407a11.616 11.616 0 006.29 1.84" />
        </svg>
      ),
    },
    {
      name: 'Instagram',
      href: 'https://instagram.com/gencmusiad',
      icon: (
        <svg className="w-5 h-5" fill="currentColor" viewBox="0 0 24 24" aria-hidden="true">
          <path fillRule="evenodd" d="M12.315 2c2.43 0 2.784.013 3.808.06 1.064.049 1.791.218 2.427.465a4.902 4.902 0 011.772 1.153 4.902 4.902 0 011.153 1.772c.247.636.416 1.363.465 2.427.048 1.067.06 1.407.06 4.123v.08c0 2.643-.012 2.987-.06 4.043-.049 1.064-.218 1.791-.465 2.427a4.902 4.902 0 01-1.153 1.772 4.902 4.902 0 01-1.772 1.153c-.636.247-1.363.416-2.427.465-1.067.048-1.407.06-4.123.06h-.08c-2.643 0-2.987-.012-4.043-.06-1.064-.049-1.791-.218-2.427-.465a4.902 4.902 0 01-1.772-1.153 4.902 4.902 0 01-1.153-1.772c-.247-.636-.416-1.363-.465-2.427-.047-1.024-.06-1.379-.06-3.808v-.63c0-2.43.013-2.784.06-3.808.049-1.064.218-1.791.465-2.427a4.902 4.902 0 011.153-1.772A4.902 4.902 0 015.45 2.525c.636-.247 1.363-.416 2.427-.465C8.901 2.013 9.256 2 11.685 2h.63zm-.081 1.802h-.468c-2.456 0-2.784.011-3.807.058-.975.045-1.504.207-1.857.344-.467.182-.8.398-1.15.748-.35.35-.566.683-.748 1.15-.137.353-.3.882-.344 1.857-.047 1.023-.058 1.351-.058 3.807v.468c0 2.456.011 2.784.058 3.807.045.975.207 1.504.344 1.857.182.466.399.8.748 1.15.35.35.683.566 1.15.748.353.137.882.3 1.857.344 1.054.048 1.37.058 4.041.058h.08c2.597 0 2.917-.01 3.96-.058.976-.045 1.505-.207 1.858-.344.466-.182.8-.398 1.15-.748.35-.35.566-.683.748-1.15.137-.353.3-.882.344-1.857.048-1.055.058-1.37.058-4.041v-.08c0-2.597-.01-2.917-.058-3.96-.045-.976-.207-1.505-.344-1.858a3.097 3.097 0 00-.748-1.15 3.098 3.098 0 00-1.15-.748c-.353-.137-.882-.3-1.857-.344-1.023-.047-1.351-.058-3.807-.058zM12 6.865a5.135 5.135 0 110 10.27 5.135 5.135 0 010-10.27zm0 1.802a3.333 3.333 0 100 6.666 3.333 3.333 0 000-6.666zm5.338-3.205a1.2 1.2 0 110 2.4 1.2 1.2 0 010-2.4z" clipRule="evenodd" />
        </svg>
      ),
    },
    {
      name: 'LinkedIn',
      href: 'https://linkedin.com/company/gencmusiad',
      icon: (
        <svg className="w-5 h-5" fill="currentColor" viewBox="0 0 24 24" aria-hidden="true">
          <path d="M19 0h-14c-2.761 0-5 2.239-5 5v14c0 2.761 2.239 5 5 5h14c2.762 0 5-2.239 5-5v-14c0-2.761-2.238-5-5-5zm-11 19h-3v-11h3v11zm-1.5-12.268c-.966 0-1.75-.79-1.75-1.764s.784-1.764 1.75-1.764 1.75.79 1.75 1.764-.783 1.764-1.75 1.764zm13.5 12.268h-3v-5.604c0-3.368-4-3.113-4 0v5.604h-3v-11h3v1.765c1.396-2.586 7-2.777 7 2.476v6.759z" />
        </svg>
      ),
    },
    {
      name: 'YouTube',
      href: 'https://www.youtube.com/channel/UClEhsOUwxLxgUi2Vg5-od3A',
      icon: (
        <svg className="w-5 h-5" fill="currentColor" viewBox="0 0 24 24" aria-hidden="true">
          <path d="M23.498 6.186a3.016 3.016 0 0 0-2.122-2.136C19.505 3.545 12 3.545 12 3.545s-7.505 0-9.377.505A3.017 3.017 0 0 0 .502 6.186C0 8.07 0 12 0 12s0 3.93.502 5.814a3.016 3.016 0 0 0 2.122 2.136c1.871.505 9.376.505 9.376.505s7.505 0 9.377-.505a3.015 3.015 0 0 0 2.122-2.136C24 15.93 24 12 24 12s0-3.93-.502-5.814zM9.545 15.568V8.432L15.818 12l-6.273 3.568z" />
        </svg>
      ),
    },
  ];

  // Footer linkleri
  const footerLinks = [
    {
      title: t('company'),
      links: [
        { name: t('about'), href: '#about', section: true },
        { name: t('services'), href: '#services', section: true },
        { name: t('partners'), href: '#partners', section: true },
        { name: t('apply'), href: 'https://gm2.ifollow.com.tr/register', isModal: false, directLink: true, external: true },
        { name: locale === 'tr' ? 'İletişim' : 'Contact', href: "https://gencmusiad.org.tr/bize-ulasin/", isModal: false, directLink: true, external: true },
      ],
    }
  ];

  // Animasyon varyasyonları
  const footerVariants = {
    hidden: { opacity: 0 },
    visible: {
      opacity: 1,
      transition: {
        staggerChildren: 0.1,
      },
    },
  };

  const itemVariants = {
    hidden: { opacity: 0, y: 20 },
    visible: {
      opacity: 1,
      y: 0,
      transition: {
        duration: 0.6,
        ease: [0.22, 1, 0.36, 1],
      },
    },
  };

  return (
    <footer className="relative bg-gray-900 text-white overflow-hidden">
      {/* Grafik Elementleri */}
      <div className="absolute inset-0 overflow-hidden pointer-events-none">
        <div className="absolute top-0 left-1/4 w-96 h-96 bg-blue-600/20 rounded-full blur-3xl transform -translate-y-1/2"></div>
        <div className="absolute bottom-0 right-1/4 w-64 h-64 bg-indigo-600/20 rounded-full blur-3xl transform translate-y-1/2"></div>
      </div>
      
      {/* Ana İçerik */}
      <div className="relative">
        <div className="mx-auto max-w-7xl px-6 pb-8 pt-16 lg:px-8">
          <motion.div 
            className="xl:grid xl:grid-cols-3 xl:gap-8"
            variants={footerVariants}
            initial="hidden"
            whileInView="visible"
            viewport={{ once: true, margin: "-10%" }}
          >
            {/* Kurumsal Bilgiler */}
            <motion.div 
              className="space-y-8 xl:col-span-1"
              variants={itemVariants}
            >
              <Link 
                href={createLocalizedHref('/')}
                className="inline-block relative"
              >
                <div className="relative w-auto h-24">
                  <Image 
                    src="/logos/logogm2.png"
                    alt="GM2 Logo"
                    width={250}
                    height={125}
                    className="object-contain h-full w-auto dark:filter dark:brightness-110 drop-shadow-[0_0_3px_rgba(255,255,255,0.3)]"
                    priority
                  />
                  <motion.div 
                    className="absolute -inset-2 rounded-xl blur-sm opacity-10"
                    animate={{ 
                      opacity: [0.05, 0.15, 0.05],
                      background: ['rgba(59, 130, 246, 0.2)', 'rgba(99, 102, 241, 0.2)', 'rgba(59, 130, 246, 0.2)']
                    }}
                    transition={{ duration: 4, repeat: Infinity }}
                  />
                </div>
              </Link>
              
              <p className="text-gray-300 max-w-md text-base leading-relaxed">
                {t('description')}
              </p>
              
              <div className="flex space-x-5">
                {socialLinks.map((item) => (
                  <motion.a
                    key={item.name}
                    href={item.href}
                    target="_blank"
                    rel="noopener noreferrer"
                    className="text-gray-400 hover:text-white transition-colors duration-300"
                    whileHover={{ scale: 1.1 }}
                    whileTap={{ scale: 0.95 }}
                  >
                    <span className="sr-only">{item.name}</span>
                    {item.icon}
                  </motion.a>
                ))}
              </div>
            </motion.div>
            
            {/* Bağlantı Kategorileri */}
            <motion.div 
              className="mt-16 xl:mt-0 xl:col-span-2 grid grid-cols-1 md:grid-cols-2 gap-8"
              variants={itemVariants}
            >
              {/* Kurumsal Menü */}
              <div>
                <h3 className="font-semibold text-white tracking-wider uppercase text-base">
                  {t('company')}
                </h3>
                <ul role="list" className="mt-4 space-y-3">
                  {footerLinks[0].links.map((item) => (
                    <li key={item.name}>
                      {item.isModal ? (
                        <button 
                          onClick={openModal}
                          className="text-base text-gray-300 hover:text-white transition-colors duration-300 inline-block"
                        >
                          {item.name}
                        </button>
                      ) : item.directLink ? (
                        <a 
                          href={item.href} 
                          className="text-base text-gray-300 hover:text-white transition-colors duration-300 inline-block"
                          target={item.external ? "_blank" : undefined}
                          rel={item.external ? "noopener noreferrer" : undefined}
                        >
                          {item.name}
                        </a>
                      ) : item.section ? (
                        <a
                          href={item.href}
                          onClick={(e) => handleScrollToSection(e, item.href)}
                          className="text-base text-gray-300 hover:text-white transition-colors duration-300 inline-block"
                        >
                          {item.name}
                        </a>
                      ) : (
                        <Link 
                          href={item.href} 
                          className="text-base text-gray-300 hover:text-white transition-colors duration-300 inline-block"
                        >
                          {item.name}
                        </Link>
                      )}
                    </li>
                  ))}
                </ul>
              </div>
              
              {/* İletişim Bilgileri */}
              <div>
                <h3 className="font-semibold text-white tracking-wider uppercase text-base">
                  {t('contact')}
                </h3>
                <ul role="list" className="mt-4 space-y-4">
                  <li>
                    <div className="flex items-start">
                      <div className="flex-shrink-0 mt-1">
                        <svg className="w-6 h-6 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                          <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z"></path>
                          <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M15 11a3 3 0 11-6 0 3 3 0 016 0z"></path>
                        </svg>
                      </div>
                      <div className="ml-3">
                        <p className="text-base text-gray-300">{t('contactInfo.addressLine')}</p>
                        <p className="text-sm text-gray-400 mt-1">{t('contactInfo.country')}</p>
                      </div>
                    </div>
                  </li>
                  <li>
                    <div className="flex items-start">
                      <div className="flex-shrink-0 mt-1">
                        <svg className="w-6 h-6 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                          <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"></path>
                        </svg>
                      </div>
                      <div className="ml-3">
                        <p className="text-base text-gray-300">{t('contactInfo.phoneNumber')}</p>
                        <p className="text-base text-gray-300">{t('contactInfo.phoneNumber2')}</p>
                        <p className="text-sm text-gray-400 mt-1">{t('contactInfo.phoneHours')}</p>
                      </div>
                    </div>
                  </li>
                  <li>
                    <div className="flex items-start">
                      <div className="flex-shrink-0 mt-1">
                        <svg className="w-6 h-6 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                          <path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"></path>
                        </svg>
                      </div>
                      <div className="ml-3">
                        <p className="text-base text-gray-300">{t('contactInfo.emailAddress')}</p>
                        <p className="text-sm text-gray-400 mt-1">{t('contactInfo.emailResponse')}</p>
                      </div>
                    </div>
                  </li>
                </ul>
              </div>
            </motion.div>
          </motion.div>
          
          {/* Alt Bilgi ve Telif Hakkı */}
          <motion.div 
            className="mt-16 border-t border-gray-800 pt-8 flex flex-col md:flex-row justify-between items-center"
            variants={itemVariants}
            initial="hidden"
            whileInView="visible"
            viewport={{ once: true }}
          >
            <p className="text-base text-gray-400">
              &copy; {new Date().getFullYear()} MÜSİAD GM2 {t('rights')}
            </p>
            
            <div className="mt-4 md:mt-0">
              <p className="text-xs text-gray-500 italic">UpcyTech</p>
            </div>
          </motion.div>
        </div>
      </div>
    </footer>
  );
} 