function formatEuro(value) { return `${Number(value || 0).toFixed(2).replace(".", ",")} EUR`; } function escapeHtml(value) { return String(value || "") .replaceAll("&", "&") .replaceAll("<", "<") .replaceAll(">", ">") .replaceAll('"', """) .replaceAll("'", "'"); } function buildCartKey(item) { const infoText = item.category === "movie" ? `Sitz: ${item.seatId} (${item.hall})` : item.time; return `${item.title}-${item.hall}-${infoText}`; } function isDrinkItem(item) { if (item.category !== "snack") { return false; } const title = String(item.title || "").toLowerCase(); const size = String(item.hall || "").toLowerCase(); const drinkKeywords = [ "cola", "sprite", "fanta", "mezzo", "fuze", "wasser", "getraenk", "drink" ]; return drinkKeywords.some((word) => title.includes(word)) || size.includes("l"); } function buildItemInfo(item) { if (item.category === "movie") { return `
Sitzplatz: ${escapeHtml(item.seatId || "-")}
Saal: ${escapeHtml(item.hall || "-")}
Uhrzeit: ${escapeHtml(item.time || "-")} Uhr
`; } if (isDrinkItem(item)) { return `
Variante: ${escapeHtml(item.time || "-")}
Groesse: ${escapeHtml(item.hall || "-")}
`; } return `
Kategorie: Snack
Variante: ${escapeHtml(item.time || "-")}
Groesse: ${escapeHtml(item.hall || "-")}
`; } function groupCartItems() { const groups = new Map(); cart.forEach((item) => { const key = buildCartKey(item); if (!groups.has(key)) { groups.set(key, { key, quantity: 0, total: 0, item }); } const group = groups.get(key); group.quantity += 1; group.total += Number(item.price || 0); }); return Array.from(groups.values()); } function saveCart() { localStorage.setItem("eagleCart", JSON.stringify(cart)); updateCartBadge(); } function updateCartBadge() { const cartBadge = document.getElementById("cart-badge"); if (!cartBadge) { return; } cartBadge.innerText = cart.length; cartBadge.classList.toggle("hidden", cart.length === 0); } function renderCart() { const cartList = document.getElementById("cart-items-list"); const totalEl = document.getElementById("cart-total-right"); const vatEl = document.getElementById("cart-vat-right"); if (!cartList || !totalEl || !vatEl) { return; } if (!Array.isArray(cart) || cart.length === 0) { cartList.innerHTML = '

Dein Warenkorb ist leer.

'; totalEl.innerText = formatEuro(0); vatEl.innerText = `inkl. 19% MwSt: ${formatEuro(0)}`; return; } const groupedItems = groupCartItems(); const header = /*html*/`
MENGE
VORSCHAU
NAME
INFO
PREIS
AKTION
`; const rows = groupedItems .map((group) => { const imageHtml = group.item.img ? /*html*/`${escapeHtml(group.item.title)}` : /*html*/`
Kein Bild
`; const quantityHtml = group.item.category === "movie" ? /*html*/`
${group.quantity}x
` : /*html*/`
${group.quantity}
`; return /*html*/`
${quantityHtml}
${imageHtml}
${escapeHtml(group.item.title)}
${buildItemInfo(group.item)}
${formatEuro(group.total)}
`; }) .join(""); cartList.innerHTML = header + rows; const total = cart.reduce((sum, item) => sum + Number(item.price || 0), 0); const vat = total - total / 1.19; totalEl.innerText = formatEuro(total); vatEl.innerText = `inkl. 19% MwSt: ${formatEuro(vat)}`; saveCart(); } window.removeItem = function removeItem(id) { cart = cart.filter((item) => item.id !== id); saveCart(); renderCart(); }; window.changeQty = function changeQty(title, delta) { if (delta > 0) { const item = cart.find((entry) => entry.title === title); if (item) { cart.push({ ...item, id: Date.now() + Math.random() }); } } else { const index = cart .map((entry) => entry.title) .lastIndexOf(title); if (index !== -1) { cart.splice(index, 1); } } saveCart(); renderCart(); };