`;
}).join('');
}
window.goToTab = function(index) {
if (index > currentTabIndex && !validateCurrentTab()) return;
saveCurrentTabData();
currentTabIndex = index;
if (tabs[currentTabIndex] === 'exercises') updateRecommendedExercises();
if (tabs[currentTabIndex] === 'plan') renderPlanSummary();
updateUI();
};
function validateCurrentTab() {
if (currentTabIndex === 0) {
const checked = document.querySelector('input[name="concern"]:checked');
if (!checked) {
alert("Please select at least one posture concern to proceed.");
return false;
}
}
return true;
}
function saveCurrentTabData() {
if (tabs[currentTabIndex] === 'assessment') {
userSelections.concerns.clear();
document.querySelectorAll('input[name="concern"]:checked').forEach(input => {
userSelections.concerns.add(input.value);
});
}
}
function updateUI() {
Object.keys(tabButtons).forEach((key, index) => {
tabButtons[key].classList.toggle('active', index === currentTabIndex);
tabContents[key].classList.toggle('active', index === currentTabIndex);
});
prevBtn.classList.toggle('invisible', currentTabIndex === 0);
nextBtn.classList.toggle('invisible', currentTabIndex === tabs.length - 1);
}
function handleNav(direction) {
const newIndex = currentTabIndex + (direction === 'next' ? 1 : -1);
if (newIndex >= 0 && newIndex < tabs.length) {
window.goToTab(newIndex);
}
}
function generatePdf() {
prepareReportData();
const reportContainer = document.getElementById('pdf-report-container');
reportContainer.style.display = 'block';
html2canvas(reportContainer, { scale: 2, useCORS: true }).then(canvas => {
const { jsPDF } = window.jspdf;
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'portrait', unit: 'px', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const ratio = canvas.width / canvas.height;
const imgHeight = pdfWidth / ratio;
pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, imgHeight);
pdf.save('Personalized-Posture-Plan.pdf');
reportContainer.style.display = 'none';
});
}
function prepareReportData() {
document.getElementById('report-date').textContent = new Date().toLocaleDateString('en-US');
const reportBody = document.getElementById('pdf-report-body');
let concernsHtml = ``;
let exercisesHtml = `
`;
});
exercisesHtml += ``;
reportBody.innerHTML = concernsHtml + exercisesHtml;
}
// --- Event Listeners ---
nextBtn.addEventListener('click', () => handleNav('next'));
prevBtn.addEventListener('click', () => handleNav('prev'));
document.getElementById('download-pdf-btn').addEventListener('click', generatePdf);
// --- Initial Setup ---
renderAssessmentOptions();
updateUI();
});
Identified Concerns
`;
userSelections.concerns.forEach(key => {
concernsHtml += ``;
});
concernsHtml += `
${postureData[key].label}
${postureData[key].description}
Your Exercise Plan
`; userSelections.exercises.forEach(exId => { const ex = exerciseData[exId]; exercisesHtml += `${ex.name}
${ex.desc}
Recommendation: ${ex.sets}
