"use client"; import { useState, useEffect, useMemo } from "react"; import { Product } from "../lib/data/products"; import { usePetStore } from "../lib/store/usePetStore"; import { productService } from "../lib/services/productService"; import { motion } from "motion/react"; import { Eye, ShoppingCart, Heart, AlertCircle, Sparkles } from "lucide-react"; import SafeImage from "./SafeImage"; import { ProductCardSkeleton } from "./Skeleton"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useSettingsStore } from "../lib/store/settingsStore"; import { useCartStore } from "../lib/store/cartStore"; import { toast } from "sonner"; function ProductCard({ product }: { product: Product }) { const router = useRouter(); const getText = useSettingsStore((state) => state.getText); const { getActivePet } = usePetStore(); const activePet = getActivePet(); const { addItem } = useCartStore(); const nameFa = product.nameFa || product.name; const nameEn = product.nameEn || ""; 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}` }; return { type: "neutral", text: `مناسب برای ${activePet.name}` }; }, [product, activePet]); return ( {/* Category Badge */} {product.category} {/* Compatibility Tag */} {compatibility && ( {compatibility.type === "alert" ? : compatibility.type === "success" ? : } {compatibility.text} )} {/* Image */} {/* PDP Link overlay */} {/* Hover Actions */} { e.stopPropagation(); router.push(`/shop/${product.slug || product.id}`); }} className="w-11 h-11 rounded-full bg-white text-canina-blue flex items-center justify-center hover:scale-110 transition-transform shadow-lg cursor-pointer" > { e.stopPropagation(); addItem(product, 1); toast.success(`${nameFa} به سبد خرید اضافه شد.`); }} className="w-11 h-11 rounded-full bg-canina-blue text-white flex items-center justify-center hover:scale-110 transition-transform shadow-lg border border-white/20 cursor-pointer" > {/* Content */} {/* Dual-language Name */} {nameFa} {nameEn && ( {nameEn} )} {/* Short description */} {product.shortDescription || product.description} {/* Footer: Price + CTA */} {product.price} {getText("product_view_details", "مشاهده جزئیات")} ); } export default function FeaturedProducts() { const router = useRouter(); const getText = useSettingsStore((state) => state.getText); const [products, setProducts] = useState([]); const [isLoading, setIsLoading] = useState(true); useEffect(() => { productService.getFeaturedProducts() .then(setProducts) .catch(() => toast.error("خطا در دریافت لیست محصولات از سرور.")) .finally(() => setIsLoading(false)); }, []); return ( {getText("featured_badge", "بیشترین انتخاب توسط دامپزشکان")} {getText("featured_title_line1", "محصولات برگزیده و راهکارهای")}{" "} {getText("featured_title_line2", "درمان تخصصی")} router.push("/shop")} className="inline-flex items-center gap-2 text-canina-blue font-black text-sm hover:translate-x-1 transition-all group font-vazir" > {getText("featured_view_all", "مشاهده تمامی محصولات")} ← {isLoading ? ( Array.from({ length: 4 }).map((_, i) => ) ) : products.length > 0 ? ( products.map((p) => ) ) : ( {getText("featured_no_products_title", "هیچ محصولی یافت نشد")} {getText("featured_no_products_desc", "در حال حاضر هیچ محصول برجستهای برای نمایش وجود ندارد.")} )} ); }
{product.shortDescription || product.description}
{getText("featured_no_products_desc", "در حال حاضر هیچ محصول برجستهای برای نمایش وجود ندارد.")}