"use client"; import React, { useState, useRef, useEffect } from "react"; import { Search, ChevronDown, Menu, X, Pill, ShieldCheck, HeartPulse, Sparkles, ShoppingBag, User, PlusCircle, Check, Building2, LogIn, Wallet, LogOut, MapPin, FileHeart, Dog, Cat, BookOpen, FileText, Video, Award, PhoneCall, HelpCircle, Activity } from "lucide-react"; import { motion, AnimatePresence } from "motion/react"; import Link from "next/link"; import { useCartStore } from "../lib/store/cartStore"; import { usePetStore } from "../lib/store/usePetStore"; import { useUserStore } from "../lib/store/userStore"; import { useSettingsStore } from "../lib/store/settingsStore"; import { toast } from "sonner"; import HeaderButton from "./HeaderButton"; import AuthModal from "./AuthModal"; import PrescriptionUploadModal from "./PrescriptionUploadModal"; import { cn } from "../lib/utils"; import { productService } from "../lib/services/productService"; const MENU_ICONS: Record = { joints: , immune: , energy: , "special-care": , }; export default function Header({ onNavigate = () => {}, onShopNavigate = () => {}, currentView = 'home', onCartOpen = () => {}, onSearch = () => {}, onB2BOpen = () => {} }: { onNavigate?: (v: any) => void; onShopNavigate?: (c?: string, s?: string) => void; currentView?: string; onCartOpen?: () => void; onSearch?: (q: string) => void; onB2BOpen?: () => void; }) { const [isMegaMenuOpen, setIsMegaMenuOpen] = useState(false); const [activeDropdown, setActiveDropdown] = useState(null); const [isSearchFocused, setIsSearchFocused] = useState(false); const [isAuthModalOpen, setIsAuthModalOpen] = useState(false); const [isPrescriptionModalOpen, setIsPrescriptionModalOpen] = useState(false); const [isPetSwitcherOpen, setIsPetSwitcherOpen] = useState(false); const [searchQuery, setSearchQuery] = useState(""); const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false); const [menuItems, setMenuItems] = useState<{ id: string; title: string; icon: React.ReactNode; solutions: string[]; }[]>([ { id: "joints", title: "مفاصل و استخوان", icon: MENU_ICONS["joints"], solutions: ["لنگیدن", "سختی در بلند شدن", "درد مفاصل", "رشد سریع توله‌سگ", "پاهای پرانتزی", "ضعف تاندون"] }, { id: "immune", title: "تقویت سیستم ایمنی و گوارش", icon: MENU_ICONS["immune"], solutions: ["ضعف بعد از بیماری", "بی‌اشتهایی", "بعد از زایمان", "اسهال", "مشکلات گوارشی"] }, { id: "energy", title: "ویتامین‌ها و انرژی‌بخش‌ها", icon: MENU_ICONS["energy"], solutions: ["نفس‌نفس زدن", "خستگی", "سن بالا", "بی‌حالی"] }, { id: "special-care", title: "مراقبت‌های ویژه (پوست، دندان و چشم)", icon: MENU_ICONS["special-care"], solutions: ["ریزش مو", "خشکی پوست", "خارش", "جرم دندان", "سوزش چشم"] } ]); const petMenuRef = useRef(null); const [isMounted, setIsMounted] = useState(false); useEffect(() => { setIsMounted(true); }, []); const { getTotalItems } = useCartStore(); const { pets, activePetId, setActivePet, getActivePet } = usePetStore(); const { role, isLoggedIn, logout, profile } = useUserStore(); const activePet = getActivePet(); const getText = useSettingsStore(state => state.getText); useEffect(() => { const loadNavFilters = async () => { try { const data = await productService.getNavigationFilters(); if (data && data.length > 0) { const mapped = data.map(item => ({ id: item.slug, title: item.name, icon: MENU_ICONS[item.slug] || , solutions: item.symptoms || [] })); setMenuItems(mapped); } } catch (e) { console.error("Failed to load navigation filters:", e); } }; loadNavFilters(); }, []); useEffect(() => { function handleClickOutside(event: MouseEvent) { if (petMenuRef.current && !petMenuRef.current.contains(event.target as Node)) { setIsPetSwitcherOpen(false); } } document.addEventListener("mousedown", handleClickOutside); return () => document.removeEventListener("mousedown", handleClickOutside); }, []); const handleSearch = (e: React.FormEvent) => { e.preventDefault(); if (searchQuery.trim()) { onSearch(searchQuery); setIsSearchFocused(false); } }; return ( <> setIsAuthModalOpen(false)} /> setIsPrescriptionModalOpen(false)} />
{/* Top Free Shipping Notice */}
🚚 {getText('shipping_notice', "ارسال رایگان برای سفارش‌های بالای ۱۵۰ هزار تومان — گارانتی اصالت کانینا آلمان")}
{/* TOP ROW: Logo + Search + Primary Actions */}
{/* Mobile Menu Toggle & Logo */}
C
Canina {getText('brand_name_fa', "ایران")} نماینده رسمی CANINA PHARMA GMBH GERMANY
{/* Center Search Input (Desktop) */}
setSearchQuery(e.target.value)} className="w-full bg-medical-gray-50 border border-medical-gray-200 rounded-2xl py-2.5 pr-10 pl-4 text-xs font-bold text-medical-gray-900 focus:outline-none focus:ring-2 focus:ring-canina-blue/20 focus:bg-white transition-all" />
{/* Left Action Buttons */}
{/* Prescription Upload Button */} {/* User Account Button */} {isLoggedIn ? ( {profile.firstName || 'حساب کاربری'} ) : ( )} {/* Shopping Cart Button */}
{/* BOTTOM ROW: Clean Organized Dropdown Navigation Bar (Desktop) */}
{/* Dropdown 1: Category Mega-Menu */}
setIsMegaMenuOpen(true)} onMouseLeave={() => setIsMegaMenuOpen(false)} > {isMegaMenuOpen && ( {menuItems.map((item, idx) => (
setIsMegaMenuOpen(false)} className="flex items-center gap-3 mb-3 cursor-pointer" >
{item.icon}

{item.title}

{item.solutions.slice(0, 6).map((sol, sIdx) => ( setIsMegaMenuOpen(false)} > {sol} ))}
))}
)}
{/* Dropdown 2: Products & Catalog */}
setActiveDropdown('products')} onMouseLeave={() => setActiveDropdown(null)} > {activeDropdown === 'products' && (
کاتالوگ جامع محصولات کاتالوگ آنلاین و دوز مصرفی
)}
{/* Dropdown 3: Science & Academy */}
setActiveDropdown('science')} onMouseLeave={() => setActiveDropdown(null)} > {activeDropdown === 'science' && (
دانشنامه علمی کانینا مجله سلامت پت (وبلاگ)
)}
{/* Dropdown 4: Smart Tools & Pet Profile */}
setActiveDropdown('tools')} onMouseLeave={() => setActiveDropdown(null)} > {activeDropdown === 'tools' && (
شناسنامه و سوابق سلامت پت پایش هوشمند مصرف مکمل‌ها
)}
{/* Dropdown 5: Company & B2B */}
setActiveDropdown('company')} onMouseLeave={() => setActiveDropdown(null)} > {activeDropdown === 'company' && (
درباره کمپانی کانینا آلمان نمادهای اعتماد و مجوزهای رسمی تماس با مرکز پشتیبانی
)}
{/* Mobile Navigation Drawer & Backdrop */} {isMobileMenuOpen && ( <> setIsMobileMenuOpen(false)} className="lg:hidden fixed inset-0 bg-black/50 z-40 backdrop-blur-xs" />
setSearchQuery(e.target.value)} className="w-full bg-medical-gray-50 border border-medical-gray-200 rounded-xl py-3 pr-10 pl-4 text-xs font-bold" />
setIsMobileMenuOpen(false)} className="block p-3 rounded-xl bg-medical-gray-50 text-medical-gray-900"> 🛒 محصولات تخصصی کانینا setIsMobileMenuOpen(false)} className="block p-3 rounded-xl hover:bg-medical-gray-50 text-medical-gray-800"> 📑 کاتالوگ آنلاین و دوز مصرفی setIsMobileMenuOpen(false)} className="block p-3 rounded-xl hover:bg-medical-gray-50 text-medical-gray-800"> 🧬 دانشنامه علمی setIsMobileMenuOpen(false)} className="block p-3 rounded-xl hover:bg-medical-gray-50 text-medical-gray-800"> 📰 مجله سلامت پت setIsMobileMenuOpen(false)} className="block p-3 rounded-xl hover:bg-medical-gray-50 text-medical-gray-800"> 🎥 آکادمی ویدئویی و مشاوره دامپزشک setIsMobileMenuOpen(false)} className="block p-3 rounded-xl hover:bg-medical-gray-50 text-medical-gray-800"> 🐾 شناسنامه و سوابق سلامت پت
)}
); }