import { useEffect, useRef } from 'react';
import { gsap } from 'gsap';
import { ScrollTrigger } from 'gsap/ScrollTrigger';
import { Cloud, Check, ArrowRight, TrendingUp, Zap, Globe, Server } from 'lucide-react';

gsap.registerPlugin(ScrollTrigger);

const beneficios = [
  'Redução de custos',
  'Escalabilidade',
  'Alta disponibilidade',
  'Backup automático',
];

const servicos = [
  { titulo: 'Migração para nuvem', descricao: 'Transição segura dos seus sistemas.', icon: Server },
  { titulo: 'Multi-cloud', descricao: 'Múltiplos provedores integrados.', icon: Cloud },
  { titulo: 'Cloud híbrida', descricao: 'On-premise + nuvem.', icon: Globe },
  { titulo: 'Serverless', descricao: 'Execute código sem gerenciar servidores.', icon: Zap },
];

const provedores = ['AWS', 'Azure', 'Google Cloud', 'Oracle', 'IBM'];

const CloudComputing = () => {
  const heroRef = useRef<HTMLDivElement>(null);
  const beneficiosRef = useRef<HTMLDivElement>(null);
  const servicosRef = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const ctx = gsap.context(() => {
      const heroItems = heroRef.current?.querySelectorAll('.animate-item');
      if (heroItems?.length) {
        gsap.fromTo(heroItems, { y: 50, opacity: 0 }, { y: 0, opacity: 1, duration: 0.8, stagger: 0.1, ease: 'expo.out' });
      }

      const beneficioItems = beneficiosRef.current?.querySelectorAll('.beneficio-item');
      if (beneficioItems?.length) {
        gsap.fromTo(beneficioItems, { x: -30, opacity: 0 }, { x: 0, opacity: 1, duration: 0.5, stagger: 0.05, ease: 'expo.out', scrollTrigger: { trigger: beneficiosRef.current, start: 'top 80%' } });
      }

      const servicoCards = servicosRef.current?.querySelectorAll('.servico-card');
      if (servicoCards?.length) {
        gsap.fromTo(servicoCards, { y: 50, opacity: 0 }, { y: 0, opacity: 1, duration: 0.6, stagger: 0.1, ease: 'back.out(1.7)', scrollTrigger: { trigger: servicosRef.current, start: 'top 80%' } });
      }
    });

    return () => ctx.revert();
  }, []);

  return (
    <div className="bg-[#0e0e0e] min-h-screen">
      {/* Hero */}
      <section ref={heroRef} className="pt-32 pb-20 relative overflow-hidden">
        <div className="absolute top-0 right-0 w-[600px] h-[600px] bg-[#cbf400]/5 rounded-full blur-3xl -translate-y-1/2 translate-x-1/2" />
        <div className="container-custom relative z-10">
          <div className="grid lg:grid-cols-2 gap-12 items-center">
            <div>
              <div className="animate-item flex items-center gap-2 mb-6">
                <Cloud className="w-5 h-5 text-[#cbf400]" />
                <span className="text-[#cbf400] font-semibold">Serviços</span>
                <span className="text-gray-500">/</span>
                <span className="text-white">Cloud</span>
              </div>
              <h1 className="animate-item text-4xl md:text-5xl lg:text-6xl font-black text-white mb-6">Cloud <span className="text-gradient">Computing</span></h1>
              <p className="animate-item text-xl text-gray-400 mb-8 leading-relaxed">Migre sua infraestrutura para a nuvem com segurança e escalabilidade.</p>
              <div className="animate-item flex flex-wrap gap-4">
                <a href="https://api.whatsapp.com/send?phone=551148101704&text=Olá!%20Gostaria%20de%20saber%20mais%20sobre%20Cloud" target="_blank" rel="noopener noreferrer" className="btn-primary inline-flex items-center gap-2">Solicitar avaliação<ArrowRight className="w-5 h-5" /></a>
                <a href="#servicos" className="btn-secondary">Conhecer serviços</a>
              </div>
            </div>
            <div className="animate-item relative">
              <div className="absolute -inset-4 bg-gradient-to-r from-[#cbf400]/20 to-transparent rounded-2xl blur-2xl" />
              <img src="/service-cloud.png" alt="Cloud" className="relative w-full h-auto animate-float" />
            </div>
          </div>
        </div>
      </section>

      {/* Benefícios */}
      <section ref={beneficiosRef} className="py-20 bg-[#1a1a1a]">
        <div className="container-custom">
          <div className="grid lg:grid-cols-2 gap-12 items-center">
            <div>
              <h2 className="text-3xl md:text-4xl font-black text-white mb-6">Benefícios da <span className="text-gradient">Nuvem</span></h2>
              <div className="space-y-4">
                {beneficios.map((b, i) => (
                  <div key={i} className="beneficio-item flex items-center gap-3">
                    <div className="w-6 h-6 rounded-full bg-[#cbf400]/10 flex items-center justify-center flex-shrink-0"><Check className="w-4 h-4 text-[#cbf400]" /></div>
                    <span className="text-gray-300">{b}</span>
                  </div>
                ))}
              </div>
            </div>
            <div className="relative">
              <div className="bg-[#0e0e0e] rounded-2xl p-8 border border-white/5">
                <div className="flex items-center justify-between mb-6">
                  <span className="text-gray-400">Economia média</span>
                  <TrendingUp className="w-6 h-6 text-[#cbf400]" />
                </div>
                <div className="text-5xl font-black text-[#cbf400] mb-2">60%</div>
                <p className="text-gray-400">Redução nos custos</p>
              </div>
            </div>
          </div>
        </div>
      </section>

      {/* Serviços */}
      <section id="servicos" ref={servicosRef} className="py-20 bg-[#0e0e0e]">
        <div className="container-custom">
          <div className="text-center mb-16">
            <h2 className="text-3xl md:text-4xl font-black text-white mb-4">Nossos Serviços <span className="text-gradient">Cloud</span></h2>
          </div>
          <div className="grid md:grid-cols-2 gap-6">
            {servicos.map((s, i) => (
              <div key={i} className="servico-card bg-[#1a1a1a] rounded-2xl p-8 border border-white/5 hover:border-[#cbf400]/30 transition-colors">
                <div className="w-16 h-16 rounded-xl bg-[#cbf400]/10 flex items-center justify-center mb-6 text-[#cbf400]"><s.icon className="w-8 h-8" /></div>
                <h4 className="text-xl font-bold text-white mb-3">{s.titulo}</h4>
                <p className="text-gray-400">{s.descricao}</p>
              </div>
            ))}
          </div>
        </div>
      </section>

      {/* Provedores */}
      <section className="py-20 bg-[#1a1a1a]">
        <div className="container-custom">
          <div className="text-center mb-12">
            <h2 className="text-3xl font-black text-white mb-4">Provedores Suportados</h2>
          </div>
          <div className="flex flex-wrap justify-center gap-4">
            {provedores.map((p, i) => (
              <div key={i} className="px-8 py-4 bg-[#0e0e0e] rounded-xl border border-white/5 text-white font-bold">{p}</div>
            ))}
          </div>
        </div>
      </section>

      {/* CTA */}
      <section className="py-20 bg-[#0e0e0e]">
        <div className="container-custom">
          <div className="bg-gradient-to-r from-[#cbf400]/10 to-transparent rounded-2xl p-12 text-center border border-[#cbf400]/20">
            <h2 className="text-3xl md:text-4xl font-black text-white mb-4">Pronto para migrar?</h2>
            <p className="text-gray-400 mb-8 max-w-2xl mx-auto">Faça uma avaliação gratuita da sua infraestrutura.</p>
            <div className="flex flex-wrap justify-center gap-4">
              <a href="https://api.whatsapp.com/send?phone=551148101704&text=Olá!%20Gostaria%20de%20avaliação%20cloud" target="_blank" rel="noopener noreferrer" className="btn-primary inline-flex items-center gap-2">Solicitar avaliação<ArrowRight className="w-5 h-5" /></a>
              <a href="/#contato" className="btn-secondary">Falar com especialista</a>
            </div>
          </div>
        </div>
      </section>
    </div>
  );
};

export default CloudComputing;
