'use client' import React, { useState } from 'react' import { Gutter } from '@payloadcms/ui' import './styles.scss' interface KitchenReportResponse { date: string mealType: string totalMeals: number ingredients: Record labels: Record portionSizes?: Record error?: string } export const KitchenDashboard: React.FC = () => { const [date, setDate] = useState(() => { const today = new Date() return today.toISOString().split('T')[0] }) const [mealType, setMealType] = useState<'breakfast' | 'lunch' | 'dinner'>('breakfast') const [loading, setLoading] = useState(false) const [error, setError] = useState(null) const [report, setReport] = useState(null) const generateReport = async () => { setLoading(true) setError(null) setReport(null) try { const response = await fetch( `/api/meals/kitchen-report?date=${date}&mealType=${mealType}`, { credentials: 'include', }, ) const data = await response.json() if (!response.ok) { throw new Error(data.error || 'Failed to generate report') } setReport(data) } catch (err) { setError(err instanceof Error ? err.message : 'An error occurred') } finally { setLoading(false) } } const getMealTypeLabel = (type: string) => { switch (type) { case 'breakfast': return 'Breakfast (Frühstück)' case 'lunch': return 'Lunch (Mittagessen)' case 'dinner': return 'Dinner (Abendessen)' default: return type } } const formatDate = (dateStr: string) => { const d = new Date(dateStr) return d.toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric', }) } return (

Kitchen Dashboard

Generate ingredient reports for meal preparation

setDate(e.target.value)} className="kitchen-dashboard__input" />
{error && (
Error: {error}
)} {report && (

Ingredient Report

Date: {formatDate(report.date)} Meal: {getMealTypeLabel(report.mealType)} Total Meals: {report.totalMeals}
{report.totalMeals === 0 ? (

No meals found for this date and meal type.

) : ( <> {report.portionSizes && Object.keys(report.portionSizes).length > 0 && (

Portion Sizes

{Object.entries(report.portionSizes).map(([size, count]) => (
{size === 'small' ? 'Small (Kleine)' : size === 'large' ? 'Large (Große)' : 'Vegetarian'} {count}
))}
)}

Ingredients Required

{Object.keys(report.ingredients).length === 0 ? (

No specific ingredients selected in orders.

) : ( {Object.entries(report.ingredients) .sort(([, a], [, b]) => b - a) .map(([key, count]) => ( ))}
Ingredient Quantity
{report.labels[key] || key} {count}
Total Items {Object.values(report.ingredients).reduce((a, b) => a + b, 0)}
)}
)}
)}
) } export default KitchenDashboard