`;
marker.bindPopup(popupContent);
rentalMarkers.push(marker);
});
}
map.on('popupopen', (e) => {
const favBtn = e.popup._container.querySelector('.favorite-btn');
favBtn.addEventListener('click', () => {
const rentalId = parseInt(favBtn.dataset.id);
if (favoriteRentals.has(rentalId)) {
favoriteRentals.delete(rentalId);
favBtn.textContent = 'Add to Favorites';
favBtn.classList.remove('bg-red-500', 'text-white');
favBtn.classList.add('bg-gray-200', 'text-gray-700');
} else {
favoriteRentals.add(rentalId);
favBtn.textContent = 'Remove Favorite';
favBtn.classList.remove('bg-gray-200', 'text-gray-700');
favBtn.classList.add('bg-red-500', 'text-white');
}
});
});
function generatePdf() {
if (favoriteRentals.size === 0) {
alert("Please add some rentals to your favorites before downloading.");
return;
}
const { jsPDF } = jspdf;
const pdf = new jsPDF();
pdf.setFontSize(22);
pdf.text(`Your Pet-Friendly Favorites`, 105, 20, { align: 'center' });
let y = 35;
Array.from(favoriteRentals).forEach((rentalId, index) => {
const rental = mockRentals.find(r => r.id === rentalId);
if (y > 260) { pdf.addPage(); y = 20; }
pdf.setFontSize(16);
pdf.setTextColor(88, 28, 135);
pdf.text(`${index + 1}. ${rental.name}`, 15, y);
y += 7;
pdf.setFontSize(11);
pdf.setTextColor(50, 50, 50);
pdf.text(`- Type: ${rental.type} | Price: $${rental.price}/night`, 20, y);
y += 6;
pdf.text(`- Pet Policy: ${rental.policy}`, 20, y);
y += 10;
});
pdf.save('pet-friendly-favorites.pdf');
}
document.getElementById('search-btn').addEventListener('click', displayRentals);
document.querySelectorAll('.filter-cb, #property-type-filter').forEach(el => el.addEventListener('change', displayRentals));
document.getElementById('pdf-download-btn').addEventListener('click', generatePdf);
// Initial load
displayRentals();
});
