"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, } from "@/lib/menu"; import { localized } from "@/lib/types"; import type { MenuEntry, Section } from "@/lib/types"; import { useDict, useLocale } from "@/components/i18n/LocaleProvider"; import LanguageSwitcher from "@/components/i18n/LanguageSwitcher"; export default function PublicMobileMenu({ monday, sections, entries, showLabeling, }: { monday: string; sections: Section[]; entries: MenuEntry[]; showLabeling: boolean; }) { const router = useRouter(); const dict = useDict(); const locale = useLocale(); const days = dict.weekdays.long.map((weekday, i) => ({ weekday, short: dict.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, dict.dateLocale)}

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

{dict.publicMenu.noEntry}

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

{localized(e.dish, locale)} {showLabeling && codes && ( {codes} )}{" "} – {formatPrice(e.dish.price)}

); }) )}
); })}
); } return (
{dict.publicMenu.prevWeekShort} {dict.publicMenu.nextWeekShort}
{tab === "tag" ? ( <>
{days.map((d, i) => ( ))}
{renderDay(days[selectedIdx])} ) : (
{days.map((d) => renderDay(d))}
)} {dict.publicMenu.suggestDish}
); }