import { useQuery } from '@tanstack/react-query'
import { useParams, Link } from 'react-router-dom'
import {
Clock, Users, ChefHat, ArrowLeft, Flame, BookOpen,
ShoppingBasket, ExternalLink, CookingPot
} from 'lucide-react'
import { mealPlannerApi } from '../api'
import type { Recipe } from '../types'
import { Button } from '../components/ui/Button'
import { Badge } from '../components/ui/Badge'
import { Card, CardBody, CardHeader } from '../components/ui/Card'
import { Skeleton, SkeletonText } from '../components/ui/Skeleton'
import { showToast } from '../lib/toast'
function RecipeDetailSkeleton() {
return (
)
}
export default function RecipeDetail() {
const { id } = useParams<{ id: string }>()
const { data: recipe, isLoading } = useQuery({
queryKey: ['recipe', id],
queryFn: () => mealPlannerApi.recipes.get(id!).then(r => r.data),
enabled: !!id,
})
if (isLoading || !recipe) {
return
}
const totalTime = recipe.total_time_minutes ??
(recipe.prep_time_minutes || 0) + (recipe.cook_time_minutes || 0)
const handleAddToPlan = () => {
showToast.success('Coming soon: add this recipe to the current meal plan.')
}
return (
{/* Top bar */}
{recipe.name}
{recipe.description}
} onClick={handleAddToPlan}>
Add to Plan
{/* Meta row */}
{recipe.cuisine_tags?.map(t => (
{t}
))}
{recipe.dietary_tags?.map(t => (
{t}
))}
{recipe.protein_type && (
{recipe.protein_type}
)}
{recipe.spice_level != null && (
Spice {recipe.spice_level}/5
)}
{/* Image + Quick stats */}
{recipe.image_url ? (
) : (
)}
Quick Stats
{totalTime > 0 ? `${totalTime} min total` : 'Time not set'}
{recipe.prep_time_minutes ?? 0} min prep ยท {recipe.cook_time_minutes ?? 0} min cook
{recipe.servings} servings
{recipe.calories_per_serving && (
{recipe.calories_per_serving} kcal/serving
)}
{recipe.source_url && (
Source
)}
{recipe.discovery_reason && (
{recipe.discovery_reason}
)}
{/* Ingredients */}
Ingredients
{recipe.ingredients?.map((ing, i) => (
-
{ing.qty != null && `${ing.qty}${ing.unit ? ` ${ing.unit}` : ''} `}
{ing.name || 'Unknown ingredient'}
))}
{/* Instructions */}
Instructions
{recipe.instructions?.map((step, i) => (
-
{i + 1}
{step}
))}
)
}