import React from 'react'; import { mergeClasses as cn } from '@/lib/styles/designSystem'; import type { Translation } from '@/types/i18n'; interface NavLinksProps { translations: Translation['navigation']; scrolled: boolean; className?: string; } interface NavLinkProps { href: string; children: React.ReactNode; isActive?: boolean; onClick?: () => void; } const NavLink: React.FC = ({ href, children, isActive = false, onClick }) => { return ( {children} {/* Hover effect */}
{/* Active indicator */} {isActive && (
)} ); }; export const NavLinks: React.FC = ({ translations, className }) => { const [activeSection, setActiveSection] = React.useState('home'); // Observer pour détecter la section active React.useEffect(() => { const handleScroll = () => { const scrollPosition = window.scrollY; const windowHeight = window.innerHeight; // Si on est en haut de la page (moins de 100px du haut), on active "home" if (scrollPosition < 100) { setActiveSection('home'); return; } // Sinon, on utilise l'intersection observer logic const sections = ['home', 'services', 'about']; let currentSection = 'home'; sections.forEach((sectionId) => { const element = document.getElementById(sectionId); if (element) { const rect = element.getBoundingClientRect(); const sectionTop = rect.top + scrollPosition; // Si la section est visible dans le viewport if (scrollPosition >= sectionTop - windowHeight / 3) { currentSection = sectionId; } } }); setActiveSection(currentSection); }; // Écouter le scroll window.addEventListener('scroll', handleScroll); // Appeler une fois au chargement handleScroll(); return () => { window.removeEventListener('scroll', handleScroll); }; }, []); // Observer pour détecter la section active avec IntersectionObserver (fallback) React.useEffect(() => { const observer = new IntersectionObserver( (entries) => { entries.forEach((entry) => { if (entry.isIntersecting && window.scrollY > 100) { setActiveSection(entry.target.id); } }); }, { threshold: 0.3, rootMargin: '-100px 0px -100px 0px' } ); const sections = ['home', 'services', 'about']; sections.forEach((id) => { const element = document.getElementById(id); if (element) observer.observe(element); }); return () => observer.disconnect(); }, []); const handleNavClick = (sectionId: string) => { if (sectionId === 'home') { // Scroll to top for home section window.scrollTo({ top: 0, behavior: 'smooth' }); } else if (sectionId === 'contact') { // Open email client for contact window.location.href = 'mailto:contact@la-banquise.fr'; } else { // Scroll to specific section const element = document.getElementById(sectionId); if (element) { element.scrollIntoView({ behavior: 'smooth', block: 'start' }); } } }; return ( ); };