لبيّتك
توصيل الطلبات لبيتك
دخول
حساب جديد
`); win.document.close(); } catch(e) {} } function closeTracker() { document.getElementById('trackerModal').style.display = 'none'; if (trackerPoll) { clearInterval(trackerPoll); trackerPoll = null; } } // ====== SEARCH ====== function filterRestaurants(query) { const q = query.toLowerCase(); document.querySelectorAll('.restaurant-card').forEach(card => { const text = card.textContent.toLowerCase(); card.style.display = text.includes(q) ? '' : 'none'; }); } // ====== RATINGS ====== function rateOrder(orderId, restaurantId) { var stars = [1,2,3,4,5]; var starHtml = ''; for (var i = 0; i < stars.length; i++) { var n = stars[i]; starHtml += '☆'; } var html = '
' + '
' + '

⭐ قيّم الطلب #' + orderId + '

' + '
' + starHtml + '
' + '
' + '
' + '' + '
'; document.body.insertAdjacentHTML('beforeend', html); } function highlightStars(n) { document.querySelectorAll('.star-star').forEach((s, i) => { s.textContent = i < n ? '★' : '☆'; }); } function unhighlightStars() { document.querySelectorAll('.star-star').forEach(s => { s.textContent = '☆'; }); } function closeRating() { var modal = document.getElementById('ratingModal'); if (modal) modal.remove(); } async function submitRating(orderId, restaurantId, rating) { const comment = document.getElementById('ratingComment')?.value || ''; try { await API.post('/ratings', { restaurant_id: restaurantId, order_id: orderId, rating, comment }); document.getElementById('ratingModal').remove(); toast(`شكراً لتقييمك! ${'⭐'.repeat(rating)}`, 'success'); } catch(err) { toast(err.message, 'error'); } } // ====== MAP ====== let checkoutMap = null; // ====== REORDER ====== async function reorder(orderId) { try { const data = await API.getOrder(orderId); const o = data.order; cart = o.items.map(i => ({ menu_item_id: i.menu_item_id, item_name: i.item_name, quantity: i.quantity, unit_price: i.unit_price })); updateCartBar(); document.getElementById('checkoutAddress').value = o.delivery_address; document.getElementById('checkoutNotes').value = o.delivery_notes || ''; checkout(); toast('تم نسخ الطلب للسلة 🔄', 'success'); } catch(err) { toast(err.message, 'error'); } } // ====== MAP ====== function getLocation() { if (!navigator.geolocation) { toast('الموقع الجغرافي غير مدعوم في هذا المتصفح', 'error'); return; } navigator.geolocation.getCurrentPosition( (pos) => { const { latitude, longitude } = pos.coords; document.getElementById('checkoutMap').style.display = 'block'; if (!checkoutMap) { checkoutMap = L.map('checkoutMap').setView([latitude, longitude], 15); L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { maxZoom: 19, attribution: '© OpenStreetMap' }).addTo(checkoutMap); } else { checkoutMap.setView([latitude, longitude], 15); } // Clear old markers checkoutMap.eachLayer(layer => { if (layer instanceof L.Marker) checkoutMap.removeLayer(layer); }); // Add marker const marker = L.marker([latitude, longitude]).addTo(checkoutMap); marker.bindPopup('📍 موقع التوصيل').openPopup(); // Reverse geocode to get address fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${latitude}&lon=${longitude}`) .then(r => r.json()) .then(data => { document.getElementById('checkoutAddress').value = data.display_name || `${latitude.toFixed(5)}, ${longitude.toFixed(5)}`; }) .catch(() => { document.getElementById('checkoutAddress').value = `${latitude.toFixed(5)}, ${longitude.toFixed(5)}`; }); }, (err) => { toast('تعذر الوصول للموقع. الرجاء إدخال العنوان يدوياً', 'error'); }, { enableHighAccuracy: true, timeout: 10000 } ); }