import { Button } from "@/components/ui/button";
import { ArrowRight, Play, Star } from "lucide-react";
import { Link } from "react-router-dom";
import { lazy, Suspense, useState } from "react";
import heroImage from "@/assets/hero-coach.jpg";

// Componente de imagem otimizada com lazy loading
const OptimizedImage = ({ src, alt, className }: { src: string; alt: string; className: string }) => {
  const [imageLoaded, setImageLoaded] = useState(false);
  const [imageError, setImageError] = useState(false);

  return (
    <div className="relative">
      {!imageLoaded && !imageError && (
        <div className={`${className} bg-muted animate-pulse flex items-center justify-center`}>
          <div className="text-muted-foreground">Carregando...</div>
        </div>
      )}
      <img 
        src={src}
        alt={alt}
        className={`${className} transition-opacity duration-300 ${imageLoaded ? 'opacity-100' : 'opacity-0'}`}
        loading="lazy"
        onLoad={() => setImageLoaded(true)}
        onError={() => setImageError(true)}
        style={{ display: imageLoaded || imageError ? 'block' : 'none' }}
      />
      {imageError && (
        <div className={`${className} bg-muted flex items-center justify-center`}>
          <div className="text-muted-foreground">Erro ao carregar imagem</div>
        </div>
      )}
    </div>
  );
};

const Hero = () => {
  return (
    <section className="relative min-h-screen flex items-center justify-center overflow-hidden">
      {/* Background Gradient */}
      <div className="absolute inset-0 bg-gradient-hero opacity-10" />
      
      {/* Hero Content */}
      <div className="container mx-auto px-4 py-20 relative z-10">
        <div className="grid lg:grid-cols-2 gap-12 items-center">
          {/* Left Content */}
          <div className="text-center lg:text-left">
            <div className="flex items-center gap-2 justify-center lg:justify-start mb-6">
              <div className="flex">
                {[...Array(5)].map((_, i) => (
                  <Star key={i} className="w-5 h-5 fill-primary text-primary" />
                ))}
              </div>
              <span className="text-muted-foreground">+200 clientes transformados</span>
            </div>
            
            <h1 className="text-5xl lg:text-7xl font-poppins font-bold mb-6 leading-tight">
              Transforme seu
              <span className="bg-gradient-primary bg-clip-text text-transparent block">
                corpo e mente
              </span>
            </h1>
            
            <p className="text-xl text-muted-foreground mb-8 leading-relaxed max-w-xl">
              Coach fitness especializado em transformações reais. Treinos personalizados, 
              nutrição planejada e acompanhamento completo para você alcançar seus objetivos.
            </p>
            
            <div className="flex flex-col sm:flex-row gap-4 justify-center lg:justify-start">
              <Button variant="hero" size="lg" className="group" asChild>
                <Link to="/consultoria">
                  Comece sua transformação
                  <ArrowRight className="ml-2 h-5 w-5 group-hover:translate-x-1 transition-transform" />
                </Link>
              </Button>
              
              <Button variant="outline" size="lg" className="group">
                <Play className="mr-2 h-5 w-5 group-hover:scale-110 transition-transform" />
                Ver resultados
              </Button>
              
            </div>
            
            <div className="flex items-center gap-8 justify-center lg:justify-start mt-12 pt-8 border-t border-border">
              <div className="text-center">
                <div className="text-3xl font-poppins font-bold text-primary">5+</div>
                <div className="text-muted-foreground">Anos de experiência</div>
              </div>
              <div className="text-center">
                <div className="text-3xl font-poppins font-bold text-primary">200+</div>
                <div className="text-muted-foreground">Clientes atendidos</div>
              </div>
              <div className="text-center">
                <div className="text-3xl font-poppins font-bold text-primary">95%</div>
                <div className="text-muted-foreground">Taxa de sucesso</div>
              </div>
            </div>
          </div>
          
          {/* Right Image */}
          <div className="relative">
            <div className="relative rounded-2xl overflow-hidden shadow-strong">
              <OptimizedImage 
                src={heroImage} 
                alt="Junior Campos - Fitness Coach" 
                className="w-full h-[600px] object-cover"
              />
              <div className="absolute inset-0 bg-gradient-to-t from-black/20 to-transparent" />
            </div>
            
            {/* Floating Stats */}
            <div className="absolute -top-4 -right-4 bg-card/90 backdrop-blur-sm rounded-xl p-4 shadow-medium border border-border">
              <div className="text-center">
                <div className="text-2xl font-poppins font-bold text-primary">98%</div>
                <div className="text-sm text-muted-foreground">Satisfação</div>
              </div>
            </div>
            
            <div className="absolute -bottom-4 -left-4 bg-card/90 backdrop-blur-sm rounded-xl p-4 shadow-medium border border-border">
              <div className="text-center">
                <div className="text-2xl font-poppins font-bold text-primary">24/7</div>
                <div className="text-sm text-muted-foreground">Suporte</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>
  );
};

export default Hero;