Estimated Total Workout Time
${totalMinutes} min ${totalSeconds} sec
Exercise Protocol
`;
const tableToClone = document.getElementById('pdf-content-table');
if (tableToClone) {
const clonedTable = tableToClone.cloneNode(true);
clonedTable.style.width = '100%';
clonedTable.style.borderCollapse = 'collapse';
clonedTable.style.fontSize = '14px';
clonedTable.querySelectorAll('thead th').forEach(th => {
th.style.backgroundColor = '#f3f4f6'; th.style.color = '#374151';
th.style.padding = '12px 15px'; th.style.textAlign = 'left';
th.style.borderBottom = '2px solid #e5e7eb'; th.style.fontWeight = '600';
});
clonedTable.querySelectorAll('tbody tr').forEach((tr, index) => {
tr.style.borderBottom = '1px solid #e5e7eb';
tr.style.backgroundColor = index % 2 === 0 ? '#ffffff' : '#f9fafb';
tr.classList.remove('bg-blue-100', 'font-semibold');
});
clonedTable.querySelectorAll('tbody td').forEach(td => {
td.style.padding = '12px 15px'; td.style.color = '#374151';
});
pdfContent += clonedTable.outerHTML;
}
pdfContent += `
This report was automatically generated by the HIIT Planner tool.
Always consult with a healthcare professional before starting any new exercise program.
`;
pdfContainer.innerHTML = pdfContent;
document.body.appendChild(pdfContainer);
window.html2canvas(pdfContainer, { scale: 2, useCORS: true }).then(canvas => {
const imgData = canvas.toDataURL('image/png');
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const imgWidth = pdfWidth;
const imgHeight = canvas.height * imgWidth / canvas.width;
pdf.addImage(imgData, 'PNG', 0, 0, imgWidth, imgHeight);
pdf.save('HIIT-Performance-Report.pdf');
document.body.removeChild(pdfContainer);
}).catch(err => {
console.error("Error generating PDF:", err);
alert("An error occurred while generating the PDF. Please try again.");
if(document.body.contains(pdfContainer)) document.body.removeChild(pdfContainer);
});
};
// --- Event Listeners ---
startBtn.addEventListener('click', startTimer);
pauseBtn.addEventListener('click', pauseTimer);
resetBtn.addEventListener('click', resetTimer);
downloadPdfBtn.addEventListener('click', downloadPDF);
saveSettingsBtn.addEventListener('click', saveExercises);
[workDurationInput, restDurationInput, roundsInput].forEach(input => {
input.addEventListener('change', generateWorkoutPlan);
});
initialize();
});
// --- Global Tab Switching Logic ---
const switchTab = (tabId) => {
const plannerTab = document.getElementById('planner-tab');
const settingsTab = document.getElementById('settings-tab');
const plannerBtn = document.getElementById('tab-planner-btn');
const settingsBtn = document.getElementById('tab-settings-btn');
const nextBtn = document.getElementById('next-btn');
const prevBtn = document.getElementById('prev-btn');
if (!plannerTab || !settingsTab || !plannerBtn || !settingsBtn || !nextBtn || !prevBtn) return;
if (tabId === 'planner') {
plannerTab.style.display = 'block';
settingsTab.style.display = 'none';
plannerBtn.classList.add('active');
settingsBtn.classList.remove('active');
prevBtn.disabled = true;
nextBtn.disabled = false;
} else {
plannerTab.style.display = 'none';
settingsTab.style.display = 'block';
plannerBtn.classList.remove('active');
settingsBtn.classList.add('active');
prevBtn.disabled = false;
nextBtn.disabled = true;
}
};
const navigateTabs = (direction) => {
const isPlannerActive = document.getElementById('tab-planner-btn').classList.contains('active');
if (direction === 'next' && isPlannerActive) switchTab('settings');
else if (direction === 'prev' && !isPlannerActive) switchTab('planner');
};
window.onload = () => { switchTab('planner'); };