Prenatal Workout Plan Generator
Your Workout Plan (Editable)
Go to the "Plan Configuration" tab to set your preferences and generate a plan.
Plan Options
No suitable exercises found for your selection. Try broadening your criteria.
"; } else { // Add headers and exercises addSectionHeader("Warm-up"); finalPlan.filter(ex => ex.type === 'warmup').forEach(createDashboardItem); addSectionHeader("Workout"); finalPlan.filter(ex => ex.type === 'workout').forEach(createDashboardItem); addSectionHeader("Cool-down"); finalPlan.filter(ex => ex.type === 'cooldown').forEach(createDashboardItem); } showTab("pwp-tab-dashboard"); } /** * Adds a section header (Warmup, Workout, Cooldown) to the dashboard list */ function addSectionHeader(title) { const header = document.createElement('h3'); header.textContent = title; dashboardList.appendChild(header); // Add table headers only once per section for desktop view if (window.innerWidth > 768) { // Only show headers on wider screens const headerRow = document.createElement('div'); headerRow.className = 'pwp-dash-header'; headerRow.innerHTML = `Exercise
Sets/Reps/Duration
Notes/Modifications
`;
dashboardList.appendChild(headerRow);
}
}
/**
* Creates an editable item row on the dashboard
*/
function createDashboardItem(exercise) {
const itemEl = document.createElement("div");
itemEl.className = "pwp-dash-item";
// Store original type for PDF grouping
itemEl.dataset.type = exercise.type;
itemEl.innerHTML = `
`;
dashboardList.appendChild(itemEl);
}
/**
* Handles removing an exercise from the dashboard
*/
function handleDashboardClick(e) {
if (e.target.dataset.action === "remove") {
e.target.closest(".pwp-dash-item").remove();
}
}
/**
* Generates a PDF report from the dashboard data
*/
function downloadPDF() {
if (typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF.autoTable === 'undefined') {
alert("Error: PDF library could not be loaded. Please try again.");
return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF("p", "pt", "a4");
const margin = 40;
let yPos = margin;
const tableHead = [["Exercise", "Sets/Reps/Duration", "Notes/Modifications"]];
const tableBodyWarmup = [];
const tableBodyWorkout = [];
const tableBodyCooldown = [];
// Get data *from the dashboard* and group by type
const dashItems = dashboardList.querySelectorAll(".pwp-dash-item");
dashItems.forEach((item) => {
const name = item.querySelector(".pwp-dash-name").value;
const reps = item.querySelector(".pwp-dash-reps").value;
const notes = item.querySelector(".pwp-dash-notes").value;
const type = item.dataset.type; // Get type from data attribute
const rowData = [name, reps, notes];
if (type === 'warmup') tableBodyWarmup.push(rowData);
else if (type === 'workout') tableBodyWorkout.push(rowData);
else if (type === 'cooldown') tableBodyCooldown.push(rowData);
});
doc.setFontSize(18);
doc.text("Prenatal Workout Plan", margin, yPos);
yPos += 30; // Move down after title
const tableOptions = {
startY: yPos,
head: tableHead,
theme: 'striped',
headStyles: {
fillColor: [0, 115, 230], // Blue
textColor: [255, 255, 255],
},
columnStyles: {
0: { cellWidth: 150 },
1: { cellWidth: 100 },
2: { cellWidth: 'auto' },
},
margin: { left: margin, right: margin }
};
// Function to add section title and table
function addSection(title, bodyData) {
if (bodyData.length > 0) {
doc.setFontSize(14);
doc.setFont(undefined, 'bold');
doc.text(title, margin, yPos);
yPos += 20; // Space before table
tableOptions.startY = yPos;
tableOptions.body = bodyData;
doc.autoTable(tableOptions);
yPos = doc.autoTable.previous.finalY + 25; // Update yPos after table + space
}
}
// Add sections if they have content
addSection("Warm-up", tableBodyWarmup);
addSection("Workout", tableBodyWorkout);
addSection("Cool-down", tableBodyCooldown);
doc.save("Prenatal_Workout_Plan.pdf");
}
/**
* Helper to escape HTML
*/
function escapeHTML(str) {
if (!str) return "";
return str
.replace(/&/g, "&")
.replace(//g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
// --- 4. INITIALIZATION & EVENT LISTENERS ---
// Tab Listeners
tabButtons.forEach((btn) => {
btn.addEventListener("click", () => showTab(btn.dataset.target));
});
navButtons.forEach((btn) => {
btn.addEventListener("click", () => showTab(btn.dataset.target));
});
// Config Tab Listeners
if (generateBtn) {
generateBtn.addEventListener("click", handleGenerate);
}
// Dashboard Tab Listeners
if (pdfBtn) {
pdfBtn.addEventListener("click", downloadPDF);
}
if (dashboardList) {
dashboardList.addEventListener("click", handleDashboardClick);
}
// Initial State
showTab("pwp-tab-dashboard"); // Start on dashboard
});
