Estimated Budget
$${Math.round(data.totalCost).toLocaleString()}
Total for ${data.tripLength} days
Sample Itinerary
${itineraryHtml}
Personalized Packing List
${packingHtml}
`;
downloadBtn.classList.remove('hidden');
const ctx = document.getElementById('budgetChart')?.getContext('2d');
if (ctx) {
if (budgetChart) budgetChart.destroy();
budgetChart = new Chart(ctx, {
type: 'doughnut',
data: {
labels: Object.keys(data.budget),
datasets: [{
data: Object.values(data.budget),
backgroundColor: ['#b45309', '#16a34a', '#f59e0b', '#6b7280'],
borderColor: '#ffffff',
borderWidth: 3
}]
},
options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { position: 'bottom' } } }
});
}
}
function downloadPDF() {
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' });
const contentToPrint = document.getElementById('dashboard-content');
if (!contentToPrint) return;
html2canvas(contentToPrint, { scale: 2, useCORS: true, onclone: (doc) => {
const chartCanvas = doc.getElementById('budgetChart');
if (chartCanvas && budgetChart) {
const img = new Image();
img.src = budgetChart.toBase64Image();
img.style.maxWidth = '100%';
img.style.height = 'auto';
chartCanvas.parentNode.replaceChild(img, chartCanvas);
}
doc.querySelectorAll('input[type="checkbox"]').forEach(cb => cb.style.display = 'none');
}}).then(canvas => {
const imgData = canvas.toDataURL('image/png');
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = (canvas.height * pdfWidth) / canvas.width;
let heightLeft = pdfHeight;
let position = 0;
const pageHeight = pdf.internal.pageSize.getHeight();
pdf.addImage(imgData, 'PNG', 0, position, pdfWidth, pdfHeight);
heightLeft -= pageHeight;
while (heightLeft >= 0) {
position = heightLeft - pdfHeight;
pdf.addPage();
pdf.addImage(imgData, 'PNG', 0, position, pdfWidth, pdfHeight);
heightLeft -= pageHeight;
}
pdf.save('My-Safari-Plan.pdf');
});
}