${sign}${mover.change.toFixed(1)}%
`;
}).join('');
};
async function downloadPDF() {
const contentToPrint = document.getElementById('pdf-content');
if (!contentToPrint) return;
if (typeof window.jspdf === 'undefined' || typeof window.html2canvas === 'undefined') {
console.error("PDF generation library is not available."); return;
}
try {
const { jsPDF } = window.jspdf;
const pdfCanvas = await html2canvas(contentToPrint, { scale: 2 });
const imgData = pdfCanvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = (pdfCanvas.height * pdfWidth) / pdfCanvas.width;
pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight);
pdf.save('investor-sentiment-dashboard.pdf');
} catch(err) {
console.error("PDF generation failed:", err);
}
}
// Set current time based on user prompt
const now = new Date('2025-09-11T12:18:00+06:00');
elements.currentTime.textContent = `Live as of ${now.toLocaleString('en-US', { dateStyle: 'full', timeStyle: 'short' })}`;
elements.pdfBtn.addEventListener('click', downloadPDF);
// Initial Render
renderDashboard(generateMockData());
});