"use client"; import React, { useState, useMemo, useEffect } from "react"; import { Product, PetType } from "../lib/data/products"; import { usePetStore } from "../lib/store/usePetStore"; import { productService } from "../lib/services/productService"; import { motion, AnimatePresence } from "motion/react"; import { ProductCardSkeleton } from "./Skeleton"; import { toast } from "sonner"; import { Search, Filter, Dog, Cat, ShieldCheck, ChevronLeft, ChevronRight, Activity, Sparkles, Stethoscope, HeartPulse, Heart, AlertCircle, Plus, Loader2 } from "lucide-react"; import { useCartStore } from "../lib/store/cartStore"; import SafeImage from "./SafeImage"; const CATEGORIES = [ { id: "all", label: "همه محصولات", icon: }, { id: "joints", label: "حرکتی و مفاصل", icon: }, { id: "immune", label: "تقویت و ایمنی", icon: }, { id: "energy", label: "ویتامین و انرژی", icon: }, { id: "special-care", label: "پلتفرم مراقبت ویژه", icon: }, ]; const CATEGORY_MAP: Record = { // Main Categories "joints": { category: "joints" }, "immune": { category: "immune" }, "energy": { category: "energy" }, "special-care": { category: "special-care" }, // Persian Fallbacks (for robust matching) "مفاصل و استخوان": { category: "joints" }, "تقویت سیستم ایمنی و گوارش": { category: "immune" }, "ویتامین‌ها و انرژی‌بخش‌ها": { category: "energy" }, "مراقبت‌های ویژه (پوست، دندان و چشم)": { category: "special-care" }, // Solutions "آرتروز سگ‌های پیر": { category: "joints", symptoms: ["درد مفاصل", "سختی در بلند شدن", "لنگیدن"] }, "رشد استخوانی توله‌سگ": { category: "joints", symptoms: ["رشد سریع توله‌سگ"] }, "تقویت رباط و تاندون": { category: "joints", query: "تاندون" }, "پیشگیری از بیماری": { category: "immune", symptoms: ["ضعف بعد از بیماری"] }, "رفع اسهال و یبوست": { category: "immune", symptoms: ["اسهال", "یبوست", "اسهال مزمن"] }, "پروبیوتیک‌ها": { category: "immune", query: "فیبر" }, "مکمل‌های مولتی‌ویتامین": { category: "energy", query: "ویتامین" }, "افزایش اشتها": { category: "energy", symptoms: ["بی‌اشتهایی"] }, "رشد و بلوغ": { category: "energy", query: "انرژی" }, "سلامت پوست و مفاصل": { category: "special-care", symptoms: ["خشکی پوست", "ریزش مو", "خارش"] }, "رفع جرم دندان": { category: "special-care", symptoms: ["جرم دندان", "بوی بد دهان", "التهاب لثه"] }, "شستشوی چشم": { category: "special-care", query: "چشم" }, }; const SYMPTOMS = [ "لنگیدن", "سختی در بلند شدن", "ریزش مو", "جرم دندان", "بی‌اشتهایی", "اسهال مزمن", "بعد از مصرف آنتی‌بیوتیک" ]; const ArchiveProductCard: React.FC<{ product: Product, onClick: (p: Product) => void }> = ({ product, onClick }) => { const { addItem } = useCartStore(); const [isAdding, setIsAdding] = useState(false); const activePet = usePetStore(state => state.pets.find(p => p.id === state.activePetId) || null); const handleAddToCart = (e: React.MouseEvent) => { e.stopPropagation(); setIsAdding(true); addItem(product, 1); toast.success(`${product.name} به سبد خرید اضافه شد`); setTimeout(() => setIsAdding(false), 800); }; const compatibility = useMemo(() => { if (!activePet) return null; const sameSpecies = product.suitableFor === activePet.type || product.suitableFor === "هر دو"; const helpsSymptom = (activePet.medicalConditions || []).some(s => product.symptoms.includes(s)); if (!sameSpecies) return { type: 'alert', text: `مخصوص ${product.suitableFor}` }; if (helpsSymptom) return { type: 'success', text: `توصیه شده برای راهکار ${activePet.name}` }; if (sameSpecies) return { type: 'neutral', text: `مناسب برای ${activePet.name}` }; return null; }, [product, activePet]); return ( onClick(product)} className="group bg-white rounded-[2.5rem] border border-medical-gray-200 overflow-hidden hover:shadow-2xl transition-all cursor-pointer flex flex-col h-full relative" > {product.specialBadge && (
{product.specialBadge}
)} {compatibility && (
{compatibility.type === 'alert' ? : compatibility.type === 'success' ? : } {compatibility.text}
)}
{(product.suitableFor === "سگ" || product.suitableFor === "هر دو") && (
)} {(product.suitableFor === "گربه" || product.suitableFor === "هر دو") && (
)}
{product.category}

