"use client"; import { useState, useEffect } from "react"; import Link from "next/link"; import Image from "next/image"; import { AnimatePresence, motion } from "framer-motion"; import { useSaleorCheckoutStore } from "@/stores/saleorCheckoutStore"; import { User, ShoppingBag, Menu, X } from "lucide-react"; import CartDrawer from "@/components/cart/CartDrawer"; const navLinks = [ { href: "/products", label: "Products" }, { href: "/about", label: "About" }, { href: "/contact", label: "Contact" }, ]; export default function Header() { const [mobileMenuOpen, setMobileMenuOpen] = useState(false); const [scrolled, setScrolled] = useState(false); const { getLineCount, toggleCart, initCheckout } = useSaleorCheckoutStore(); const itemCount = getLineCount(); // Initialize checkout on mount useEffect(() => { initCheckout(); }, [initCheckout]); // Track scroll for header styling useEffect(() => { const handleScroll = () => { setScrolled(window.scrollY > 50); }; window.addEventListener("scroll", handleScroll); return () => window.removeEventListener("scroll", handleScroll); }, []); // Lock body scroll when mobile menu is open useEffect(() => { if (mobileMenuOpen) { document.body.style.overflow = "hidden"; } else { document.body.style.overflow = ""; } return () => { document.body.style.overflow = ""; }; }, [mobileMenuOpen]); return ( <> {/* Mobile Menu Button */} setMobileMenuOpen(true)} aria-label="Open menu" > {/* Left side - Desktop Nav */} {navLinks.map((link) => ( {link.label} ))} {/* Logo - Centered (absolute on desktop, flex on mobile) */} {/* Right side - Icons */} {itemCount > 0 && ( {itemCount > 99 ? "99+" : itemCount} )} {/* Mobile Menu Overlay */} {mobileMenuOpen && ( {/* Mobile Header */} setMobileMenuOpen(false)}> setMobileMenuOpen(false)} aria-label="Close menu" > {/* Mobile Navigation */} {navLinks.map((link, index) => ( setMobileMenuOpen(false)} className="text-3xl font-medium tracking-tight hover:text-[#666666] transition-colors" > {link.label} ))} {/* Mobile Footer */} { setMobileMenuOpen(false); toggleCart(); }} > Cart ({itemCount}) Account )} > ); }