No tasks scheduled for this day.
';
} else {
dayData.tasks.forEach(task => {
dayDiv.innerHTML += `
${task.startTime} - ${task.endTime}
${task.taskName}
(${task.taskType} / ${task.priority})
`;
});
}
planOutputDiv.appendChild(dayDiv);
});
if (wpo_generatedPlanForPdf.unscheduled.length > 0) {
wpo_generatedPlanForPdf.unscheduled.forEach(task => {
unscheduledListUl.innerHTML += `
${task.name} (${task.durationMinutes}m, ${task.priority}, ${task.taskType})`;
});
} else {
unscheduledListUl.innerHTML = `
All tasks were scheduled!`;
}
document.getElementById('wpo-generated-plan-area').style.display = 'block';
document.getElementById('wpo-download-pdf-button').disabled = false;
}
function wpo_clearAllData() {
if (confirm("Clear all tasks and the generated plan? Work rhythm will remain.")) {
document.getElementById('wpo-tasks-input-list').innerHTML = '';
wpo_taskInputRowCounter = 0; wpo_tasksToPlan = [];
wpo_addTaskInputRow(); // Add one default
document.getElementById('wpo-plan-output').innerHTML = '';
document.getElementById('wpo-unscheduled-tasks-list').innerHTML = '';
document.getElementById('wpo-generated-plan-area').style.display = 'none';
document.getElementById('wpo-download-pdf-button').disabled = true;
wpo_generatedPlanForPdf = null;
}
}
function wpo_downloadPDF() {
if (!tpc_jsPDF_loaded_WPO || !tpc_autoTable_loaded_WPO) { alert("WPO Error: PDF libraries not loaded."); return; }
if (!wpo_generatedPlanForPdf) { alert("Please generate a plan first."); return; }
const doc = new TPC_jsPDF_WPO();
const primaryColor = getComputedStyle(document.documentElement).getPropertyValue('--primary-color').trim();
const darkColor = getComputedStyle(document.documentElement).getPropertyValue('--dark-color').trim();
let finalY = 15;
const reportDateStr = new Date().toLocaleDateString();
doc.setFontSize(18); doc.setTextColor(primaryColor);
doc.text("Optimized Work Plan Report", doc.internal.pageSize.getWidth() / 2, finalY, { align: 'center' });
finalY += 8; doc.setFontSize(10); doc.setTextColor(darkColor);
doc.text(`Report Date: ${reportDateStr}`, doc.internal.pageSize.getWidth() / 2, finalY, { align: 'center'});
finalY += 10;
doc.setFontSize(12); doc.setTextColor(primaryColor);
doc.text("Work Rhythm Profile Used:", 14, finalY); finalY += 6;
doc.setFontSize(9); doc.setTextColor(darkColor);
let rhythmText = `Work Hours: ${wpo_workRhythm.workStartTime} - ${wpo_workRhythm.workEndTime}. `;
rhythmText += `Lunch: ${wpo_workRhythm.lunchBreakStartTime} - ${wpo_workRhythm.lunchBreakEndTime}. `;
rhythmText += `Work Days: ${wpo_workRhythm.workDays.map(d => ['Sun','Mon','Tue','Wed','Thu','Fri','Sat'][d]).join(', ')}. `;
rhythmText += `Energy - Morning: ${wpo_workRhythm.energyLevels.morning}, Afternoon: ${wpo_workRhythm.energyLevels.afternoon}, Late Afternoon: ${wpo_workRhythm.energyLevels.lateAfternoon}.`;
doc.text(rhythmText, 14, finalY, {maxWidth: doc.internal.pageSize.getWidth() - 28});
finalY += (Math.ceil(doc.getTextDimensions(rhythmText).h / (doc.internal.pageSize.getWidth() - 28)) * 4) + 8 ;
wpo_generatedPlanForPdf.days.forEach(dayData => {
if (finalY > 250) { doc.addPage(); finalY = 15; }
doc.setFontSize(12); doc.setTextColor(primaryColor);
doc.text(dayData.date.toLocaleDateString(undefined, {weekday:'long', year:'numeric', month:'long', day:'numeric'}), 14, finalY); finalY +=7;
if (dayData.tasks.length > 0) {
const tableBody = dayData.tasks.map(task => [
`${task.startTime} - ${task.endTime}`, task.taskName, task.taskType, task.priority
]);
doc.autoTable({
startY: finalY, head: [['Time', 'Task', 'Type', 'Priority']], body: tableBody,
theme: 'grid', headStyles: { fillColor: primaryColor, textColor: '#ffffff', fontSize: 9 },
styles: { fontSize: 8, cellPadding: 1.5 }
});
finalY = doc.lastAutoTable.finalY + 7;
} else {
doc.setFontSize(9); doc.setTextColor(darkColor); doc.text("No tasks scheduled for this day.", 14, finalY); finalY += 7;
}
});
if (wpo_generatedPlanForPdf.unscheduled.length > 0) {
if (finalY > 250) { doc.addPage(); finalY = 15; }
doc.setFontSize(12); doc.setTextColor(primaryColor);
doc.text("Unscheduled Tasks", 14, finalY); finalY += 7;
const unscheduledBody = wpo_generatedPlanForPdf.unscheduled.map(task => [
task.name, `${task.durationMinutes}m`, task.priority, task.taskType, task.dueDate || 'N/A'
]);
doc.autoTable({
startY: finalY, head: [['Task Name', 'Duration', 'Priority', 'Type', 'Due Date']], body: unscheduledBody,
theme: 'grid', headStyles: {fillColor:getComputedStyle(document.documentElement).getPropertyValue('--warning-color').trim(), textColor: darkColor, fontSize:9},
styles: {fontSize:8, cellPadding:1.5}
});
}
doc.save(`Work_Plan_${new Date().toISOString().slice(0,10)}.pdf`);
}