`;
});
stretchesContainer.innerHTML = html;
}
function downloadPdf() {
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
// Header
doc.setFontSize(22);
doc.setFont('helvetica', 'bold');
doc.text('Your Ergonomics Guide', 105, 20, { align: 'center' });
doc.setFontSize(11);
doc.text(`Generated on: ${new Date().toLocaleDateString()}`, 105, 28, { align: 'center' });
// Checklist Section
doc.setFontSize(16);
doc.setFont('helvetica', 'bold');
doc.text('Ergonomics Checklist Summary', 14, 45);
let checklistTableBody = [];
for (const category in checklistData) {
checklistTableBody.push([{ content: category, colSpan: 2, styles: { fontStyle: 'bold', fillColor: '#eef2ff' } }]);
checklistData[category].forEach(item => {
const isChecked = document.getElementById(item.id).checked;
checklistTableBody.push([isChecked ? '✅ Done' : '❌ To Do', item.text]);
});
}
doc.autoTable({
startY: 50,
head: [['Status', 'Checklist Item']],
body: checklistTableBody,
theme: 'grid',
headStyles: { fillColor: [79, 70, 229] },
columnStyles: { 0: { cellWidth: 25 } }
});
// Stretches Section
let finalY = doc.autoTable.previous.finalY;
if (finalY > 200) { doc.addPage(); finalY = 0; }
doc.setFontSize(16);
doc.setFont('helvetica', 'bold');
doc.text('Recommended Stretches', 14, finalY + 15);
const stretchesTableBody = stretchesData.map(s => [s.name, s.desc]);
doc.autoTable({
startY: finalY + 20,
head: [['Stretch', 'How-To']],
body: stretchesTableBody,
theme: 'striped',
headStyles: { fillColor: [22, 163, 74] } // Green
});
doc.save('WFH-Ergonomics-Guide.pdf');
}
// --- EVENT LISTENERS ---
Object.keys(tabButtons).forEach(key => {
tabButtons[key].addEventListener('click', () => switchTab(key));
});
document.getElementById('hotspot-monitor').addEventListener('click', () => displayInteractiveTip('monitor'));
document.getElementById('hotspot-eyes').addEventListener('click', () => displayInteractiveTip('eyes'));
document.getElementById('hotspot-chair').addEventListener('click', () => displayInteractiveTip('chair'));
document.getElementById('hotspot-desk').addEventListener('click', () => displayInteractiveTip('desk'));
document.getElementById('hotspot-feet').addEventListener('click', () => displayInteractiveTip('feet'));
downloadBtn.addEventListener('click', downloadPdf);
// --- INITIALIZATION ---
populateChecklist();
populateStretches();
});
