import { notFound } from "next/navigation"; import { headers } from "next/headers"; import { auth } from "@/lib/auth/server"; import { db, recipes, eq, and } from "@epicure/db"; import { PrintTrigger } from "@/components/recipe/print-trigger"; import { formatIngredientQuantity } from "@/lib/unit-conversion"; import { getMessages, formatMessage } from "@/lib/i18n/server"; type Params = { params: Promise<{ id: string }> }; export default async function RecipePrintPage({ params }: Params) { const { id } = await params; const session = await auth.api.getSession({ headers: await headers() }); if (!session) return null; const m = getMessages((session.user as { locale?: string }).locale); const unitPref = (session.user as { unitPref?: string }).unitPref === "imperial" ? "imperial" : "metric"; const recipe = await db.query.recipes.findFirst({ where: and(eq(recipes.id, id), eq(recipes.authorId, session.user.id)), with: { ingredients: { orderBy: (t, { asc }) => asc(t.order) }, steps: { orderBy: (t, { asc }) => asc(t.order) }, }, }); if (!recipe) notFound(); const totalMins = (recipe.prepMins ?? 0) + (recipe.cookMins ?? 0); const activeTags = Object.entries(recipe.dietaryTags ?? {}) .filter(([, v]) => v) .map(([k]) => m.recipe.dietary[k as keyof typeof m.recipe.dietary]) .filter(Boolean); return ( <>

{recipe.title}

{recipe.description && (

{recipe.description}

)}
{recipe.baseServings && {formatMessage(m.recipe.servings, { count: recipe.baseServings })}} {recipe.prepMins && {formatMessage(m.recipe.prep, { mins: recipe.prepMins })}} {recipe.cookMins && {formatMessage(m.recipe.cook, { mins: recipe.cookMins })}} {totalMins > 0 && {formatMessage(m.recipe.total, { mins: totalMins })}} {recipe.difficulty && {recipe.difficulty.charAt(0).toUpperCase() + recipe.difficulty.slice(1)}}
{activeTags.length > 0 && (
{activeTags.map((tag) => ( {tag} ))}
)} {recipe.ingredients.length > 0 && ( <>

{m.recipe.ingredients}

)} {recipe.steps.length > 0 && ( <>

{m.recipe.instructions}

    {recipe.steps.map((step) => (
  1. {step.instruction} {step.timerSeconds && ( ⏱ {Math.floor(step.timerSeconds / 60)} min )}
  2. ))}
)}
); }