import { useEffect, useState } from 'react';
import { BrowserRouter as Router, Routes, Route, useLocation } from 'react-router-dom';
import { gsap } from 'gsap';
import { ScrollTrigger } from 'gsap/ScrollTrigger';
import Navigation from './sections/Navigation';
import Footer from './sections/Footer';
import WhatsAppWidget from './components/WhatsAppWidget';
import CookieConsent from './components/CookieConsent';
import HomologationBanner from './components/HomologationBanner';

// Páginas
import Home from './pages/Home';
import Sobre from './pages/Sobre';
import Blog from './pages/Blog';
import BlogPost from './pages/BlogPost';
import Cases from './pages/Cases';
import Contato from './pages/Contato';
import Privacidade from './pages/Privacidade';
import Termos from './pages/Termos';
import NotFound from './pages/NotFound';

// Páginas de Serviços
import TiGerenciada from './pages/services/TiGerenciada';
import CloudComputing from './pages/services/CloudComputing';
import Seguranca from './pages/services/Seguranca';
import Suporte from './pages/services/Suporte';
import Redes from './pages/services/Redes';
import Pabx from './pages/services/Pabx';
import Backup from './pages/services/Backup';
import Servidores from './pages/services/Servidores';
import Consultoria from './pages/services/Consultoria';
import Noc from './pages/services/Noc';

// Páginas de Tecnologias (SEO)
import Tecnologias from './pages/Tecnologias';
import WindowsServer from './pages/tech/WindowsServer';
import Linux from './pages/tech/Linux';
import PfSense from './pages/tech/PfSense';
import Proxmox from './pages/tech/Proxmox';
import Vmware from './pages/tech/Vmware';
import Sharepoint from './pages/tech/Sharepoint';
import Cisco from './pages/tech/Cisco';

// Avaliador de Maturidade Tecnológica
import Avaliador from './pages/Avaliador';
import Condominios from './pages/Condominios';

// Landing Pages por Nicho
import Contabilidade from './pages/nichos/Contabilidade';
import Advocacia from './pages/nichos/Advocacia';
import Monitoramento from './pages/nichos/Monitoramento';
import FirewallPfSense from './pages/nichos/FirewallPfSense';
import BackupCorporativo from './pages/nichos/BackupCorporativo';
import VoipEmpresarial from './pages/nichos/VoipEmpresarial';

import './App.css';

gsap.registerPlugin(ScrollTrigger);

// Componente para scroll ao topo ao mudar de página
function ScrollToTop() {
  const { pathname } = useLocation();
  
  useEffect(() => {
    window.scrollTo(0, 0);
    // Refresh ScrollTrigger ao mudar de página
    ScrollTrigger.refresh();
  }, [pathname]);
  
  return null;
}

// Componente de Progress Bar
function ProgressBar() {
  const [scrollProgress, setScrollProgress] = useState(0);
  
  useEffect(() => {
    const handleScroll = () => {
      const scrollTop = window.scrollY;
      const docHeight = document.documentElement.scrollHeight - window.innerHeight;
      const progress = (scrollTop / docHeight) * 100;
      setScrollProgress(progress);
    };

    window.addEventListener('scroll', handleScroll, { passive: true });
    return () => window.removeEventListener('scroll', handleScroll);
  }, []);
  
  return (
    <div
      className="progress-bar"
      style={{ width: `${scrollProgress}%` }}
    />
  );
}

function App() {
  return (
    <Router>
      <ScrollToTop />
      <div className="relative bg-[#0e0e0e] min-h-screen">
        <ProgressBar />
        <Navigation />
        
        <main>
          <Routes>
            {/* Página Inicial */}
            <Route path="/" element={<Home />} />
            
            {/* Sobre */}
            <Route path="/sobre" element={<Sobre />} />
            
            {/* Serviços */}
            <Route path="/servicos/ti-gerenciada" element={<TiGerenciada />} />
            <Route path="/servicos/cloud-computing" element={<CloudComputing />} />
            <Route path="/servicos/seguranca" element={<Seguranca />} />
            <Route path="/servicos/suporte" element={<Suporte />} />
            <Route path="/servicos/redes" element={<Redes />} />
            <Route path="/servicos/pabx" element={<Pabx />} />
            <Route path="/servicos/backup" element={<Backup />} />
            <Route path="/servicos/servidores" element={<Servidores />} />
            <Route path="/servicos/consultoria" element={<Consultoria />} />
            <Route path="/servicos/noc" element={<Noc />} />
            
            {/* Blog */}
            <Route path="/blog" element={<Blog />} />
            <Route path="/blog/:slug" element={<BlogPost />} />
            
            {/* Cases */}
            <Route path="/cases" element={<Cases />} />
            
            {/* Tecnologias (SEO) */}
            <Route path="/tecnologias" element={<Tecnologias />} />
            <Route path="/suporte-windows-server" element={<WindowsServer />} />
            <Route path="/suporte-linux-empresas" element={<Linux />} />
            <Route path="/suporte-pfsense" element={<PfSense />} />
            <Route path="/suporte-proxmox" element={<Proxmox />} />
            <Route path="/suporte-vmware" element={<Vmware />} />
            <Route path="/suporte-sharepoint" element={<Sharepoint />} />
            <Route path="/suporte-redes-cisco" element={<Cisco />} />
            
            {/* Avaliador de Maturidade */}
            <Route path="/avaliacao" element={<Avaliador />} />
            
            {/* Tecnologia para Condomínios */}
            <Route path="/tecnologia-para-condominios" element={<Condominios />} />
            
            {/* Landing Pages por Nicho */}
            <Route path="/ti-para-contabilidades" element={<Contabilidade />} />
            <Route path="/ti-para-advocacias" element={<Advocacia />} />
            <Route path="/monitoramento-empresarial" element={<Monitoramento />} />
            <Route path="/firewall-pfsense-empresarial" element={<FirewallPfSense />} />
            <Route path="/backup-corporativo" element={<BackupCorporativo />} />
            <Route path="/voip-empresarial" element={<VoipEmpresarial />} />
            
            {/* Contato */}
            <Route path="/contato" element={<Contato />} />
            
            {/* Páginas Legais */}
            <Route path="/privacidade" element={<Privacidade />} />
            <Route path="/termos" element={<Termos />} />
            
            {/* 404 */}
            <Route path="*" element={<NotFound />} />
          </Routes>
        </main>
        
        <Footer />
        <WhatsAppWidget />
        <CookieConsent />
        <HomologationBanner />
      </div>
    </Router>
  );
}

export default App;
