// API Service Layer class ApiService { static async get(endpoint) { try { const response = await fetch(`/api/${endpoint}`); if (!response.ok) throw new Error('Network response was not ok'); return await response.json(); } catch (error) { console.error(`Error fetching ${endpoint}:`, error); throw error; } } static async post(endpoint, data) { try { const response = await fetch(`/api/${endpoint}`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(data) }); if (!response.ok) throw new Error('Network response was not ok'); return await response.json(); } catch (error) { console.error(`Error posting to ${endpoint}:`, error); throw error; } } } // App State Management class AppState { constructor() { this.user = JSON.parse(localStorage.getItem('user')) || null; this.cart = JSON.parse(localStorage.getItem('cart')) || { food: [], rides: [], stays: [] }; } async login(credentials) { try { const user = await ApiService.post('auth/login', credentials); this.user = user; localStorage.setItem('user', JSON.stringify(user)); this.updateAuthState(); return user; } catch (error) { throw error; } } logout() { this.user = null; localStorage.removeItem('user'); this.updateAuthState(); } addToCart(type, item) { this.cart[type].push(item); localStorage.setItem('cart', JSON.stringify(this.cart)); this.updateCartBadge(); } updateCartBadge() { const total = Object.values(this.cart).reduce((sum, arr) => sum + arr.length, 0); document.querySelectorAll('cart-badge').forEach(badge => { badge.setAttribute('count', total); }); } updateAuthState() { document.querySelectorAll('auth-state').forEach(el => { if (this.user) { el.setAttribute('logged-in', 'true'); } else { el.removeAttribute('logged-in'); } }); } } const appState = new AppState(); // Initialize app document.addEventListener('DOMContentLoaded', () => { appState.updateAuthState(); appState.updateCartBadge(); }); // Shared JavaScript functionality document.addEventListener('DOMContentLoaded', function() { // Initialize tooltips const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')); tooltipTriggerList.map(function(tooltipTriggerEl) { return new bootstrap.Tooltip(tooltipTriggerEl); }); // Handle property favorite toggle document.querySelectorAll('.favorite-btn').forEach(btn => { btn.addEventListener('click', function(e) { e.preventDefault(); const icon = this.querySelector('i'); if (icon.getAttribute('data-feather') === 'heart') { icon.setAttribute('data-feather', 'heart'); icon.classList.add('fill-rose-500'); feather.replace(); } else { icon.setAttribute('data-feather', 'heart'); icon.classList.remove('fill-rose-500'); feather.replace(); } }); }); // Smooth scrolling for anchor links document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function(e) { e.preventDefault(); document.querySelector(this.getAttribute('href')).scrollIntoView({ behavior: 'smooth' }); }); }); }); // Function to sync property locations with HF map function syncWithHFMap(properties) { // This would need to be implemented based on HF Space API // For now we'll just log the properties to console console.log('Syncing properties with HF Map:', properties); // Example of how you might send data to HF Space iframe const hfIframe = document.querySelector('hf-map').shadowRoot.querySelector('iframe'); if (hfIframe && hfIframe.contentWindow) { hfIframe.contentWindow.postMessage({ type: 'UPDATE_PROPERTIES', data: properties }, 'https://ko0ol-test1ce.hf.space'); } } // Function to handle property search with map filtering function searchProperties() { const searchTerm = document.getElementById('property-search').value.toLowerCase(); const propertyCards = document.querySelectorAll('.property-card'); const markers = []; // This would need to reference your actual markers array propertyCards.forEach(card => { const title = card.querySelector('.property-title').textContent.toLowerCase(); const location = card.querySelector('.property-location').textContent.toLowerCase(); if (title.includes(searchTerm) || location.includes(searchTerm)) { card.style.display = 'block'; // Show corresponding marker on map const cardId = card.getAttribute('data-id'); const marker = markers.find(m => m.id === cardId); if (marker) marker.setVisible(true); } else { card.style.display = 'none'; // Hide corresponding marker on map const cardId = card.getAttribute('data-id'); const marker = markers.find(m => m.id === cardId); if (marker) marker.setVisible(false); } }); } // Property data const properties = [ { id: 1, title: "Mountain Retreat", location: "Kazbegi, Georgia", description: "Luxurious villa with stunning mountain views", price: 120, rating: 4.9, type: "Entire villa", guests: 6, area: "120 m²", images: [ "http://static.photos/nature/1200x630/10", "http://static.photos/nature/640x360/20", "http://static.photos/nature/640x360/21", "http://static.photos/nature/640x360/22" ], amenities: ["Kitchen", "WiFi", "Pool", "Parking", "TV", "Air Conditioning"], host: { name: "Giorgi", avatar: "http://static.photos/people/100x100/1", joined: "2018", reviews: 12 } }, { id: 2, title: "Vineyard Estate", location: "Kakheti, Georgia", description: "Beautiful wine estate in Georgia's famous wine region", price: 150, rating: 4.8, type: "Wine estate", guests: 8, area: "200 m²", images: [ "http://static.photos/nature/1200x630/11", "http://static.photos/nature/640x360/24", "http://static.photos/nature/640x360/25", "http://static.photos/nature/640x360/26" ], amenities: ["Kitchen", "WiFi", "Pool", "Parking", "TV", "Wine tasting"], host: { name: "Nino", avatar: "http://static.photos/people/100x100/4", joined: "2019", reviews: 8 } }, // Add more properties as needed ]; // Load property details function loadPropertyDetails(id) { const property = properties.find(p => p.id === parseInt(id)); if (property) { document.getElementById('property-title').textContent = property.title; document.getElementById('property-location').textContent = property.location; document.getElementById('property-rating').textContent = property.rating; document.getElementById('property-price').textContent = property.price; document.getElementById('property-type').textContent = property.type; document.getElementById('property-guests').textContent = property.guests; document.getElementById('property-area').textContent = property.area; document.getElementById('property-description').textContent = property.description; document.getElementById('booking-price').textContent = property.price; // Update gallery images const gallery = document.querySelector('property-gallery'); gallery.innerHTML = ''; property.images.forEach(img => { const slide = document.createElement('img'); slide.setAttribute('slot', 'slide'); slide.src = img; slide.className = 'gallery-slide'; gallery.appendChild(slide); }); } } // Initialize when details page loads if (window.location.pathname.includes('details.html')) { const urlParams = new URLSearchParams(window.location.search); const propertyId = urlParams.get('id'); loadPropertyDetails(propertyId); } // Property details data const propertiesData = [ { id: 1, title: "Mountain Retreat", location: "Kazbegi, Georgia", rating: 4.9, price: "$120", type: "Entire Villa", guests: "6 guests", area: "120 m²", description: "Experience breathtaking views of the Caucasus Mountains from this luxurious retreat. Perfect for families or groups looking to explore Georgia's stunning nature while enjoying modern comforts.", mainImage: "http://static.photos/nature/1200x630/10", images: [ "http://static.photos/nature/640x360/20", "http://static.photos/nature/640x360/21", "http://static.photos/nature/640x360/22", "http://static.photos/nature/640x360/23" ], similar: [2, 3, 5] }, { id: 2, title: "Vineyard Estate", location: "Kakheti, Georgia", rating: 4.8, price: "$150", type: "Wine Estate", guests: "8 guests", area: "200 m²", description: "Immerse yourself in Georgia's famous wine culture at this beautiful vineyard estate. Includes wine tasting tours and stunning views of the Alazani Valley.", mainImage: "http://static.photos/nature/1200x630/11", images: [ "http://static.photos/nature/640x360/24", "http://static.photos/nature/640x360/25", "http://static.photos/nature/640x360/26", "http://static.photos/nature/640x360/27" ], similar: [1, 4, 5] }, { id: 3, title: "Black Sea Villa", location: "Batumi, Georgia", rating: 4.7, price: "$110", type: "Beach Villa", guests: "4 guests", area: "90 m²", description: "Modern beachfront villa with private access to the Black Sea. Perfect for those who want to combine city life with beach relaxation.", mainImage: "http://static.photos/nature/1200x630/12", images: [ "http://static.photos/nature/640x360/28", "http://static.photos/nature/640x360/29", "http://static.photos/nature/640x360/30", "http://static.photos/nature/640x360/31" ], similar: [1, 2, 4] } ]; // Redirect to property details page function showPropertyDetails(id) { window.location.href = `details.html?id=${id}`; } function closePropertyModal() { document.getElementById('propertyModal').classList.add('hidden'); } function changeMainImage(src) { document.getElementById('modalMainImage').src = src; } // Initialize maps with clustering function initMapClustering() { // This would be implemented with marker clustering library // Example using MarkerClusterer (would need to include the library) // const markerCluster = new MarkerClusterer(globalMap, markers, { // imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m', // gridSize: 60, // maxZoom: 15 // }); } const searchTerm = document.getElementById('property-search').value.toLowerCase(); const propertyCards = document.querySelectorAll('.property-card'); propertyCards.forEach(card => { const title = card.querySelector('.property-title').textContent.toLowerCase(); const location = card.querySelector('.property-location').textContent.toLowerCase(); if (title.includes(searchTerm) || location.includes(searchTerm)) { card.style.display = 'block'; } else { card.style.display = 'none'; } }); }