{product.name}

{product.symptoms.slice(0, 2).map((s, i) => ( {s} ))}
{product.price}
); } import { useRouter } from 'next/navigation'; export default function ArchivePage({ initialCategory = "all", initialSearch = "" }: { initialCategory?: string, initialSearch?: string }) { const router = useRouter(); const [selectedCategory, setSelectedCategory] = useState(initialCategory); const [selectedPet, setSelectedPet] = useState("all"); const [activeSymptoms, setActiveSymptoms] = useState([]); const [searchQuery, setSearchQuery] = useState(initialSearch); const [isUpdating, setIsUpdating] = useState(false); const [filteredProducts, setFilteredProducts] = useState([]); // Debug Log for Search Params useEffect(() => { console.log("[ArchivePage] URL Params Sync:", { initialCategory, initialSearch }); }, [initialCategory, initialSearch]); // Sync state with prop change (e.g. from Header menu) useEffect(() => { setIsUpdating(true); // Normalize Input (Trim and lowercase) const normSearch = (initialSearch || "").trim().toLowerCase(); const normCat = initialCategory.trim().toLowerCase(); const mapKey = normSearch || normCat; const mapping = CATEGORY_MAP[mapKey]; console.log("[ArchivePage] Processing Mapping for:", mapKey); // Reset ALL other filters when a new category/solution is selected from menu setSelectedPet("all"); setActiveSymptoms([]); setSearchQuery(""); if (mapping) { if (mapping.category) setSelectedCategory(mapping.category); if (mapping.query) setSearchQuery(mapping.query); if (mapping.symptoms) { setActiveSymptoms(mapping.symptoms); } } else { setSelectedCategory(initialCategory); setSearchQuery(initialSearch); if (initialSearch && SYMPTOMS.includes(initialSearch)) { setActiveSymptoms([initialSearch]); } } const timer = setTimeout(() => { window.scrollTo({ top: 0, behavior: "smooth" }); }, 400); return () => clearTimeout(timer); }, [initialCategory, initialSearch]); useEffect(() => { const fetchProducts = async () => { setIsUpdating(true); try { const data = await productService.getProducts({ category: selectedCategory, petType: selectedPet, query: searchQuery }); let result = data; if (activeSymptoms.length > 0) { result = result.filter(p => p.symptoms.some(s => activeSymptoms.includes(s))); } setFilteredProducts(result); } catch (error) { console.error("Failed to fetch products:", error); toast.error("خطا در دریافت لیست محصولات از سرور. لطفاً صفحه را رفرش کنید."); } finally { setIsUpdating(false); } }; fetchProducts(); }, [selectedCategory, selectedPet, searchQuery, activeSymptoms]); const toggleSymptom = (s: string) => { setActiveSymptoms(prev => prev.includes(s) ? prev.filter(item => item !== s) : [...prev, s]); }; return (
{/* Mobile Navigation & Breadcrumbs */}
router.push('/')}>کانینا فروشگاه تخصصی
{/* Desktop Breadcrumbs */}
router.push('/')}>خانه کاتالوگ کامل محصولات
{/* Sidebar Filters */} {/* Main Content */}

کاتولوگ دارویی Canina

setSearchQuery(e.target.value)} className="w-full bg-white border border-medical-gray-200 rounded-full py-3 pr-11 pl-4 text-sm focus:outline-none focus:ring-2 focus:ring-canina-blue/20" />
{isUpdating ? (
{Array.from({ length: 6 }).map((_, i) => ( ))}
) : filteredProducts.length > 0 ? (
{filteredProducts.map((p: Product) => ( router.push(`/shop/${p.slug || p.id}`)} /> ))}
) : (

محصولی یافت نشد!

با فیلترهای فعلی محصولی مطابق با نیاز شما پیدا نکردیم. لطفاً فیلترها را گسترده‌تر کنید یا دکمه ریست را بزنید.

)}
); }