File size: 12,266 Bytes
2f312e5
bb38542
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2f312e5
 
 
 
 
 
 
 
 
 
bb38542
 
 
 
 
 
 
 
 
 
2f312e5
 
 
 
 
bb38542
2f312e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bb38542
2f312e5
bb38542
 
 
 
 
2f312e5
 
bb38542
2f312e5
bb38542
 
 
 
 
2f312e5
 
cbe4375
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e4cc90d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cbe4375
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2476f41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ccd6f09
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d9574f7
ccd6f09
d9574f7
ccd6f09
 
 
 
 
 
 
 
cbe4375
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351

// 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';
        }
    });
}