"use client"; import { useState, useTransition } from "react"; import { useTranslations } from "next-intl"; import { useRouter, usePathname } from "next/navigation"; import Link from "next/link"; import Image from "next/image"; import { FolderOpen, Flame, Search } from "lucide-react"; import { Badge } from "@/components/ui/badge"; import { Input } from "@/components/ui/input"; import { buttonVariants } from "@/components/ui/button"; import { NewCollectionButton } from "@/components/social/new-collection-button"; import { EmptyState } from "@/components/shared/empty-state"; import { RecipeCoverPlaceholder } from "@/components/recipe/recipe-cover-placeholder"; import { cn } from "@/lib/utils"; type Thumbnail = { recipeId: string; recipeType?: "dish" | "drink"; coverIcon: string | null; coverColor: string | null; photoUrl: string | null; }; type Collection = { id: string; name: string; description: string | null; tags: string[]; visibility: "private" | "unlisted" | "public" | "followers"; recipeCount: number; thumbnails: Thumbnail[]; }; type Props = { collections: Collection[]; query: string; }; function CollectionThumbCollage({ thumbnails }: { thumbnails: Thumbnail[] }) { if (thumbnails.length === 0) { return (
); } return (
{Array.from({ length: 4 }).map((_, i) => { const thumb = thumbnails[i]; return (
{thumb ? ( thumb.photoUrl ? ( ) : ( ) ) : null}
); })}
); } export function CollectionsPageContent({ collections, query }: Props) { const t = useTranslations("collections"); const tRecipe = useTranslations("recipe"); const router = useRouter(); const pathname = usePathname(); const [search, setSearch] = useState(query); const [, startTransition] = useTransition(); function handleSearch(value: string) { setSearch(value); const params = new URLSearchParams(); if (value.trim()) params.set("q", value.trim()); startTransition(() => router.push(`${pathname}?${params.toString()}`)); } return (

{t("title")}

{t("subtitle")}

{t("discoverTitle")}
handleSearch(e.target.value)} placeholder={t("searchPlaceholder")} className="pl-9" />
{collections.length === 0 ? ( : undefined} /> ) : (
{collections.map((col) => (

{col.name}

{col.visibility !== "private" && ( {tRecipe(`visibility.${col.visibility}`)} )}
{col.description &&

{col.description}

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

{col.recipeCount !== 1 ? t("recipeCountPlural", { count: col.recipeCount }) : t("recipeCount", { count: col.recipeCount })}

))}
)}
); }