"use client"; import { useState, useEffect } from "react"; import { useTranslations } from "next-intl"; import Link from "next/link"; import { Clock, Users, ChefHat, Flame, Heart, Sparkles } from "lucide-react"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Badge } from "@/components/ui/badge"; import { useLocale } from "@/lib/i18n/provider"; type FeedRecipe = { id: string; title: string; description: string | null; baseServings: number; prepMins: number | null; cookMins: number | null; difficulty: string | null; aiGenerated: boolean; createdAt: string; authorId: string; authorName: string; authorUsername: string | null; authorAvatarUrl: string | null; visibility: string; favoriteCount?: number; }; type Props = { followedCount: number; feedRecipes: FeedRecipe[]; }; function RecipeCard({ recipe, locale }: { recipe: FeedRecipe; locale: string }) { return (
{recipe.authorName.slice(0, 2).toUpperCase()}
{recipe.authorName} {new Date(recipe.createdAt).toLocaleDateString(locale, { month: "short", day: "numeric" })}
{recipe.favoriteCount !== undefined && recipe.favoriteCount > 0 && ( {recipe.favoriteCount} )} {recipe.aiGenerated && AI}

{recipe.title}

{recipe.description && (

{recipe.description}

)}
{recipe.difficulty && {recipe.difficulty}} {recipe.baseServings} {recipe.prepMins && {recipe.prepMins}m} {recipe.cookMins && {recipe.cookMins}m}
); } function TrendingTab() { const { locale } = useLocale(); const t = useTranslations("feed"); const [recipes, setRecipes] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { fetch("/api/v1/feed/trending") .then((r) => r.json() as Promise<{ data: FeedRecipe[] }>) .then(({ data }) => setRecipes(data)) .catch(() => {}) .finally(() => setLoading(false)); }, []); if (loading) return

{t("loading")}

; if (recipes.length === 0) return

{t("trendingEmpty")}

; return (
{recipes.map((recipe) => ( ))}
); } function ForYouTab() { const { locale } = useLocale(); const t = useTranslations("feed"); const [recipes, setRecipes] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { fetch("/api/v1/feed/for-you") .then((r) => r.json() as Promise<{ data: FeedRecipe[] }>) .then(({ data }) => setRecipes(data)) .catch(() => {}) .finally(() => setLoading(false)); }, []); if (loading) return

{t("loading")}

; if (recipes.length === 0) return

{t("forYouEmpty")}

; return (
{recipes.map((recipe) => ( ))}
); } export function FeedPageContent({ followedCount, feedRecipes }: Props) { const t = useTranslations("feed"); const { locale } = useLocale(); const [tab, setTab] = useState<"following" | "trending" | "forYou">("following"); return (

{t("title")}

{/* Tabs */}
{tab === "following" ? ( followedCount === 0 ? (

{t("followEmpty")}

) : feedRecipes.length === 0 ? (

{t("noNew")}

) : (
{feedRecipes.map((recipe) => ( ))}
) ) : tab === "trending" ? ( ) : ( )}
); }