`;
wotmpPlannerData.schedule.forEach(slot => {
const slotDiv = document.createElement('div');
slotDiv.className = `wotmp-timeslot type-${slot.type}`;
slotDiv.innerHTML = `
${wotmpMinutesToTimeStr(slot.startMinutes)} - ${wotmpMinutesToTimeStr(slot.endMinutes)}
${slot.activityName}
`;
planDisplay.appendChild(slotDiv);
});
const unscheduledDiv = document.getElementById('wotmp-unscheduled-items-display');
const unscheduledListEl = document.getElementById('wotmp-unscheduled-list');
unscheduledListEl.innerHTML = '';
if (wotmpPlannerData.unscheduledItems.length > 0) {
wotmpPlannerData.unscheduledItems.forEach(item => unscheduledListEl.innerHTML += `
${item}`);
unscheduledDiv.style.display = 'block';
} else {
unscheduledDiv.style.display = 'none';
}
document.getElementById('wotmp-reflection-prompts').style.display = 'block';
const pdfBtn = document.getElementById('wotmp-pdf-download');
if(pdfBtn) pdfBtn.style.display = 'inline-block';
}
function wotmpGetFormattedDateForPDF_context() {
return new Date(2025, 4, 18).toLocaleDateString(undefined, { year: 'numeric', month: 'long', day: 'numeric' });
}
function wotmpDownloadPDF() {
if (!jsPDF_constructor_wotmp) { alert("PDF library error."); return; }
if (wotmpPlannerData.schedule.length === 0 && wotmpPlannerData.unscheduledItems.length === 0) {
alert("Please generate a plan first."); return;
}
wotmpPlannerData.reflection = { // Capture reflection values
wellbeingRating: wotmpGetInputValue('wotmp-reflect-wellbeing', 'select-number', 0),
workedWell: wotmpGetInputValue('wotmp-reflect-worked-well'),
improvementTomorrow: wotmpGetInputValue('wotmp-reflect-improvement')
};
const doc = new jsPDF_constructor_wotmp('p', 'pt', 'a4');
const FONT_FAMILY = "helvetica";
const ACCENT_COLOR_HEX = getComputedStyle(document.documentElement).getPropertyValue('--accent-color').trim();
const PRIMARY_TEXT_COLOR_HEX = getComputedStyle(document.documentElement).getPropertyValue('--primary-text').trim();
const SECTION_TITLE_COLOR_HEX = getComputedStyle(document.documentElement).getPropertyValue('--section-title-color').trim();
const BUTTON_TEXT_COLOR_HEX = getComputedStyle(document.documentElement).getPropertyValue('--button-text-color').trim();
let yPos = 40;
const pageWidth = doc.internal.pageSize.getWidth();
const margin = 40;
const usableWidth = pageWidth - (2 * margin);
doc.setFillColor(ACCENT_COLOR_HEX);
doc.rect(0, 0, pageWidth, yPos + 10, 'F');
doc.setFont(FONT_FAMILY, "bold"); doc.setFontSize(16); doc.setTextColor(BUTTON_TEXT_COLOR_HEX);
doc.text("My Wellness-Oriented Daily Plan", pageWidth / 2, yPos, { align: "center" });
yPos += 25;
doc.setFont(FONT_FAMILY, "normal"); doc.setFontSize(10); doc.setTextColor(PRIMARY_TEXT_COLOR_HEX);
doc.text(`Plan for Date: ${new Date(wotmpPlannerData.planDate+'T00:00:00').toLocaleDateString(undefined, { weekday:'long', year: 'numeric', month: 'long', day: 'numeric' })}`, margin, yPos);
doc.text(`Generated on: ${wotmpGetFormattedDateForPDF_context()}`, pageWidth - margin, yPos, { align: 'right'});
yPos += 15;
doc.setFont(FONT_FAMILY, "italic"); doc.setFontSize(9);
doc.text(`Intention: ${wotmpPlannerData.dayIntention || "Not specified."}`, margin, yPos); yPos += 15;
doc.setFont(FONT_FAMILY, "bold"); doc.setFontSize(10); doc.setTextColor(SECTION_TITLE_COLOR_HEX);
doc.text("Key Wellness Goals:", margin, yPos); yPos += 12;
doc.setFont(FONT_FAMILY, "normal"); doc.setFontSize(9);
if(wotmpPlannerData.wellnessGoalsSelected.length > 0) {
wotmpPlannerData.wellnessGoalsSelected.forEach(goal => {
if (yPos > doc.internal.pageSize.getHeight() - 25) { doc.addPage(); yPos = margin; }
let goalText = goal;
if (goal === "Other Custom Wellness Goal" && wotmpPlannerData.wellnessGoalOtherText) {
goalText = `Other: ${wotmpPlannerData.wellnessGoalOtherText}`;
}
doc.text(`• ${goalText}`, margin + 10, yPos); yPos += 11;
});
} else { doc.text("None specified.", margin + 10, yPos); yPos += 11; }
yPos += 8;
doc.setFont(FONT_FAMILY, "bold"); doc.setFontSize(10); doc.setTextColor(SECTION_TITLE_COLOR_HEX);
doc.text("Anticipated Energy Levels:", margin, yPos); yPos += 12;
doc.setFont(FONT_FAMILY, "normal"); doc.setFontSize(9);
doc.text(` Morning: ${wotmpPlannerData.energyLevels.morning}, Afternoon: ${wotmpPlannerData.energyLevels.afternoon}, Evening: ${wotmpPlannerData.energyLevels.evening}`, margin + 5, yPos); yPos+=15;
doc.setFont(FONT_FAMILY, "bold"); doc.setFontSize(12); doc.setTextColor(SECTION_TITLE_COLOR_HEX);
doc.text("Daily Schedule:", margin, yPos); yPos += 5;
if (jsPDF_autoTable_plugin_wotmp && wotmpPlannerData.schedule.length > 0) {
const scheduleTableBody = wotmpPlannerData.schedule.map(slot => [
`${wotmpMinutesToTimeStr(slot.startMinutes)} - ${wotmpMinutesToTimeStr(slot.endMinutes)}`,
slot.activityName,
slot.type
]);
doc.autoTable({
startY: yPos,
head: [['Time Slot', 'Activity / Task', 'Type']], body: scheduleTableBody, theme: 'grid',
margin: {left: margin, right: margin},
headStyles: { fillColor: ACCENT_COLOR_HEX, textColor: BUTTON_TEXT_COLOR_HEX, fontSize: 9, fontStyle:'bold' },
styles: { font: FONT_FAMILY, fontSize: 8, cellPadding: 3, overflow: 'linebreak' },
columnStyles: { 0: {cellWidth: 100}, 1:{cellWidth:'auto'}, 2:{cellWidth:70} },
didParseCell: function(data) { // Color Type column based on activity type
if (data.section === 'body' && data.column.index === 2) {
const type = data.cell.raw.toLowerCase();
if (type.includes('work')) data.cell.styles.fillColor = getComputedStyle(document.documentElement).getPropertyValue('--work-block-bg').trim();
else if (type.includes('wellness') || type.includes('physical') || type.includes('mindful')) data.cell.styles.fillColor = getComputedStyle(document.documentElement).getPropertyValue('--wellness-block-bg').trim();
else if (type.includes('personal') || type.includes('hobby') || type.includes('social') || type.includes('meal') || type.includes('chores')) data.cell.styles.fillColor = getComputedStyle(document.documentElement).getPropertyValue('--personal-block-bg').trim();
else if (type.includes('break')) data.cell.styles.fillColor = getComputedStyle(document.documentElement).getPropertyValue('--break-block-bg').trim();
else if (type.includes('free')) data.cell.styles.fillColor = getComputedStyle(document.documentElement).getPropertyValue('--free-block-bg').trim();
}
}
});
yPos = doc.lastAutoTable.finalY + 15;
} else if (wotmpPlannerData.schedule.length > 0) { // Fallback for no autoTable
doc.setFont(FONT_FAMILY, "normal"); doc.setFontSize(8);
wotmpPlannerData.schedule.forEach(slot => {
if (yPos > doc.internal.pageSize.getHeight() - 20) { doc.addPage(); yPos = margin; }
doc.text(`• ${wotmpMinutesToTimeStr(slot.startMinutes)}-${wotmpMinutesToTimeStr(slot.endMinutes)}: ${slot.activityName} (${slot.type})`, margin, yPos);
yPos += 10;
});
yPos += 5;
} else {
doc.setFont(FONT_FAMILY, "normal"); doc.setFontSize(9);
doc.text("No schedule generated.", margin, yPos); yPos += 15;
}
if (wotmpPlannerData.unscheduledItems.length > 0) {
if (yPos > doc.internal.pageSize.getHeight() - 40) { doc.addPage(); yPos = margin; }
doc.setFont(FONT_FAMILY, "bold"); doc.setFontSize(10); doc.setTextColor(SECTION_TITLE_COLOR_HEX);
doc.text("Unscheduled Items:", margin, yPos); yPos += 12;
doc.setFont(FONT_FAMILY, "normal"); doc.setFontSize(9);
wotmpPlannerData.unscheduledItems.forEach(item => {
if (yPos > doc.internal.pageSize.getHeight() - 25) { doc.addPage(); yPos = margin; }
doc.text(`• ${item}`, margin + 10, yPos); yPos += 11;
});
yPos += 8;
}
if (wotmpPlannerData.reflection.wellbeingRating > 0 || wotmpPlannerData.reflection.workedWell || wotmpPlannerData.reflection.improvementTomorrow) {
if (yPos > doc.internal.pageSize.getHeight() - 80) { doc.addPage(); yPos = margin; }
doc.setFont(FONT_FAMILY, "bold"); doc.setFontSize(12); doc.setTextColor(SECTION_TITLE_COLOR_HEX);
doc.text("End-of-Day Reflection:", margin, yPos); yPos += 18;
doc.setFont(FONT_FAMILY, "normal"); doc.setFontSize(9);
if(wotmpPlannerData.reflection.wellbeingRating > 0) {
doc.text(`Well-being Support Rating: ${wotmpPlannerData.reflection.wellbeingRating}/5`, margin, yPos); yPos += 12;
}
if(wotmpPlannerData.reflection.workedWell){
doc.setFont(FONT_FAMILY, "italic"); doc.text("What worked well:", margin, yPos); yPos += 11;
doc.setFont(FONT_FAMILY, "normal");
const wwLines = doc.splitTextToSize(wotmpPlannerData.reflection.workedWell, usableWidth);
doc.text(wwLines, margin + 10, yPos); yPos += wwLines.length * 11 + 5;
}
if(wotmpPlannerData.reflection.improvementTomorrow){
doc.setFont(FONT_FAMILY, "italic"); doc.text("Adjustment for tomorrow:", margin, yPos); yPos += 11;
doc.setFont(FONT_FAMILY, "normal");
const itLines = doc.splitTextToSize(wotmpPlannerData.reflection.improvementTomorrow, usableWidth);
doc.text(itLines, margin + 10, yPos); yPos += itLines.length * 11 + 5;
}
}
const pageCount = doc.internal.getNumberOfPages();
for (let i = 1; i <= pageCount; i++) {
doc.setPage(i);
const pageHeight = doc.internal.pageSize.getHeight();
doc.setLineWidth(0.5); doc.setDrawColor(ACCENT_COLOR_HEX);
doc.line(margin, pageHeight - 30, pageWidth - margin, pageHeight - 30);
doc.setFont(FONT_FAMILY, "normal"); doc.setFontSize(8); doc.setTextColor(PRIMARY_TEXT_COLOR_HEX);
doc.text(`Page ${i} of ${pageCount}`, pageWidth / 2, pageHeight - 20, { align: "center" });
}
doc.save("Wellness_Oriented_Daily_Plan.pdf");
}