import React, { useMemo, useState } from 'react'; import { Box, Typography, Paper, IconButton, Chip, TextField, InputAdornment, Card, CardMedia, Badge, BottomNavigation, BottomNavigationAction, Button, Snackbar, Alert, } from '@mui/material'; import AddIcon from '@mui/icons-material/Add'; import RemoveIcon from '@mui/icons-material/Remove'; import SearchIcon from '@mui/icons-material/Search'; import ShoppingCartIcon from '@mui/icons-material/ShoppingCart'; import MicIcon from '@mui/icons-material/Mic'; import HomeIcon from '@mui/icons-material/Home'; import MenuBookIcon from '@mui/icons-material/MenuBook'; import TrackChangesIcon from '@mui/icons-material/TrackChanges'; import AutoAwesomeIcon from '@mui/icons-material/AutoAwesome'; import StarIcon from '@mui/icons-material/Star'; import { MENU_ITEMS, CATEGORIES } from '../../data/menuData'; import type { MenuItem, CategoryType } from '../../data/menuData'; import { StatusBadge } from '../common/StatusBadge'; import { useLocale } from '../../i18n/LocaleContext'; import { CartPeekDrawer } from './CartPeekDrawer'; interface MenuBrowseViewProps { cart: { [itemId: string]: number }; cartNotes?: { [itemId: string]: string }; menuItems?: MenuItem[]; onUpdateCart: (itemId: string, quantity: number) => void; onOpenCustomization: (item: MenuItem) => void; onOpenVoice: () => void; onNavigate: (view: 'landing' | 'menu' | 'cart' | 'status' | 'bill' | 'voice') => void; } const DIETARY_FILTERS = [ { label: 'All', value: null }, { label: '๐ŸŸข Veg', value: 'veg' }, { label: '๐Ÿ”ด Non-Veg', value: 'non-veg' }, { label: '๐ŸŒฟ Jain', value: 'jain' }, ]; const SPICE_ICONS: Record = { mild: '๐ŸŸก', medium: '๐ŸŸ ', hot: '๐Ÿ”ด', 'extra-hot': '๐Ÿ”ฅ', }; const tableLabel = () => sessionStorage.getItem('customer_table_number') || sessionStorage.getItem('customer_table_id') || 'โ€”'; export const MenuBrowseView: React.FC = ({ cart, cartNotes = {}, menuItems = MENU_ITEMS, onUpdateCart, onOpenCustomization, onOpenVoice, onNavigate, }) => { const { t } = useLocale(); const [activeCategory, setActiveCategory] = useState('All'); const [searchQuery, setSearchQuery] = useState(''); const [dietaryFilter, setDietaryFilter] = useState(null); const [bottomNav, setBottomNav] = useState(1); const [cartPeekOpen, setCartPeekOpen] = useState(false); const [emptyHint, setEmptyHint] = useState(false); const totalCartItems = Object.values(cart).reduce((a, b) => a + b, 0); const totalCartValue = Object.entries(cart).reduce((sum, [id, qty]) => { const item = menuItems.find((m) => String(m.id) === id); return sum + (item ? item.price * qty : 0); }, 0); const cartLines = useMemo( () => Object.entries(cart) .map(([id, qty]) => { const item = menuItems.find((m) => String(m.id) === id); if (!item) return null; return { item, qty, notes: cartNotes[id] }; }) .filter(Boolean) as { item: MenuItem; qty: number; notes?: string }[], [cart, cartNotes, menuItems] ); const filteredItems = useMemo(() => { return menuItems.filter((item) => { if (item.isAvailable === false) return false; const matchCategory = activeCategory === 'All' || item.category === activeCategory; const matchSearch = !searchQuery || item.name.toLowerCase().includes(searchQuery.toLowerCase()) || (item.nameHindi && item.nameHindi.includes(searchQuery)) || item.description.toLowerCase().includes(searchQuery.toLowerCase()); const matchDietary = !dietaryFilter || item.dietary === dietaryFilter; return matchCategory && matchSearch && matchDietary; }); }, [menuItems, activeCategory, searchQuery, dietaryFilter]); const openCartCheck = () => { setCartPeekOpen(true); }; const handleCartTap = () => { openCartCheck(); if (totalCartItems === 0) setEmptyHint(true); }; const handleBottomNav = (_: React.SyntheticEvent, newValue: number) => { setBottomNav(newValue); if (newValue === 0) onNavigate('landing'); if (newValue === 1) setBottomNav(1); if (newValue === 2) { openCartCheck(); if (totalCartItems === 0) setEmptyHint(true); setBottomNav(1); } if (newValue === 3) onNavigate('status'); }; return ( Menu Table {tableLabel()} ยท Tap dishes to add ยท Check cart anytime 0 ? '#ac2d00' : '#f2ede9', color: totalCartItems > 0 ? '#fff' : '#8f7068', '&:hover': { bgcolor: totalCartItems > 0 ? '#872100' : '#ede8e4' }, }} > setSearchQuery(e.target.value)} slotProps={{ input: { startAdornment: ( ), }, }} sx={{ '& .MuiOutlinedInput-root': { borderRadius: '12px', bgcolor: '#f8f5f2', '& fieldset': { border: '1px solid #e4ddd8' }, }, }} /> {CATEGORIES.map((cat) => { const catEmoji: Record = { All: '๐Ÿฝ๏ธ', Starters: '๐Ÿฅ—', Biryani: '๐Ÿš', Mains: '๐Ÿ›', Breads: '๐Ÿซ“', Drinks: '๐Ÿฅค', Desserts: '๐Ÿฎ', Specials: 'โญ', }; const isActive = activeCategory === cat; return ( setActiveCategory(cat)} sx={{ fontWeight: 800, flexShrink: 0, bgcolor: isActive ? '#ac2d00' : '#ffffff', color: isActive ? '#fff' : '#5b4139', border: isActive ? '2px solid #ac2d00' : '1.5px solid #e4ddd8', '&:hover': { bgcolor: isActive ? '#872100' : '#f5ede9' }, }} /> ); })} {DIETARY_FILTERS.map((f) => ( setDietaryFilter(f.value)} variant={dietaryFilter === f.value ? 'filled' : 'outlined'} color={dietaryFilter === f.value ? 'primary' : 'default'} sx={{ fontWeight: 700, flexShrink: 0 }} /> ))} Order with AI voice Say what you want โ€” we add it to your cart 0 ? 22 : 14 }}> {activeCategory !== 'All' && ( {activeCategory} ({filteredItems.length}) )} {filteredItems.length === 0 ? ( No dishes found Try a different search or filter ) : ( {filteredItems.map((item) => { const qty = cart[String(item.id)] || 0; return ( 0 ? '1.5px solid #ac2d00' : '1px solid #f0ebe7', overflow: 'hidden', bgcolor: '#ffffff', display: 'flex', boxShadow: '0 2px 10px rgba(0,0,0,0.04)', }} > {(item.isChefSpecial || item.isBestseller) && ( ) : ( ) } label={item.isChefSpecial ? 'Special' : 'Hit'} size="small" sx={{ position: 'absolute', top: 6, left: 6, height: 22, fontSize: '0.62rem', fontWeight: 800, bgcolor: 'rgba(0,0,0,0.7)', color: '#fff', }} /> )} {item.name} {item.description} โ‚น{item.price} {item.spiceLevel ? `${SPICE_ICONS[item.spiceLevel] || ''} ` : ''} {item.prepTimeMinutes} min {qty === 0 ? ( ) : ( onUpdateCart(String(item.id), qty - 1)} sx={{ color: '#fff', p: 0.7 }} > {qty} onUpdateCart(String(item.id), qty + 1)} sx={{ color: '#fff', p: 0.7 }} > )} ); })} )} {totalCartItems > 0 && ( View cart ยท {totalCartItems} item{totalCartItems === 1 ? '' : 's'} โ‚น{totalCartValue.toFixed(0)} )} } sx={{ '&.Mui-selected': { color: '#ac2d00' } }} /> } sx={{ '&.Mui-selected': { color: '#ac2d00' } }} /> } sx={{ '&.Mui-selected': { color: '#ac2d00' } }} /> } sx={{ '&.Mui-selected': { color: '#ac2d00' } }} /> setCartPeekOpen(false)} onUpdateCart={onUpdateCart} onContinueShopping={() => setCartPeekOpen(false)} onCheckout={() => { setCartPeekOpen(false); onNavigate('cart'); }} /> setEmptyHint(false)} anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }} sx={{ bottom: { xs: 140, sm: 140 } }} > setEmptyHint(false)} sx={{ fontWeight: 700, borderRadius: '12px' }}> Cart is empty โ€” add a dish, then check it here anytime. ); };