import { Link } from 'react-router-dom'; import type { Recipe, Tag } from '../types/recipe'; import { colors, radius, recipeAccentPalette, shadows, typography } from '../theme'; interface RecipeCardProps { recipe: Recipe; tags?: Tag[]; } const foodEmojis = ['🥗', '🍲', '🍝', '🍜', '🍛', '🥘', '🍗', '🍤', '🍕', '🥪', '🍳', '🍱']; function formatTime(minutes?: number): string { if (!minutes) return ''; if (minutes < 60) return `${minutes}m`; const hours = Math.floor(minutes / 60); const mins = minutes % 60; return mins > 0 ? `${hours}h ${mins}m` : `${hours}h`; } function formatDate(timestamp?: number): string { if (!timestamp) return ''; const date = new Date(timestamp * 1000); return date.toLocaleDateString(); } function accentForRecipe(recipe: Recipe, tags: Tag[]) { if (tags[0]?.color) return tags[0].color; return recipeAccentPalette[recipe.id % recipeAccentPalette.length]; } function emojiForRecipe(recipe: Recipe) { return foodEmojis[recipe.id % foodEmojis.length]; } function MetaChip({ label, value, emoji }: { label: string; value: string; emoji: string }) { return (
{value} {label}
); } export function RecipeCard({ recipe, tags = [] }: RecipeCardProps) { const totalTime = (recipe.prep_time_minutes || 0) + (recipe.cook_time_minutes || 0); const accent = accentForRecipe(recipe, tags); return (
{tags[0]?.name ?? 'Homemade'}

{recipe.title}

{recipe.description ? (

{recipe.description}

) : (

No description yet

)}
{recipe.servings ? : null} {totalTime > 0 ? : null}
{tags.length > 0 && (
{tags.slice(0, 4).map((tag) => ( {tag.name} ))} {tags.length > 4 ? +{tags.length - 4} : null}
)}
{recipe.last_cooked_at ? `Cooked ${formatDate(recipe.last_cooked_at)}` : 'Not cooked yet'} View recipe
); }