/* ═══════════════════════════════════════════ MENU ═══════════════════════════════════════════ */ function renderMenu() { // Build categories const cs = document.getElementById('cat-scroll'); if (!cs.innerHTML) { CATS.forEach(c => { const d = document.createElement('div'); d.className = 'cat-item' + (c === activeCategory ? ' active' : ''); d.innerHTML = `
${CAT_EMOJI[c]||'🍽'}
${c}
`; d.onclick = () => { document.querySelectorAll('.cat-item').forEach(x => x.classList.remove('active')); d.classList.add('active'); activeCategory = c; renderMenuGrid(); document.getElementById('menu-section-label').textContent = c === 'All' ? 'Top rated for you' : c; }; cs.appendChild(d); }); } renderMenuGrid(); } function filterMenuItems() { renderMenuGrid(); } function renderMenuGrid() { const grid = document.getElementById('items-grid'); if (MENU.length === 0) { grid.innerHTML = '
Loading menu...
'; return; } const q = document.getElementById('menu-search-input')?.value.toLowerCase() || ''; let filtered = MENU.filter(item => { const matchCat = activeCategory === 'All' || item.cat === activeCategory; const matchQ = !q || item.name.toLowerCase().includes(q) || item.sub.toLowerCase().includes(q); return matchCat && matchQ; }); const sortVal = document.getElementById('menu-sort')?.value; if (sortVal === 'price-low') filtered.sort((a,b) => a.price - b.price); if (sortVal === 'price-high') filtered.sort((a,b) => b.price - a.price); if (sortVal === 'rating') filtered.sort((a,b) => b.rating - a.rating); grid.innerHTML = filtered.map(item => { const inCart = cart.find(c => c.id === item.id); const imgHtml = item.img ? `${item.name}` : ''; const isOutOfStock = parseInt(item.stock) <= 0; const isPopular = parseInt(item.popularity) > 10; // Mark as popular if ordered more than 10 times let qtyControls = ''; if (isOutOfStock) { qtyControls = ``; } else if (inCart) { qtyControls = ``; } else { qtyControls = ``; } return `
${imgHtml} ${item.emoji} ${isPopular ? `` : ''}
${item.name}
${item.sub}
`; }).join(''); updateCartIndicators(); } function sortMenuItems(val) { renderMenuGrid(); } function changeMenuQty(id, delta) { const item = cart.find(c => c.id === id); if (!item) return; item.qty += delta; if (item.qty <= 0) cart = cart.filter(c => c.id !== id); renderMenuGrid(); updateCartIndicators(); }