"use client"; import { useState, useEffect } from "react"; import Link from "next/link"; import { useRouter, usePathname } from "next/navigation"; import { Menu, X } from "lucide-react"; import { useLanguage } from "@/contexts/LanguageContext"; import LanguageSelector from "./LanguageSelector"; export default function Header() { const { t } = useLanguage(); const router = useRouter(); const pathname = usePathname(); const [isScrolled, setIsScrolled] = useState(false); const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false); const navItems = [ { name: t("nav", "about"), href: "/#about" }, { name: t("nav", "technology"), href: "/#technology" }, { name: t("nav", "projects"), href: "/#projects" }, { name: t("nav", "solutions"), href: "/#solutions" }, { name: t("nav", "products"), href: "/#products" }, { name: t("nav", "downloads"), href: "/downloads" }, { name: t("nav", "contact"), href: "/#contact" }, ]; useEffect(() => { const handleScroll = () => { setIsScrolled(window.scrollY > 50); }; window.addEventListener("scroll", handleScroll); return () => window.removeEventListener("scroll", handleScroll); }, []); // Handle hash scroll after navigation useEffect(() => { if (pathname === "/" && window.location.hash) { const hash = window.location.hash.substring(1); setTimeout(() => { const element = document.getElementById(hash); if (element) { element.scrollIntoView({ behavior: "smooth" }); } }, 100); } }, [pathname]); const handleNavClick = (e: React.MouseEvent, href: string) => { // If it's not a hash link, let it navigate normally if (!href.includes("#")) { return; } e.preventDefault(); const hash = href.split("#")[1]; if (pathname === "/") { // Already on homepage, just scroll const element = document.getElementById(hash); if (element) { element.scrollIntoView({ behavior: "smooth" }); } } else { // Navigate to homepage first, then scroll router.push(href); } setIsMobileMenuOpen(false); }; return (
{/* Logo */} GRANTECH {/* Desktop Navigation */} {/* Mobile Menu Button */}
{/* Mobile Menu */} {isMobileMenuOpen && (
)}
); }