"use client"

import { useState } from 'react'
import { Button } from './ui/button'
import { Facebook, Instagram, Gamepad2 } from 'lucide-react'
import { getServerInfo, getServerAddress, connectToGameServer } from '../lib/mtaServer'
import { useTranslations } from 'next-intl'

export default function Footer() {
  const t = useTranslations('footer')
  const [email, setEmail] = useState('')
  const [serverInfo] = useState(getServerInfo())

  const handleNewsletterSubmit = (e: React.FormEvent) => {
    e.preventDefault()
    // Handle newsletter subscription
    
    setEmail('')
  }

  const connectToServer = () => {
    connectToGameServer()
  }

  const joinDiscord = () => {
            window.open('https://discord.gg/6rjeA3TPBn', '_blank')
  }

  return (
    <footer className="bg-card backdrop-blur-sm border-t border-border">
      <div className="container mx-auto px-4 py-6">
        <div className="grid md:grid-cols-4 gap-6">
          {/* Brand Section */}
          <div className="md:col-span-2">
            <div className="flex items-center space-x-3 mb-4">
              <img src="/images/logo.webp" alt="UrbanGamers" className="w-10 h-10 rounded" />
              <h3 className="text-2xl font-bold" style={{ color: '#0087FF' }}>UrbanGamers</h3>
            </div>
            <p className="text-muted-foreground mb-4 max-w-md">
              {t('description')}
            </p>
            
            {/* Server Connection & Discord Section */}
            <div className="space-y-3 mb-4">
              {/* MTA Server Connection */}
              <div className="bg-card border border-primary/20 rounded-2xl p-2 shadow">
                <div className="flex items-center justify-between">
                  <div className="flex items-center space-x-3">
                    <div className="w-9 h-9 bg-[#0087FF]/15 rounded-xl flex items-center justify-center">
                      <Gamepad2 className="w-5 h-5" style={{ color: '#0087FF' }} />
                    </div>
                    <div>
                      <p className="text-muted-foreground text-sm">{t('serverIp')}</p>
                      <p className="text-foreground text-sm font-semibold">
                        {getServerAddress(serverInfo.ip, serverInfo.port)}
                      </p>
                    </div>
                  </div>
                  <Button 
                    className="bg-primary text-primary-foreground hover:bg-primary/90 font-semibold px-4 py-2 rounded-xl transition-all duration-200"
                    onClick={connectToServer}
                  >
                    <Gamepad2 className="w-4 h-4 mr-2" />
                    {t('connectNow')}
                  </Button>
                </div>
              </div>

              {/* Discord Server */}
              <div className="bg-card border border-primary/20 rounded-2xl p-2 shadow">
                <div className="flex items-center justify-between">
                  <div className="flex items-center space-x-3">
                    <div className="w-9 h-9 bg-[#0087FF]/15 rounded-xl flex items-center justify-center text-[#0087FF]">
                      <svg className="w-5 h-5" viewBox="0 0 24 24" fill="currentColor">
                        <path d="M20.317 4.3698a19.7913 19.7913 0 00-4.8851-1.5152.0741.0741 0 00-.0785.0371c-.211.3753-.4447.8648-.6083 1.2495-1.8447-.2762-3.68-.2762-5.4868 0-.1636-.3933-.4058-.8742-.6177-1.2495a.077.077 0 00-.0785-.037 19.7363 19.7363 0 00-4.8852 1.515.0699.0699 0 00-.0321.0277C.5334 9.0458-.319 13.5799.0992 18.0578a.0824.0824 0 00.0312.0561c2.0528 1.5076 4.0413 2.4228 5.9929 3.0294a.0777.0777 0 00.0842-.0276c.4616-.6304.8731-1.2952 1.226-1.9942a.076.076 0 00-.0416-.1057c-.6528-.2476-1.2743-.5495-1.8722-.8923a.077.077 0 01-.0076-.1277c.1258-.0943.2517-.1923.3718-.2914a.0743.0743 0 01.0776-.0105c3.9278 1.7933 8.18 1.7933 12.0614 0a.0739.0739 0 01.0785.0095c.1202.099.246.1981.3728.2924a.077.077 0 01-.0066.1276 12.2986 12.2986 0 01-1.873.8914.0766.0766 0 00-.0407.1067c.3604.698.7719 1.3628 1.225 1.9932a.076.076 0 00.0842.0286c1.961-.6067 3.9495-1.5219 6.0023-3.0294a.077.077 0 00.0313-.0552c.5004-5.177-.8382-9.6739-3.5485-13.6604a.061.061 0 00-.0312-.0286zM8.02 15.3312c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9555-2.4189 2.157-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419-.0189 1.3332-.9555 2.4189-2.1569 2.4189zm7.9748 0c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9554-2.4189 2.1569-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.9555 2.4189-2.1568 2.4189Z"/>
                      </svg>
                    </div>
                    <div>
                      <p className="text-muted-foreground text-sm">{t('discordServer')}</p>
                      <p className="text-foreground text-sm font-semibold">
                        discord.gg/6rjeA3TPBn
                      </p>
                    </div>
                  </div>
                  <Button 
                    className="bg-primary text-primary-foreground hover:bg-primary/90 font-semibold px-4 py-2 rounded-xl transition-all duration-200"
                    onClick={joinDiscord}
                  >
                    <svg className="w-4 h-4 mr-2" viewBox="0 0 24 24" fill="currentColor">
                      <path d="M20.317 4.3698a19.7913 19.7913 0 00-4.8851-1.5152.0741.0741 0 00-.0785.0371c-.211.3753-.4447.8648-.6083 1.2495-1.8447-.2762-3.68-.2762-5.4868 0-.1636-.3933-.4058-.8742-.6177-1.2495a.077.077 0 00-.0785-.037 19.7363 19.7363 0 00-4.8852 1.515.0699.0699 0 00-.0321.0277C.5334 9.0458-.319 13.5799.0992 18.0578a.0824.0824 0 00.0312.0561c2.0528 1.5076 4.0413 2.4228 5.9929 3.0294a.0777.0777 0 00.0842-.0276c.4616-.6304.8731-1.2952 1.226-1.9942a.076.076 0 00-.0416-.1057c-.6528-.2476-1.2743-.5495-1.8722-.8923a.077.077 0 01-.0076-.1277c.1258-.0943.2517-.1923.3718-.2914a.0743.0743 0 01.0776-.0105c3.9278 1.7933 8.18 1.7933 12.0614 0a.0739.0739 0 01.0785.0095c.1202.099.246.1981.3728.2924a.077.077 0 01-.0066.1276 12.2986 12.2986 0 01-1.873.8914.0766.0766 0 00-.0407.1067c.3604.698.7719 1.3628 1.225 1.9932a.076.076 0 00.0842.0286c1.961-.6067 3.9495-1.5219 6.0023-3.0294a.077.077 0 00.0313-.0552c.5004-5.177-.8382-9.6739-3.5485-13.6604a.061.061 0 00-.0312-.0286zM8.02 15.3312c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9555-2.4189 2.157-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419-.0189 1.3332-.9555 2.4189-2.1569 2.4189zm7.9748 0c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9554-2.4189 2.1569-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.9555 2.4189-2.1568 2.4189Z"/>
                    </svg>
                    {t('joinNow')}
                  </Button>
                </div>
              </div>
            </div>
          </div>

          {/* Quick Links */}
          <div>
            <h4 className="text-lg font-semibold text-foreground mb-2">{t('quickLinks.title')}</h4>
            <ul className="space-y-1.5">
              <li><a href="#home" className="text-muted-foreground hover:text-primary transition-colors">{t('quickLinks.home')}</a></li>
              <li><a href="#how-to-play" className="text-muted-foreground hover:text-primary transition-colors">{t('quickLinks.howToPlay')}</a></li>
              <li><a href="https://discord.gg/6rjeA3TPBn" target="_blank" rel="noopener noreferrer" className="text-muted-foreground hover:text-primary transition-colors">{t('quickLinks.contact')}</a></li>
            </ul>
          </div>

          {/* Contact & Social */}
          <div>
            <h4 className="text-lg font-semibold text-foreground mb-2">{t('connectWithUs.title')}</h4>
            <div className="space-y-4">
              <div>
                <p className="text-muted-foreground text-sm mb-2">{t('connectWithUs.followUs')}</p>
                <div className="flex space-x-2.5">
                  <a
                    href="https://www.facebook.com/profile.php?id=100083956382586"
                    target="_blank"
                    rel="noopener noreferrer"
                    aria-label="Facebook"
                    className="w-9 h-9 bg-[#0087FF]/10 rounded-xl flex items-center justify-center transition-all duration-200 hover:scale-105 border border-[#0087FF]/30 group"
                  >
                    <Facebook className="w-4 h-4" style={{ color: '#8ab4ff' }} />
                  </a>
                  <a
                    href="https://www.instagram.com/urbangamers.es/"
                    target="_blank"
                    rel="noopener noreferrer"
                    aria-label="Instagram"
                    className="w-9 h-9 bg-[#0087FF]/10 rounded-xl flex items-center justify-center transition-all duration-200 hover:scale-105 border border-[#0087FF]/30 group"
                  >
                    <Instagram className="w-4 h-4" style={{ color: '#ff8a8a' }} />
                  </a>
                  <a
                    href="https://discord.gg/6rjeA3TPBn"
                    target="_blank"
                    rel="noopener noreferrer"
                    aria-label="Discord"
                    className="w-9 h-9 bg-[#0087FF]/10 rounded-xl flex items-center justify-center transition-all duration-200 hover:scale-105 border border-[#0087FF]/30 group"
                  >
                    <svg className="w-4 h-4" viewBox="0 0 24 24" fill="currentColor">
                      <path d="M20.317 4.3698a19.7913 19.7913 0 00-4.8851-1.5152.0741.0741 0 00-.0785.0371c-.211.3753-.4447.8648-.6083 1.2495-1.8447-.2762-3.68-.2762-5.4868 0-.1636-.3933-.4058-.8742-.6177-1.2495a.077.077 0 00-.0785-.037 19.7363 19.7363 0 00-4.8852 1.515.0699.0699 0 00-.0321.0277C.5334 9.0458-.319 13.5799.0992 18.0578a.0824.0824 0 00.0312.0561c2.0528 1.5076 4.0413 2.4228 5.9929 3.0294a.0777.0777 0 00.0842-.0276c.4616-.6304.8731-1.2952 1.226-1.9942a.076.076 0 00-.0416-.1057c-.6528-.2476-1.2743-.5495-1.8722-.8923a.077.077 0 01-.0076-.1277c.1258-.0943.2517-.1923.3718-.2914a.0743.0743 0 01.0776-.0105c3.9278 1.7933 8.18 1.7933 12.0614 0a.0739.0739 0 01.0785.0095c.1202.099.246.1981.3728.2924a.077.077 0 01-.0066.1276 12.2986 12.2986 0 01-1.873.8914.0766.0766 0 00-.0407.1067c.3604.698.7719 1.3628 1.225 1.9932a.076.076 0 00.0842.0286c1.961-.6067 3.9495-1.5219 6.0023-3.0294a.077.077 0 00.0313-.0552c.5004-5.177-.8382-9.6739-3.5485-13.6604a.061.061 0 00-.0312-.0286zM8.02 15.3312c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9555-2.4189 2.157-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419-.0189 1.3332-.9555 2.4189-2.1569 2.4189zm7.9748 0c-1.1825 0-2.1569-1.0857-2.1569-2.419 0-1.3332.9554-2.4189 2.1569-2.4189 1.2108 0 2.1757 1.0952 2.1568 2.419 0 1.3332-.9555 2.4189-2.1568 2.4189Z"/>
                    </svg>
                  </a>
                </div>
              </div>
            </div>
          </div>
        </div>

      </div>
    </footer>
  )
}
