"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, AnimatePresence } from "motion/react"; import { Eye, ShoppingCart, ShieldCheck, Heart, AlertCircle, Sparkles } from "lucide-react"; import SafeImage from "./SafeImage"; import { ProductCardSkeleton } from "./Skeleton"; import Link from 'next/link'; import { useSettingsStore } from "../lib/store/settingsStore"; import { useCartStore } from "../lib/store/cartStore"; function ProductCard({ product, onClick }: { product: Product; key?: string | number; onClick: (p: Product) => void }) { const router = useRouter(); const getText = useSettingsStore(state => state.getText); const { getActivePet } = usePetStore(); const activePet = getActivePet(); const { addItem } = useCartStore(); 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 ( {/* Independent Category Tag at the absolute top-right of the card */} {product.category} {compatibility && ( {compatibility.type === 'alert' ? : compatibility.type === 'success' ? : } {compatibility.text} )} {/* Product Image Area */} {/* Main PDP Link */} {/* Hover Actions (z-20 to be clickable over the main PDP link) */} { e.stopPropagation(); router.push(`/shop/${product.slug || product.id}`); }} className="w-12 h-12 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(`${product.name} به سبد خرید شما اضافه شد.`); }} className="w-12 h-12 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 Area */} {product.name} {product.shortDescription || product.description} {product.benefits && ( {product.benefits} )} {product.price} {getText('product_view_details', "مشاهده جزئیات")} ); } import { useRouter } from 'next/navigation'; import { toast } from 'sonner'; export default function FeaturedProducts() { const router = useRouter(); const getText = useSettingsStore(state => state.getText); const [products, setProducts] = useState([]); const [isLoading, setIsLoading] = useState(true); useEffect(() => { const fetchFeatured = async () => { try { const data = await productService.getFeaturedProducts(); setProducts(data); } catch (error) { console.error("Failed to fetch featured products:", error); toast.error("خطا در دریافت لیست محصولات از سرور. لطفاً صفحه را رفرش کنید."); } finally { setIsLoading(false); } }; fetchFeatured(); }, []); return ( {/* Header - Correct RTL alignment with primary and secondary elements */} {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) => ( router.push(`/shop/${p.slug || p.id}`)} product={p} /> )) ) : ( {getText('featured_no_products_title', "هیچ محصولی یافت نشد")} {getText('featured_no_products_desc', "در حال حاضر هیچ محصول برجستهای برای نمایش وجود ندارد. لطفاً در پنل ادمین محصولات برگزیده را تنظیم کنید.")} )} ); }
{product.shortDescription || product.description}
{getText('featured_no_products_desc', "در حال حاضر هیچ محصول برجستهای برای نمایش وجود ندارد. لطفاً در پنل ادمین محصولات برگزیده را تنظیم کنید.")}