import type { Metadata } from "next"; import { notFound } from "next/navigation"; import { headers } from "next/headers"; import Link from "next/link"; import { Printer, UtensilsCrossed, StickyNote, ExternalLink } from "lucide-react"; import { auth } from "@/lib/auth/server"; import { db, collections, eq, and } from "@epicure/db"; import { collectionVisibleToViewer } from "@/lib/visibility"; import { RecipeGridCard } from "@/components/recipe/recipe-grid-card"; import { CollectionRecipesGrid } from "@/components/collections/collection-recipes-grid"; import { ForkCollectionButton } from "@/components/collections/fork-collection-button"; import { ShareCollectionButton } from "@/components/collections/share-collection-button"; import { GenerateMealDialog } from "@/components/collections/generate-meal-dialog"; import { EditCollectionDialog } from "@/components/collections/edit-collection-dialog"; import { DeleteCollectionDialog } from "@/components/collections/delete-collection-dialog"; import { Badge } from "@/components/ui/badge"; import { buttonVariants } from "@/components/ui/button"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; import { cn } from "@/lib/utils"; import { ExportMarkdownButton } from "@/components/shared/export-markdown-button"; import { EmptyState } from "@/components/shared/empty-state"; import { collectionToMarkdown } from "@/lib/markdown/collection"; import { getMessages } from "@/lib/i18n/server"; type Params = { params: Promise<{ id: string }> }; export const metadata: Metadata = {}; export default async function CollectionPage({ 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 col = await db.query.collections.findFirst({ where: and(eq(collections.id, id), collectionVisibleToViewer(session.user.id)), with: { recipes: { orderBy: (t, { asc }) => asc(t.position), with: { recipe: { with: { photos: true } } }, }, }, }); if (!col) notFound(); const isOwner = col.userId === session.user.id; const recipeList = col.recipes.flatMap((r) => (r.recipe ? [r.recipe] : [])); return (

{col.name}

{col.description &&

{col.description}

} {col.tags.length > 0 && (
{col.tags.map((tag) => ( {tag} ))}
)}

{recipeList.length} recipe{recipeList.length !== 1 ? "s" : ""} ยท {m.recipe.visibility[col.visibility]}

{isOwner && col.notes && (

{col.notes}

)}
{recipeList.length > 0 && ( <> } /> {m.collections.exportPdf} )} {isOwner && } {isOwner && } {isOwner && ( )} {isOwner && } {col.visibility === "public" && ( } /> {m.recipe.viewPublicly} )} {!isOwner && (col.visibility === "public" || col.visibility === "unlisted") && ( )}
{recipeList.length === 0 ? ( ) : isOwner ? ( ) : (
{recipeList.map((recipe) => ( ))}
)}
); }