"use client"; import Link from "next/link"; import React, { useState, useEffect, MouseEvent } from "react"; import { useParams, usePathname } from "next/navigation"; import { CiMenuFries } from "react-icons/ci"; import { IoCloseOutline } from "react-icons/io5"; import LanguageSwitcher from "../ui/LanguageSwitcher"; export default function Header() { const params = useParams<{ locale?: string }>(); const pathname = usePathname(); const locale = params?.locale ?? "fr"; const homePath = `/${locale}`; const links = [ { text: "Accueil", target: homePath }, { text: "Travaux", target: `${homePath}#works` }, { text: "A propos", target: `${homePath}#about` }, { text: "Blog", target: `${homePath}/blog` }, ]; const [isOpen, setIsOpen] = useState(false); const [showText, setShowText] = useState(false); const scrollToSection = (id: string) => { const element = document.getElementById(id); if (!element) return false; element.scrollIntoView({ behavior: "smooth" }); return true; }; const handleAnchorClick = (e: MouseEvent, target: string) => { const isAnchor = target.includes("#"); const isOnHome = pathname === homePath || pathname === `${homePath}/`; if (isAnchor && isOnHome) { e.preventDefault(); const sectionId = target.split("#")[1]; scrollToSection(sectionId); } setIsOpen(false); }; useEffect(() => { const hash = window.location.hash.replace("#", ""); if (!hash) return; if (scrollToSection(hash)) return; const timer = window.setTimeout(() => { scrollToSection(hash); }, 120); return () => window.clearTimeout(timer); }, [pathname]); useEffect(() => { if (isOpen) { const timer = setTimeout(() => setShowText(true), 450); return () => clearTimeout(timer); } setShowText(false); }, [isOpen]); return (
M. Guilbert
logo mg dev
M. Guilbert
Sélection de la langue
); }