"use client"; import Image from "next/image"; import Link from "next/link"; import { Heart, ShoppingBag, Sparkles } from "lucide-react"; import { useState } from "react"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import type { Product } from "@/lib/headless/types"; import { formatMoney } from "@/lib/utils"; import { useCartStore } from "@/store/cart-store"; import { useWishlistStore } from "@/store/wishlist-store"; export function ProductCard({ product, priority = false }: { product: Product; priority?: boolean }) { const addItem = useCartStore((state) => state.addItem); const wishlistProducts = useWishlistStore((state) => state.products); const wishlistHydrated = useWishlistStore((state) => state.hasHydrated); const toggleProduct = useWishlistStore((state) => state.toggleProduct); const isFavorite = wishlistHydrated && wishlistProducts.some((item) => item.id === product.id); const discountPercent = product.compareAtPrice && product.price ? Math.round((1 - product.price / product.compareAtPrice) * 100) : null; const [selectedVariantId, setSelectedVariantId] = useState(product.variants[0]?.id); return (
{product.name}
{discountPercent && discountPercent > 0 && -{discountPercent}%}{product.isNew && Nuevo}{product.featured && Top}
{product.category}{product.collection}

{product.name}

{product.shortDescription}

{product.variants.length > 1 && (
{product.variants.map((variant) => ( ))}
)}
{product.compareAtPrice && {formatMoney(product.compareAtPrice, product.currency)}} {formatMoney(product.price, product.currency)}
); }