const translations = { de: { title: "Co&Sher - Ihre Koscher Bäckerei", welcomeMessage: "Frische Backwaren mit Liebe gemacht", orderNow: "Jetzt bestellen", viewProducts: "Produkte ansehen", navProducts: "Produkte", navAbout: "Über uns", navTestimonials: "Bewertungen", navContact: "Kontakt", ourProducts: "Unsere Produkte", orderTitle: "Ihre Bestellung", orderButton: "Bestellung aufgeben", payButton: "Bestellen und online bezahlen", viewOrders: "Bestellungen ansehen", ordersTitle: "Alle Bestellungen bei Co&sher", backToOrder: "Zurück zur Bestellung", weight: "Gewicht", price: "Preis", pieces: "Stk.", orderPlaced: "Bestellung aufgegeben! Sie erhalten die Zahlungsdetails bald über Telegram.", orderError: "Fehler beim Aufgeben der Bestellung. Bitte versuchen Sie es später erneut.", customerInfo: "Ihre Daten", nameLabel: "Name", phoneLabel: "Telefonnummer (Telegram)", itemName: "Produkt", itemImage: "Bild", quantity: "Menge", subtotal: "Zwischensumme", total: "Gesamt", customer: "Kunde", phone: "Telefon", date: "Datum", orderConfirmationTitle: "Bestellung aufgegeben", orderConfirmationMessage: "Ihre Bestellung wurde erfolgreich aufgegeben! Bitte warten Sie auf die Zahlungsdetails über Telegram.", close: "Schließen", aboutTitle: "Über unsere Bäckerei", aboutText1: "Co&Sher Bakers ist ein koscherer Bäcker in Wien, der die Traditionen des osteuropäischen Backens fortführt und ausschließlich natürliche Zutaten und bewährte Rezepte verwendet.", aboutText2: "Jeden Tag kreieren unsere Bäcker unter der strengen Aufsicht der Mashgiach unübertroffene Desserts, damit Sie den wahren Geschmack traditioneller koscherer Süßigkeiten genießen können. Bestellen Sie die Lieferung und probieren Sie noch heute unsere Backwaren!", galleryTitle: "Gallery", testimonialsTitle: "Was unsere Kunden sagen", testimonial1Text: "Die besten Croissants in der Stadt! Immer frisch und unglaublich lecker.", testimonial1Author: "Anna, Stammkundin", testimonial2Text: "Der Napoleon ist einfach magisch! Danke für so leckere Desserts.", testimonial2Author: "Michael, Naschkatze", testimonial3Text: "Ich liebe Ihr Baguette – perfekt zum Frühstückskaffee!", testimonial3Author: "Elena, Anwohnerin", contactTitle: "Kontaktieren Sie uns", contactLocation: "Wir befinden uns in Wien, Österreich", contactPhoneLabel: "Telefon:", contactEmailLabel: "Email:", contactHoursLabel: "Öffnungszeiten:", contactHours: "Mo-So, 8:00–20:00", footerText: "© 2025 Co&Sher Bäckerei", emailLabel: "Email (optional)", emailError: "Bitte geben Sie eine gültige Email-Adresse ein", deliveryDateLabel: "Gewünschtes Lieferdatum", deliveryDateError: "Bitte wählen Sie ein gültiges Datum" }, en: { title: "Co&Sher - Your Kosher Bakery", welcomeMessage: "Freshly baked goods made with love", orderNow: "Order Now", viewProducts: "View Products", navProducts: "Products", navAbout: "About Us", navTestimonials: "Testimonials", navContact: "Contact", ourProducts: "Our Products", orderTitle: "Your Order", orderButton: "Place Order", payButton: "Order and Pay Online", viewOrders: "View Orders", ordersTitle: "All Orders at Co&Sher", backToOrder: "Back to Order", weight: "Weight", price: "Price", pieces: "pcs.", orderPlaced: "Order placed! You will receive payment details via Telegram soon.", orderError: "Error placing order. Please try again later.", customerInfo: "Your Details", nameLabel: "Name", phoneLabel: "Phone Number (Telegram)", itemName: "Item", itemImage: "Image", quantity: "Quantity", subtotal: "Subtotal", total: "Total", customer: "Customer", phone: "Phone", date: "Date", orderConfirmationTitle: "Order Placed", orderConfirmationMessage: "Your order has been successfully placed! Please wait for payment details via Telegram.", close: "Close", aboutTitle: "About Our Bakery", aboutText1: "Co&Sher Bakery is a kosher bakery in Vienna that continues the traditions of Eastern European baking, using only natural ingredients and proven recipes.", aboutText2: "Every day, our bakers create unrivaled desserts under the strict supervision of the Mashgiach so that you can enjoy the real taste of traditional kosher sweets. Order delivery and try our pastries today!", galleryTitle: "Gallery", testimonialsTitle: "What Our Customers Say", testimonial1Text: "The best croissants in town! Always fresh and incredibly delicious.", testimonial1Author: "Anna, Regular Customer", testimonial2Text: "The Napoleon is simply magical! Thanks for such delicious desserts.", testimonial2Author: "Michael, Sweet Tooth", testimonial3Text: "I love your baguette – perfect with morning coffee!", testimonial3Author: "Elena, Local Resident", contactTitle: "Contact Us", contactLocation: "We are located in Vienna, Austria", contactPhoneLabel: "Phone:", contactEmailLabel: "Email:", contactHoursLabel: "Opening Hours:", contactHours: "Mon-Sun, 8:00–20:00", footerText: "© 2025 Co&Sher Bakery", emailLabel: "Email (optional)", emailError: "Please enter a valid email address", deliveryDateLabel: "Desired Delivery Date", deliveryDateError: "Please select a valid date" } }; function updateLanguage(lang) { document.querySelectorAll('[data-i18n]').forEach(element => { const key = element.getAttribute('data-i18n'); if (translations[lang][key]) { element.innerHTML = translations[lang][key]; } else { console.warn(`Translation key "${key}" not found for language "${lang}"`); element.innerHTML = key; } }); document.documentElement.lang = lang; localStorage.setItem('language', lang); updateErrorMessages(lang); const currentLanguageElement = document.getElementById('currentLanguage'); if (currentLanguageElement) { currentLanguageElement.textContent = lang.toUpperCase(); } } function updateErrorMessages(lang) { const nameError = document.getElementById('nameError'); const phoneError = document.getElementById('phoneError'); const emailError = document.getElementById('emailError'); const deliveryDateError = document.getElementById('deliveryDateError'); if (nameError) nameError.textContent = lang === 'de' ? 'Bitte geben Sie Ihren Namen ein' : 'Please enter your name'; if (phoneError) phoneError.textContent = lang === 'de' ? 'Bitte geben Sie eine gültige Telefonnummer ein' : 'Please enter a valid phone number'; if (emailError) emailError.textContent = lang === 'de' ? 'Bitte geben Sie eine gültige Email-Adresse ein' : 'Please enter a valid email address'; if (deliveryDateError) deliveryDateError.textContent = lang === 'de' ? 'Bitte wählen Sie ein gültiges Datum' : 'Please select a valid date'; } function calculateTotal() { let total = 0; document.querySelectorAll('.item-subtotal').forEach(subtotal => { total += parseFloat(subtotal.textContent) || 0; }); const totalPriceElement = document.getElementById('totalPrice'); if (totalPriceElement) totalPriceElement.textContent = total.toFixed(2); return total; } let isLoadingItems = false; async function loadItems() { if (isLoadingItems) return; isLoadingItems = true; try { const response = await fetch('/api/items'); if (!response.ok) throw new Error('Failed to load items'); const items = await response.json(); const itemsBody = document.getElementById('items'); const productsContainer = document.getElementById('products-list'); const lang = localStorage.getItem('language') || 'de'; if (itemsBody) { itemsBody.innerHTML = ''; document.querySelectorAll('.qty-input').forEach(input => input.value = '0'); document.querySelectorAll('.item-subtotal').forEach(subtotal => subtotal.textContent = '0'); if (items.length === 0) { itemsBody.innerHTML = '
${item.weight}g | ${item.price}€
`; card.addEventListener('click', () => { document.getElementById('productDetailModalLabel').textContent = itemName; document.getElementById('productDetailImage').src = imageSrc; document.getElementById('productDetailDescription').textContent = description || 'No description available'; const modal = new bootstrap.Modal(document.getElementById('productDetailModal')); modal.show(); }); productsContainer.appendChild(card); }); } } catch (error) { console.error('Error loading items:', error); const itemsBody = document.getElementById('items'); if (itemsBody) itemsBody.innerHTML = 'No orders available
'; console.log('No orders to display'); return; } orders.forEach(order => { const lines = order.order_text.split('\n'); let itemsHtml = ''; lines.forEach(line => { const match = line.match(/(.+): (\d+) (?:Stk\.|pcs\.) x ([\d.]+)€ = ([\d.]+)€/); if (match) { const [_, itemName, qty, price, subtotal] = match; itemsHtml += `${translations[lang].customer}: ${order.customer_name}
${translations[lang].phone}: ${order.customer_phone}
${translations[lang].total}: ${order.total_price}€
${translations[lang].date}: ${new Date(order.created_at).toLocaleString(lang === 'de' ? 'de-AT' : 'en-GB')}
${itemsHtml ? 'Items:
No items in this order
'} `; ordersContainer.appendChild(card); }); console.log('Rendered', orders.length, 'orders'); } catch (error) { console.error('Error loading orders:', error); const ordersContainer = document.getElementById('orders'); if (ordersContainer) { ordersContainer.innerHTML = 'Error loading orders: ' + error.message + '
'; } } } document.addEventListener('DOMContentLoaded', () => { const lang = localStorage.getItem('language') || 'de'; updateLanguage(lang); if (document.getElementById('items') || document.getElementById('products-list')) loadItems(); if (document.getElementById('orders')) loadOrders(); document.querySelectorAll('.language-dropdown a').forEach(link => { link.addEventListener('click', (e) => { e.preventDefault(); const lang = e.target.getAttribute('data-lang'); updateLanguage(lang); if (document.getElementById('items') || document.getElementById('products-list')) loadItems(); if (document.getElementById('orders')) loadOrders(); }); }); // Добавляем обработчик для кнопки "Close" в orderConfirmationModal const closeConfirmationBtn = document.getElementById('closeConfirmationBtn'); if (closeConfirmationBtn) { closeConfirmationBtn.addEventListener('click', () => { // Закрываем orderConfirmationModal const confirmationModal = bootstrap.Modal.getInstance(document.getElementById('orderConfirmationModal')); if (confirmationModal) { confirmationModal.hide(); } // Закрываем orderModal const orderModal = bootstrap.Modal.getInstance(document.getElementById('orderModal')); if (orderModal) { orderModal.hide(); } }); } });