"use client"; // Mobile Ansicht der öffentlichen Speisekarte: Tag (Standard) oder Woche, // umschaltbar ohne Seiten-Reload. Ab dem "sm"-Breakpoint übernimmt die // normale Wochentabelle (siehe app/page.tsx), diese Komponente blendet // sich dort per CSS aus. import Link from "next/link"; import { useRouter } from "next/navigation"; import { useState } from "react"; import { addDays, dishCodes, entriesFor, formatDateLong, formatPrice, mondayOf, todayISO, weekdayIndex, WEEKDAYS, WEEKDAYS_SHORT, } from "@/lib/menu"; import type { MenuEntry, Section } from "@/lib/types"; export default function PublicMobileMenu({ monday, sections, entries, }: { monday: string; sections: Section[]; entries: MenuEntry[]; }) { const router = useRouter(); const days = WEEKDAYS.map((weekday, i) => ({ weekday, short: WEEKDAYS_SHORT[i], iso: addDays(monday, i), })); const isCurrentWeek = monday === mondayOf(todayISO()); const todayIdx = isCurrentWeek ? weekdayIndex(todayISO()) : -1; const [tab, setTab] = useState<"tag" | "woche">("tag"); const [selectedIdx, setSelectedIdx] = useState(todayIdx >= 0 ? todayIdx : 0); function goToday() { const currentMonday = mondayOf(todayISO()); if (currentMonday === monday) { const idx = weekdayIndex(todayISO()); setSelectedIdx(idx >= 0 ? idx : 0); setTab("tag"); } else { router.push(`/?woche=${currentMonday}`); } } function renderDay(day: { weekday: string; iso: string }) { return (

{day.weekday} · {formatDateLong(day.iso)}

{sections.map((s) => { const items = entriesFor(entries, day.iso, s.key); return (
{s.label}{" "} · {s.time_range}
{items.length === 0 ? (

–

) : ( items.map((e) => { const codes = dishCodes(e.dish); return (

{e.dish.name} {codes && {codes}}{" "} – {formatPrice(e.dish.price)}

); }) )}
); })}
); } return (
← Woche Woche →
{tab === "tag" ? ( <>
{days.map((d, i) => ( ))}
{renderDay(days[selectedIdx])} ) : (
{days.map((d) => renderDay(d))}
)}
); }