import React, { useState } from 'react'
import { Link, useNavigate } from 'react-router-dom'

export default function HeroSection() {
  const [email, setEmail] = useState('')
  const [isGoogleAuthenticated, setIsGoogleAuthenticated] = useState(false)
  const [googleUser] = useState({ name: 'Nextv', email: 'nextv.stream@gmail.com', initial: 'N' })
  const navigate = useNavigate()

  const handleSubmit = (e: React.FormEvent) => {
    e.preventDefault()
    navigate(`/auth/register?email=${encodeURIComponent(email)}`)
  }

  const handleGoogleLogin = () => {
    // Demo stub for OAuth flow
    setTimeout(() => setIsGoogleAuthenticated(true), 600)
  }

  const handleGoogleContinue = () => {
    navigate('/broadcasts')
  }

  return (
    <section className="relative bg-white py-20 lg:py-32">
      <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
        <div className="grid lg:grid-cols-2 gap-16 items-center">
          {/* Left Content */}
          <div className="space-y-8">
            <div className="space-y-6">
              <h1 className="text-4xl lg:text-6xl font-black text-gray-900 leading-tight">
                La manera más sencilla de
                <br />
                <span className="text-gray-900">grabar y transmitir</span>
                <br />
                <span className="text-gray-900">en vivo</span>
              </h1>

              <p className="text-xl text-gray-600 leading-relaxed max-w-lg">
                AvanzaCast es un estudio profesional para grabar y hacer transmisiones en vivo desde tu
                navegador. Graba contenido o transmite en vivo a Facebook, YouTube y otras plataformas.
              </p>

              <div className="bg-blue-50 border border-blue-200 rounded-lg p-4">
                <div className="flex items-start">
                  <div className="text-blue-600 mr-3 mt-0.5">ℹ️</div>
                  <div>
                    <p className="text-blue-900 font-medium">¡Te refieres a AvanzaCast!</p>
                    <p className="text-blue-700 text-sm">Recibirás una prueba gratuita de 14 días. No se requiere tarjeta.</p>
                  </div>
                </div>
              </div>
            </div>
          </div>

          {/* Right Content - Registration Form */}
          <div className="bg-white rounded-2xl shadow-xl border border-gray-200 p-6 max-w-md mx-auto">
            <div className="mb-4">
              {!isGoogleAuthenticated ? (
                <button
                  onClick={handleGoogleLogin}
                  className="w-full flex items-center justify-center px-4 py-2.5 border border-gray-300 rounded-md shadow-sm bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition-colors"
                >
                  <div className="flex items-center space-x-3">
                    <svg className="w-5 h-5" viewBox="0 0 24 24">
                      <path fill="#4285F4" d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"/>
                      <path fill="#34A853" d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"/>
                      <path fill="#FBBC04" d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"/>
                      <path fill="#EA4335" d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"/>
                    </svg>
                    <span className="text-sm font-medium text-gray-700">Continuar con Google</span>
                  </div>
                </button>
              ) : (
                <button
                  onClick={handleGoogleContinue}
                  className="w-full flex items-center px-4 py-2.5 border border-gray-300 rounded-lg shadow-sm bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition-colors"
                >
                  <div className="w-7 h-7 bg-purple-600 rounded-full flex items-center justify-center">
                    <span className="text-white text-sm font-bold">{googleUser.initial}</span>
                  </div>
                  <div className="flex-1 ml-3">
                    <p className="text-sm font-medium text-gray-900">Continuar como {googleUser.name}</p>
                    <p className="text-xs text-gray-500">{googleUser.email}</p>
                  </div>
                  <svg className="w-4 h-4 text-gray-400" viewBox="0 0 24 24" fill="currentColor">
                    <path d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"/>
                  </svg>
                </button>
              )}
            </div>

            <div className="relative mb-4">
              <div className="absolute inset-0 flex items-center">
                <div className="w-full border-t border-gray-200"></div>
              </div>
              <div className="relative flex justify-center text-sm">
                <span className="px-3 bg-white text-gray-500">O continúa con tu correo</span>
              </div>
            </div>

            <form onSubmit={handleSubmit} className="space-y-4">
              <div>
                <input
                  type="email"
                  value={email}
                  onChange={(e) => setEmail(e.target.value)}
                  placeholder="Ingresa tu dirección de correo electrónico"
                  className="w-full px-6 py-4 text-base border-2 border-gray-300 rounded-xl focus:ring-4 focus:ring-blue-500/20 focus:border-blue-500 transition-all duration-200 placeholder:text-gray-500 hover:border-gray-400 shadow-sm hover:shadow-md"
                  required
                />
              </div>

              <button
                type="submit"
                className="w-full bg-gradient-to-r from-blue-600 to-blue-700 hover:from-blue-700 hover:to-blue-800 text-white py-4 px-6 rounded-xl font-bold text-base transition-all duration-200 transform hover:scale-105 hover:shadow-lg active:scale-95 shadow-md"
              >
                ¡Empiezo gratis ahora!
              </button>

              <div className="text-center py-2">
                <p className="text-green-600 font-medium text-xs">¡Confiado por más de 12,000,000 creadores!</p>
              </div>

              <div className="text-xs text-gray-500 text-center leading-tight">
                <p>
                  Al continuar, aceptas nuestros{' '}
                  <Link to="/terms" className="text-blue-600 hover:underline">
                    Términos de Servicio
                  </Link>
                  , {' '}
                  <Link to="/privacy-policy" className="text-blue-600 hover:underline">
                    Política de Uso
                  </Link>
                  , y reconoces nuestra{' '}
                  <Link to="/privacy" className="text-blue-600 hover:underline">
                    Política de Privacidad
                  </Link>
                  .
                </p>
              </div>

              <div className="text-center pt-2">
                <p className="text-sm text-gray-600">
                  ¿Ya usas AvanzaCast?{' '}
                  <Link to="/auth/login" className="text-blue-600 hover:underline font-medium">
                    Inicia sesión
                  </Link>
                  .
                </p>
              </div>
            </form>
          </div>
        </div>
      </div>
    </section>
  )
}
