const AMENITY_KEYS = { has_ac: { icon: 'fa-snowflake', key: 'amenity.ac' }, has_tv: { icon: 'fa-tv', key: 'amenity.tv' }, has_fridge: { icon: 'fa-sink', key: 'amenity.fridge' }, has_wifi: { icon: 'fa-wifi', key: 'amenity.wifi' }, has_kettle: { icon: 'fa-mug-hot', key: 'amenity.kettle' }, has_hairdryer: { icon: 'fa-wind', key: 'amenity.hairdryer' }, has_shower: { icon: 'fa-shower', key: 'amenity.shower' }, has_sea_view: { icon: 'fa-water', key: 'amenity.sea_view' } }; function rt(key, fallback) { return (window.I18n && typeof window.I18n.t === 'function') ? window.I18n.t(key) : fallback; } let cachedRooms = []; async function loadRoomsPublic() { try { const res = await fetch('/api/rooms'); if (!res.ok) throw new Error('Failed to load rooms'); cachedRooms = await res.json(); renderRoomsPublic(cachedRooms); updateRoomPrices(cachedRooms); } catch (err) { console.error('Error loading rooms:', err); document.getElementById('roomsEmpty').style.display = 'block'; } } function renderRoomsPublic(rooms) { const grid = document.getElementById('roomsGrid'); const empty = document.getElementById('roomsEmpty'); if (!rooms || rooms.length === 0) { grid.innerHTML = ''; empty.style.display = 'block'; return; } empty.style.display = 'none'; grid.innerHTML = rooms.map((room, index) => { const amenities = Array.isArray(room.amenities) ? room.amenities : []; const floors = Array.isArray(room.floors) ? room.floors : []; const images = Array.isArray(room.images) ? room.images : []; const primaryImg = images.find(i => i.is_primary) || images[0]; let imageSrc = room.image_path || 'data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 250"%3E%3Crect fill="%23274151" width="400" height="250"/%3E%3Ctext fill="%2364748b" font-family="sans-serif" font-size="16" x="50%25" y="50%25" text-anchor="middle" dy=".3em"%3EФото%3C/text%3E%3C/svg%3E'; if (primaryImg && primaryImg.image_path) { imageSrc = primaryImg.image_path; } const fullImageSrc = imageSrc.startsWith('uploads') || imageSrc.startsWith('data') ? '/' + imageSrc : imageSrc; const allImages = images.length > 0 ? images : (room.image_path ? [{ image_path: room.image_path, is_primary: 1 }] : []); let imagesHtml = ''; if (allImages.length > 1) { const dotsHtml = allImages.map((img, i) => { const src = img.image_path.startsWith('uploads') || img.image_path.startsWith('data') ? '/' + img.image_path : img.image_path; return ``; }).join(''); imagesHtml = `
${escapeHtml(room.description || '')}