import { Card, CardContent, CardHeader, CardTitle } from "~/components/ui/card"; import { Utensils, Salad, Cake, CookingPot, Icon, Carrot, LogIn, CalendarCheck, Check, CheckCheck, Loader2, } from "lucide-react"; import { cheese } from "@lucide/lab"; import { registerForMeal, type Meal } from "~/lib/api"; import { Button } from "../ui/button"; import { toast } from "sonner"; import { useState } from "react"; import { getSavedCredentials } from "./credentials"; const getCourseIcon = (courseName: string) => { const name = courseName.toLowerCase(); if (name.includes("hors")) return ; if (name.includes("plat")) return ; if (name.includes("garniture")) return ; if (name.includes("fromage")) return ; if (name.includes("dessert")) return ; return ; }; export function DailyMenu({ meals, refetchMeals }: { meals: Meal[]; refetchMeals: () => Promise }) { if (meals.length === 0) { return (

Aucun menu disponible pour ce jour.

); } const [isLoading, setLoading] = useState(false); const credentials = getSavedCredentials(); const handleRegister = async (id: number) => { try { if (!credentials) { toast.error( "Veuillez d'abord enregistrer vos identifiants dans l'onglet BJRepas." ); return; } await registerForMeal(id, credentials.username, credentials.password); await refetchMeals(); setLoading(false); } catch (error) { console.error("Error registering for meal:", error); toast.error( "Une erreur est survenue lors de l'inscription au repas. Veuillez réessayer." ); } }; return (

{meals.length > 1 ? "Menus" : "Menu"} du jour

{meals.map((meal, mealIndex) => (
{meal.name}
{meal.courses.map((course, courseIndex) => (
{getCourseIcon(course.name)}

{course.name}

{course.description}

))}
{meal.submittable && (meal.isRegistered ? ( ) : isLoading ? ( ) : ( ))}
))}
); }