"use client"; import { Check, Plus, Repeat2 } from "lucide-react"; import { useState } from "react"; export interface OverlapDish { id: string; title: string; cuisine: string; standaloneCheckout: number; } export interface OverlapComboSnapshot { checkoutTotal: number; usedTotal: number; carryoverValue: number; sharedNames: string[]; packageCount: number; } interface OverlapExplorerProps { dishes: OverlapDish[]; /** Keyed by sorted comma-joined dish IDs; precomputed on the server so zero catalog data ships to the landing bundle. */ combos: Record; } const fmt = (n: number) => `$${n.toFixed(2)}`; export function OverlapExplorer({ dishes, combos }: OverlapExplorerProps) { const [selected, setSelected] = useState(() => dishes.slice(0, 2).map((d) => d.id)); function toggleDish(id: string) { setSelected((prev) => { if (prev.includes(id)) { return prev.length > 1 ? prev.filter((x) => x !== id) : prev; // keep at least 1 selected } return [...prev, id]; }); } const comboKey = [...selected].sort().join(","); const current = combos[comboKey]; const naiveSum = dishes.filter((d) => selected.includes(d.id)).reduce((acc, d) => acc + d.standaloneCheckout, 0); const saved = Math.max(0, naiveSum - (current?.checkoutTotal ?? 0)); return (

Interactive checkout math · 2 people

Toggle dishes to watch shared packages drop the bill

Grocery stores sell whole bags of onions, rice, and spices—not single tablespoons. Selecting meals that reuse open packages slashes what each extra dinner adds at the register.

    {dishes.map((dish) => { const active = selected.includes(dish.id); return (
  • ); })}
{/* Simulated paper receipt */}
Checkout Receipt {selected.length} {selected.length === 1 ? "meal" : "meals"}
Buying each meal separately
{fmt(naiveSum)}
{saved > 0.01 && (
Shared-package savings
−{fmt(saved)}
)}
Combined register total
{fmt(current?.checkoutTotal ?? 0)}
Food eaten
{fmt(current?.usedTotal ?? 0)}
Kept in pantry
{fmt(current?.carryoverValue ?? 0)}
{current && current.sharedNames.length > 0 ? (

Reused across meals: {current.sharedNames.slice(0, 5).join(", ")} {current.sharedNames.length > 5 ? ` +${current.sharedNames.length - 5} more` : ""}

) : (

Select a second dish to see which store packages overlap in your cart.

)}
); }