Files
klz-cables.com/components/Header.tsx
2026-01-17 13:17:10 +01:00

129 lines
4.5 KiB
TypeScript

'use client';
import Link from 'next/link';
import Image from 'next/image';
import { useTranslations } from 'next-intl';
import { usePathname } from 'next/navigation';
import { Button } from './ui';
import { useEffect, useState } from 'react';
import { cn } from './ui';
export default function Header() {
const t = useTranslations('Navigation');
const pathname = usePathname();
const [isScrolled, setIsScrolled] = useState(false);
// Extract locale from pathname
const currentLocale = pathname.split('/')[1] || 'en';
// Check if homepage
const isHomePage = pathname === `/${currentLocale}` || pathname === '/';
useEffect(() => {
const handleScroll = () => {
setIsScrolled(window.scrollY > 50);
};
window.addEventListener('scroll', handleScroll);
return () => window.removeEventListener('scroll', handleScroll);
}, []);
// Function to get path for a different locale
const getPathForLocale = (newLocale: string) => {
const segments = pathname.split('/');
segments[1] = newLocale;
return segments.join('/');
};
const menuItems = [
{ label: t('home'), href: '/' },
{ label: t('team'), href: '/team' },
{ label: t('products'), href: '/products' },
{ label: t('blog'), href: '/blog' },
];
const headerClass = cn(
"fixed top-0 left-0 right-0 z-50 transition-all duration-500",
{
"bg-transparent py-8": isHomePage && !isScrolled,
"bg-primary py-4 shadow-2xl": !isHomePage || isScrolled,
}
);
const textColorClass = "text-white";
const logoSrc = "/logo-white.svg";
return (
<>
<header className={headerClass}>
<div className="container mx-auto px-6 md:px-12 lg:px-16 max-w-7xl flex items-center justify-between">
<Link href={`/${currentLocale}`} className="flex-shrink-0 group">
<Image
src={logoSrc}
alt="KLZ Cables"
width={120}
height={120}
className="h-14 w-auto transition-all duration-500 group-hover:scale-110"
priority
unoptimized
/>
</Link>
<div className="flex items-center gap-12">
<nav className="hidden lg:flex items-center space-x-10">
{menuItems.map((item) => (
<Link
key={item.href}
href={`/${currentLocale}${item.href === '/' ? '' : item.href}`}
className={cn(
textColorClass,
"hover:text-accent font-bold transition-all text-lg tracking-tight relative group"
)}
>
{item.label}
<span className="absolute -bottom-2 left-0 w-0 h-1 bg-accent transition-all duration-300 group-hover:w-full rounded-full" />
</Link>
))}
</nav>
<div className={cn("hidden lg:flex items-center space-x-8", textColorClass)}>
<div className="flex items-center space-x-4 text-sm font-extrabold tracking-widest uppercase">
<Link
href={getPathForLocale('en')}
className={`hover:text-accent transition-colors flex items-center gap-2 ${currentLocale === 'en' ? 'text-accent' : 'opacity-60'}`}
>
EN
</Link>
<div className="w-px h-4 bg-current opacity-20" />
<Link
href={getPathForLocale('de')}
className={`hover:text-accent transition-colors flex items-center gap-2 ${currentLocale === 'de' ? 'text-accent' : 'opacity-60'}`}
>
DE
</Link>
</div>
<Button
href={`/${currentLocale}/contact`}
variant="white"
size="md"
className="px-8 shadow-xl"
>
{t('contact')}
</Button>
</div>
{/* Mobile Menu Button */}
<button className={cn("lg:hidden p-2 rounded-xl bg-white/10 backdrop-blur-md border border-white/20", textColorClass)}>
<svg className="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 6h16M4 12h16M4 18h16" />
</svg>
</button>
</div>
</div>
</header>
{/* Removed spacer div that caused white gap */}
</>
);
}