const numeroWhatsApp = "2250140555666"; // --- NORMALISATION ET FUSION DES DONNÉES --- const allProducts = [ ...(window.MENU_PLATS || []), ...(window.MENU_PIZZAS || []), ...(window.MENU_TACOS || []), ...(window.MENU_BOISSONS || []) ].filter(p => p && p.disponible !== false) .map(p => ({ ...p, id: String(p.id), prix: Number(p.prix || 0) })) .sort((a, b) => Number(a.id) - Number(b.id)); let cart = []; let activeCategory = "ALL"; let searchTerm = ""; // --- SÉLECTION DES ÉLÉMENTS DOM --- const el = { categoryTabs: document.getElementById("categoryTabs"), menuContainer: document.getElementById("menuContainer"), searchInput: document.getElementById("searchInput"), cartItems: document.getElementById("cartItems"), cartTotal: document.getElementById("cartTotal"), mobileTotal: document.getElementById("mobileTotal"), whatsappBtn: document.getElementById("whatsappBtn"), modal: document.getElementById("optionModal"), modalContent: document.getElementById("modalContent") }; // --- FONCTIONS UTILES --- function formatPrice(n) { return Number(n || 0).toLocaleString("fr-FR") + " FCFA"; } function escapeHtml(str) { return String(str).replace(/[&<>"']/g, s => ({"&":"&","<":"<",">":">",'"':""","'":"'"}[s])); } // --- RENDU DU MENU --- function renderMenu() { const cats = ["ALL", ...new Set(allProducts.map(p => p.categorie))]; el.categoryTabs.innerHTML = cats.map(cat => ` `).join(""); const filtered = allProducts.filter(p => (activeCategory === "ALL" || p.categorie === activeCategory) && (normalize(p.nom).includes(normalize(searchTerm))) ); const groups = filtered.reduce((acc, p) => { (acc[p.categorie] = acc[p.categorie] || []).push(p); return acc; }, {}); el.menuContainer.innerHTML = Object.keys(groups).map(cat => `

${cat}

${groups[cat].map(p => `

${p.nom}

${p.description || ""}

${formatPrice(p.prix)}
`).join("")}
`).join(""); } // --- PANIER ET COMMANDE --- function addToCart(id) { const product = allProducts.find(p => p.id === id); const existing = cart.find(x => x.id === id); if (existing) existing.qty += 1; else cart.push({ ...product, qty: 1 }); renderCart(); } function renderCart() { el.cartItems.innerHTML = cart.length === 0 ? "Votre panier est vide." : cart.map(item => `
${item.qty} x ${item.nom}
${formatPrice(item.prix * item.qty)}
`).join(""); const total = cart.reduce((sum, i) => sum + (i.prix * i.qty), 0); el.cartTotal.textContent = formatPrice(total); el.mobileTotal.textContent = formatPrice(total); } function updateQty(id, delta) { const item = cart.find(x => x.id === id); if (item) { item.qty += delta; if (item.qty <= 0) cart = cart.filter(x => x.id !== id); } renderCart(); } // --- ENVOI WHATSAPP (CONSERVE VOS TEXTES) --- el.whatsappBtn.addEventListener("click", () => { const name = document.getElementById("clientName").value; const address = document.getElementById("clientAddress").value; if(!name || !address) return alert("Veuillez remplir votre nom et votre adresse."); let msg = `🍽️ COMMANDE LA SHISH\nClient: ${name}\nAdresse: ${address}\n\n🛒 Détails:\n`; msg += cart.map(i => `${i.qty}x ${i.nom} (${formatPrice(i.prix)})`).join("\n"); msg += `\n\nTotal: ${el.cartTotal.textContent}`; msg += `\n\n🚚 Livraison à charge du client (Yango).`; msg += `\n💳 Paiement Wave à la validation.`; window.open(`https://wa.me/${numeroWhatsApp}?text=${encodeURIComponent(msg)}`, "_blank"); }); function normalize(str) { return String(str).toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, ""); } // Écouteurs d'événements document.addEventListener("click", (e) => { if (e.target.dataset.category) { activeCategory = e.target.dataset.category; renderMenu(); } }); el.searchInput.addEventListener("input", e => { searchTerm = e.target.value; renderMenu(); }); renderMenu(); renderCart();