import React, { useState, useEffect, useRef } from 'react'; import { motion } from 'framer-motion'; import { ShoppingCart, User, X, Menu as MenuIcon, Home, Package, Phone, ChevronDown, Leaf, Utensils as SpicesIcon, Box, Star, LogOut, Info } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Separator } from '@/components/ui/separator'; import { Link, useNavigate, useLocation } from 'react-router-dom'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, DropdownMenuSeparator } from "@/components/ui/dropdown-menu"; import { supabase } from '@/lib/supabaseClient'; import { useToast } from "@/components/ui/use-toast"; const Header = ({ logoUrl, cartItemCount, onCategorySelect, headerHeight, session, setSession }) => { const [isMenuOpen, setIsMenuOpen] = useState(false); const navigate = useNavigate(); const location = useLocation(); const menuRef = useRef(null); const triggerRef = useRef(null); const { toast } = useToast(); const handleMenuLinkClick = (path, sectionId) => { setIsMenuOpen(false); if (path) { navigate(path); } if (sectionId) { setTimeout(() => { const section = document.getElementById(sectionId); if (section) { section.scrollIntoView({ behavior: 'smooth' }); } else if (path === '/') { navigate('/'); setTimeout(() => { const homeSection = document.getElementById(sectionId); if (homeSection) homeSection.scrollIntoView({ behavior: 'smooth' }); }, 150); } }, 100); } }; useEffect(() => { const handleClickOutside = (event) => { if (menuRef.current && !menuRef.current.contains(event.target) && triggerRef.current && !triggerRef.current.contains(event.target)) { setIsMenuOpen(false); } }; document.addEventListener("mousedown", handleClickOutside); return () => document.removeEventListener("mousedown", handleClickOutside); }, [menuRef, triggerRef]); const handleCategoryClick = (category) => { onCategorySelect(category); setIsMenuOpen(false); if (location.pathname !== '/products') { navigate('/products'); } }; const handleLogout = async () => { setIsMenuOpen(false); const { error } = await supabase.auth.signOut(); if (error) { toast({ title: "Logout Failed", description: error.message, variant: "destructive", className: "toast-destructive-theme", }); } else { setSession(null); toast({ title: "👋 Logged Out", description: "You have been successfully logged out.", className: "toast-info-theme", }); navigate('/'); } }; const menuItems = [ { label: "Home", path: "/", icon: , action: () => handleMenuLinkClick('/') }, { label: "About Us", path: "/about-us", icon: , action: () => handleMenuLinkClick('/about-us') }, { label: "Contact Us", path: "/contact", icon: , action: () => handleMenuLinkClick('/contact') }, ]; const productCategories = [ { label: "Spices", icon: , action: () => handleCategoryClick('Spices') }, { label: "Dry Fruits", icon: , action: () => handleCategoryClick('Dry Fruits') }, { label: "Taste Rider Specials", icon: , action: () => handleCategoryClick('Taste Rider Specials') }, ]; return ( <> {/* Trust badges banner removed */} {isMenuOpen ? : } {menuItems.map(item => ( {item.icon} {item.label} ))} {session ? ( <> setIsMenuOpen(false)} className="hover:bg-stone-700 focus:bg-stone-700 py-3 text-lg flex items-center w-full cursor-pointer rounded-md"> My Profile Logout > ) : ( setIsMenuOpen(false)} className="hover:bg-stone-700 focus:bg-stone-700 py-3 text-lg flex items-center w-full cursor-pointer rounded-md"> Login )} {menuItems.map(item => ( {item.label} ))} { if (location.pathname === '/') { e.preventDefault(); window.scrollTo({ top: 0, behavior: 'smooth' }); } }} > {/* Products button now navigates directly to categories */} navigate('/product-categories')} > Products {/* Wishlist button for desktop - removed */} {cartItemCount > 0 && ( {cartItemCount} )} {session ? ( <> > ) : ( )} {cartItemCount > 0 && ( {cartItemCount} )} > ); }; export default Header;