import { useEffect, useState } from 'react';
import { motion, AnimatePresence } from 'motion/react';
import { Link, useLocation } from 'react-router-dom';
import Logo from './Logo';
const navItems = [
{ label: 'Our Products', href: '/products' },
{ label: 'Our Story', href: '/history' },
{ label: 'Contact', href: '/contact' },
];
const Header = () => {
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
const { pathname } = useLocation();
// Close on navigation — without this the panel stays up over the page you just opened.
useEffect(() => setIsMobileMenuOpen(false), [pathname]);
// Escape closes it, and the page behind it doesn't scroll while it's up.
useEffect(() => {
if (!isMobileMenuOpen) return;
const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') setIsMobileMenuOpen(false); };
const previousOverflow = document.body.style.overflow;
document.body.style.overflow = 'hidden';
window.addEventListener('keydown', onKey);
return () => {
document.body.style.overflow = previousOverflow;
window.removeEventListener('keydown', onKey);
};
}, [isMobileMenuOpen]);
return (
<>
{/* Logo */}
{/* Desktop Navigation */}
{/* Mobile menu button — the same control opens and closes, so the bar never
disappears out from under your thumb. */}
{/* Mobile navigation. Three things here are load-bearing:
It lives OUTSIDE . The header carries `backdrop-blur`, and a backdrop-filter
makes an element a containing block for fixed-position descendants — so a `fixed` panel
nested inside it resolves against the 80px header box, not the viewport, and gets
clipped to a sliver.
It starts BELOW the bar (`top-20`) instead of covering it, so the logo and the toggle
stay put and the panel needs no second copy of either. One logo, one position, every
breakpoint.
It must UNMOUNT when closed: a panel parked off-screen still extends the scrollable
area, which is what used to let you scroll sideways and find the menu. */}
{isMobileMenuOpen && (
)}
>
);
};
export default Header;