"use client"; import { RiAlertLine as AlertTriangle, RiArrowRightLine as ArrowRight, RiArrowLeftRightLine as ArrowRightLeft, RiDeleteBinLine as Trash2, RiCloseLine as X } from "@remixicon/react"; import Link from "next/link"; import { useEffect, useRef } from "react"; import { DAY_NAMES, describeBlockers, isCookable, mealLabel, recipeBlockers } from "@/app/lib/plan"; import { RECIPES_BY_ID } from "@/app/lib/recipes"; import type { MealPlanState } from "@/app/types"; import { RecipeDetail, RecipeMeta } from "./RecipeDetail"; import { Button } from "@/components/base/buttons/button"; interface RecipeDialogProps { slotKey: string | null; state: MealPlanState; onClose: () => void; onSwap: (slotKey: string) => void; onRemove: (slotKey: string, recipeTitle: string) => void; } export function RecipeDialog({ slotKey, state, onClose, onSwap, onRemove }: RecipeDialogProps) { const dialogRef = useRef(null); const recipe = slotKey ? RECIPES_BY_ID.get(state.slots[slotKey]) : undefined; const open = Boolean(slotKey && recipe); useEffect(() => { const dialog = dialogRef.current; if (!dialog) return; if (open && !dialog.open) dialog.showModal(); if (!open && dialog.open) dialog.close(); return () => { if (dialog.open) dialog.close(); }; }, [open]); const [dayIndex, mealNumber] = (slotKey ?? "0-1").split("-").map(Number); return ( e.target === dialogRef.current && onClose()} aria-labelledby="recipe-dialog-title" className="m-0 mt-auto max-h-[92dvh] w-full max-w-none overflow-y-auto rounded-t-3xl border border-line bg-surface p-0 text-ink shadow-2xl sm:m-auto sm:max-w-3xl sm:rounded-3xl" > {open && recipe && slotKey && (

{DAY_NAMES[dayIndex]} ยท {mealLabel(mealNumber)}

{recipe.title}

{recipe.description}

{!isCookable(recipe, state) && (

{describeBlockers(recipeBlockers(recipe, state))}. Consider swapping this meal.

)}
Full recipe & cook mode
)}
); }