'use client'; import * as React from 'react'; import { TransitionLink } from '@/components/ui/TransitionLink'; import Image from 'next/image'; import { usePathname } from 'next/navigation'; import { motion, useScroll, useTransform, AnimatePresence } from 'framer-motion'; import { LanguageSwitcher } from './LanguageSwitcher'; export interface NavLink { label: string; url: string; children?: NavLink[]; } interface HeaderProps { navLinks: NavLink[]; } export function Header({ navLinks }: HeaderProps) { const [isScrolled, setIsScrolled] = React.useState(false); const [forceSolid, setForceSolid] = React.useState(false); const pathname = usePathname() || '/'; // Scroll bound shine effect (continuous looping as user scrolls) const { scrollY } = useScroll(); const shineX = useTransform(scrollY, (y) => { const adjustedY = Math.max(0, y - 20); // Start after the solid mode kicks in const range = 800; // 1 full sweep per 800px scrolled const progress = (adjustedY % range) / range; return `${-150 + progress * 300}%`; }); // Determine current locale from pathname const currentLocale = pathname.startsWith('/en') ? 'en' : 'de'; React.useEffect(() => { const handleScroll = () => { setIsScrolled(window.scrollY > 20); }; window.addEventListener('scroll', handleScroll); // Check for forced solid header (used by error pages, legal pages without hero, etc.) const checkSolid = () => { setForceSolid(document.body.getAttribute('data-force-solid-header') === 'true'); }; checkSolid(); // Set up observer for client-side navigation changes const observer = new MutationObserver(checkSolid); observer.observe(document.body, { attributes: true, attributeFilter: ['data-force-solid-header'] }); // Re-check when pathname changes checkSolid(); return () => { window.removeEventListener('scroll', handleScroll); observer.disconnect(); }; }, [pathname]); // Check for force solid initially const isSolidMode = isScrolled || forceSolid; return ( <>
{/* Scroll bound shine effect */}
E-TIB Gruppe {/* Masked sweep overlay on hover */}
{/* Right side elements (Language Switcher always visible, Contact button desktop only) */}
{/* Language Switcher visible on all devices */}
{/* Contact Button Desktop Only */}
); } function NavItem({ link, currentLocale, pathname, isSolidMode }: { link: NavLink, currentLocale: string, pathname: string, isSolidMode: boolean }) { const [isHovered, setIsHovered] = React.useState(false); const mappedUrl = link.url.startsWith('/') && !link.url.match(/^\/(en|de)/) ? `/${currentLocale}${link.url}` : link.url; const isActive = pathname === mappedUrl || (mappedUrl !== `/${currentLocale}` && pathname?.startsWith(`${mappedUrl}/`)); return (
setIsHovered(true)} onMouseLeave={() => setIsHovered(false)} > {link.label} {link.children && ( )} {/* Framer Motion Active Indicator */} {isActive && !link.children && ( )} {/* Subtle hover underline */} {isHovered && link.children && (
{link.children.map((child) => { const childUrl = child.url.startsWith('/') && !child.url.match(/^\/(en|de)/) ? `/${currentLocale}${child.url}` : child.url; const isChildActive = pathname === childUrl; return ( {child.label} ); })}
)}
); }