"use client"; import { useRouter } from "next/navigation"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; import Image from "next/image"; import { Product } from "@/lib/openFoodFactsApi"; import { Heart, AlertTriangle, Zap, Plus, Eye } from "lucide-react"; import { formatNutritionData } from "@/lib/openFoodFactsApi"; interface ProductCardProps { product: Product; className?: string; } const NUTRI_SCORE_CONFIG = { a: { label: "A", className: "bg-green-500 text-white border-green-500", description: "Muito bom", }, b: { label: "B", className: "bg-green-400 text-white border-green-400", description: "Bom", }, c: { label: "C", className: "bg-yellow-500 text-white border-yellow-500", description: "Regular", }, d: { label: "D", className: "bg-orange-500 text-white border-orange-500", description: "Ruim", }, e: { label: "E", className: "bg-red-500 text-white border-red-500", description: "Muito ruim", }, }; const NOVA_CONFIG = { 1: { label: "1", className: "bg-green-500 text-white", description: "Minimamente processado", }, 2: { label: "2", className: "bg-yellow-500 text-white", description: "Ingrediente culinário", }, 3: { label: "3", className: "bg-orange-500 text-white", description: "Processado", }, 4: { label: "4", className: "bg-red-500 text-white", description: "Ultraprocessado", }, }; export function ProductCard({ product, className = "" }: ProductCardProps) { const router = useRouter(); const getProductImageUrl = (): string => { return ( product.image_front_url || product.image_front_small_url || product.image_url || product.image_small_url || "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400'%3E%3Crect fill='%23f3f4f6' width='400' height='400'/%3E%3Ctext fill='%239ca3af' font-family='sans-serif' font-size='48' x='50%25' y='50%25' text-anchor='middle' dominant-baseline='middle'%3ESem Imagem%3C/text%3E%3C/svg%3E" ); }; const getNutritionGrade = () => { if (!product.nutrition_grades) return null; const grade = product.nutrition_grades.toLowerCase(); return NUTRI_SCORE_CONFIG[grade as keyof typeof NUTRI_SCORE_CONFIG] || null; }; const getNovaGroup = () => { if (!product.nova_group) return null; return NOVA_CONFIG[product.nova_group as keyof typeof NOVA_CONFIG] || null; }; const nutritionGrade = getNutritionGrade(); const novaGroup = getNovaGroup(); const imageUrl = getProductImageUrl(); const nutritionData = formatNutritionData(product); // Verificar se tem alérgenos comuns const hasCommonAllergens = product.allergens_tags?.some((allergen) => ["gluten", "milk", "eggs", "nuts", "peanuts", "soy"].some((common) => allergen.toLowerCase().includes(common) ) ) || false; return ( {/* Imagem do Produto */}
{product.product_name {/* Overlay com badges */}
{/* Badge Nutri-Score */} {nutritionGrade && (
{nutritionGrade.label}
)} {/* Badge NOVA */} {novaGroup && (
NOVA {novaGroup.label}
)} {/* Ícone de alérgenos */} {hasCommonAllergens && (
)} {/* Botão de favorito */}
{/* Nome do Produto */}

{product.product_name || "Nome não disponível"}

{/* Marca */} {product.brands && (

{product.brands}

)}
{/* Informações nutricionais resumidas */} {nutritionData && (
Energia: {nutritionData.energy}
Gorduras: {nutritionData.fat}
Açúcares: {nutritionData.sugars}
Sódio: {nutritionData.sodium}
)} {/* Categorias */} {product.categories && (
{product.categories .split(",") .slice(0, 2) .map((cat, i) => ( {cat.trim()} ))}
)} {/* Alérgenos */} {hasCommonAllergens && (
Contém alérgenos
)} {/* Botões de ação */}
); }