import { useState, Fragment } from "react";
import { useQuery } from "@tanstack/react-query";
import { ChefHat, X, Calendar } from "lucide-react";
import { usePageMeta } from "@/hooks/use-page-meta";
import Header from "@/components/header";
import Footer from "@/components/footer";
import { InArticleAd, PageSideAds, TopBannerAd, MultiplexAd } from "@/components/adsense";
interface DailyRecipe {
id: number;
dateStr: string;
name: string;
intro?: string;
recipe?: string;
seasonNote?: string | null;
imageUrl?: string | null;
}
const MONTHS_DE = ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli",
"August", "September", "Oktober", "November", "Dezember"];
function formatDate(dateStr: string): string {
const [y, m, d] = dateStr.split("-").map((x) => parseInt(x, 10));
if (!y || !m || !d) return dateStr;
return `${d}. ${MONTHS_DE[m - 1]} ${y}`;
}
function RecipeBody({ recipe }: { recipe: DailyRecipe }) {
return (
<>
{recipe.intro &&
{recipe.intro}
}
{recipe.recipe && (
{recipe.recipe}
)}
{recipe.seasonNote && {recipe.seasonNote}
}
>
);
}
export default function RecipesPage() {
usePageMeta(
"Rezepte - Alpenküche & Volksmusik",
"Das Rezept des Tages und alle bisherigen Rezepte aus der Alpenküche bei FOLX TV — österreichische, bayerische und schweizer Hausmannskost."
);
const [selected, setSelected] = useState(null);
const [page, setPage] = useState(0);
const PAGE_SIZE = 12;
const { data = [], isLoading } = useQuery({
queryKey: ["/api/recipes"],
staleTime: 1000 * 60 * 30,
});
const today = data[0];
const rest = data.slice(1);
const totalPages = Math.max(1, Math.ceil(rest.length / PAGE_SIZE));
const pageItems = rest.slice(page * PAGE_SIZE, (page + 1) * PAGE_SIZE);
const goPage = (p: number) => {
setPage(Math.max(0, Math.min(totalPages - 1, p)));
document.getElementById("rezept-archiv")?.scrollIntoView({ behavior: "smooth", block: "start" });
};
return (
Rezepte
Jeden Tag ein neues Rezept aus der Alpenküche — und das ganze Archiv zum Nachkochen.
{today && (
{today.imageUrl && (

)}
{formatDate(today.dateStr)}
{today.name}
)}
{rest.length > 0 && (
{rest.length} Rezepte · Seite {page + 1} von {totalPages}
{pageItems.map((r, idx) => (
{idx > 0 && idx % 4 === 0 && (
)}
))}
{totalPages > 1 && (
{Array.from({ length: totalPages }).map((_, i) => (
))}
)}
)}
{!isLoading && data.length === 0 && (
Noch keine Rezepte vorhanden.
)}
{selected && (
setSelected(null)}
data-testid="modal-recipe"
>
e.stopPropagation()}
>
{selected.imageUrl && (

)}
{formatDate(selected.dateStr)}
{selected.name}
)}
);
}