import React, { useState, useEffect } from 'react'; import { Menu, X, Scale, Search } from 'lucide-react'; import { Link, useLocation, useNavigate } from 'react-router-dom'; import { cn } from '../../lib/utils'; export function Navbar() { const [isScrolled, setIsScrolled] = useState(false); const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false); const location = useLocation(); const navigate = useNavigate(); useEffect(() => { const handleScroll = () => { setIsScrolled(window.scrollY > 10); }; window.addEventListener('scroll', handleScroll); return () => window.removeEventListener('scroll', handleScroll); }, []); // Handle hash scrolling when navigating across pages useEffect(() => { if (location.hash) { const element = document.querySelector(location.hash); if (element) { setTimeout(() => { element.scrollIntoView({ behavior: 'smooth' }); }, 100); } } else { window.scrollTo(0,0); } }, [location]); const handleNavClick = (e: React.MouseEvent, href: string) => { setIsMobileMenuOpen(false); if (href.startsWith('/#')) { const hash = href.substring(1); if (location.pathname === '/') { e.preventDefault(); const element = document.querySelector(hash); if (element) { element.scrollIntoView({ behavior: 'smooth' }); // Update URL hash without jumping window.history.pushState(null, '', hash); } } else { // Let it navigate to /#hash normally } } }; const navLinks = [ { name: 'Sobre', href: '/sobre' }, { name: 'Áreas de Atuação', href: '/areas' }, { name: 'Como Funciona', href: '/funcionamento' }, { name: 'Blog', href: '/blog' }, { name: 'Contato', href: '/contato' }, ]; return ( ); }