🍅 Session Structure (Pomodoro Technique)
Structure each study session for optimal focus and retention:
- Focus: ${data.pomodoro.study} minutes of uninterrupted study.
- Short Break: ${data.pomodoro.short_break} minutes to relax.
- Repeat this cycle ${data.pomodoro.sessions} times.
- Long Break: After ${data.pomodoro.sessions} cycles, take a longer ${data.pomodoro.long_break}-minute break.
💡 Recommended Activities (${data.learningStyle.split(' ')[0]})
Incorporate these activities tailored to your learning style:
${data.activities.map(activity => `- ${activity}
`).join('')}
🧠 Review & Retention (Spaced Repetition)
To move information to long-term memory, review new topics systematically. A good starting schedule is: ${data.repetitionSchedule}, and then weekly.
`;
planPlaceholderEl.classList.add('hidden');
planContentEl.classList.remove('hidden');
}
// --- CONFIGURATION TAB ---
function populateConfig() {
const container = document.getElementById('config-inputs');
container.innerHTML = `
Pomodoro Timer Settings (minutes)
Spaced Repetition Intervals (days)
`;
container.addEventListener('change', handleConfigChange);
}
function handleConfigChange(e) {
if (e.target.dataset.configKey) {
const keys = e.target.dataset.configKey.split('.');
let temp = state.config;
keys.forEach((key, index) => {
if (index === keys.length - 1) {
temp[key] = Array.isArray(temp) ? parseInt(e.target.value) : parseFloat(e.target.value);
} else {
temp = temp[key];
}
});
}
}
// --- PDF GENERATION ---
window.downloadPDF = async () => {
const { jsPDF } = window.jspdf;
if (!state.planData) {
alert("Please generate a plan first.");
return;
}
const data = state.planData;
const reportContainer = document.createElement('div');
reportContainer.id = 'pdf-report';
reportContainer.className = 'w-[800px] bg-white p-10 text-gray-800';
reportContainer.style.position = 'absolute';
reportContainer.style.left = '-9999px';
reportContainer.style.fontFamily = 'Inter, sans-serif';
reportContainer.innerHTML = `
Optimized Study Plan
For: ${data.subject}
Learning Profile & Goals
Primary Goal: ${data.goal}
Goal Deadline: ${data.deadline}
Time Commitment: ${data.hoursPerWeek} hrs/week
Total Duration: ${data.weeks} weeks
Learning Style: ${data.learningStyle.split(' ')[0]}
Peak Focus: ${data.productiveTime}
Actionable Study Protocol
🗓️Weekly Cadence
Commit to ${data.sessionsPerWeek} focused study sessions each week to stay on track.
🍅Session Structure
Use the ${data.pomodoro.study}/${data.pomodoro.short_break} Pomodoro method, taking a ${data.pomodoro.long_break} min break every ${data.pomodoro.sessions} sessions.
💡Learning Activities
Focus on these methods: ${data.activities.join(' ')}
🧠Retention Schedule
Review new material after ${state.config.repetition_intervals.join(', ')} days to build long-term memory.
This plan is a guideline. Adjust based on your progress and energy levels. Consistency is key.
`;
document.body.appendChild(reportContainer);
try {
const canvas = await html2canvas(reportContainer, { scale: 2, useCORS: true, logging: false });
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'portrait', unit: 'mm', format: 'a4' });
const pageHeight = pdf.internal.pageSize.getHeight();
const pageWidth = pdf.internal.pageSize.getWidth();
const margin = 15;
const contentWidth = pageWidth - (margin * 2);
const imgProps = pdf.getImageProperties(imgData);
const contentHeight = (imgProps.height * contentWidth) / imgProps.width;
let heightLeft = contentHeight;
let position = 0;
pdf.addImage(imgData, 'PNG', margin, margin, contentWidth, contentHeight);
heightLeft -= (pageHeight - (margin * 2));
while (heightLeft > 0) {
position -= (pageHeight - (margin * 2));
pdf.addPage();
pdf.addImage(imgData, 'PNG', margin, position + margin, contentWidth, contentHeight);
heightLeft -= (pageHeight - (margin * 2));
}
pdf.save('Personalized-Study-Plan.pdf');
} catch (error) {
console.error("Error generating PDF:", error);
alert("Sorry, there was an error creating the PDF report.");
} finally {
document.body.removeChild(reportContainer);
}
};
// --- INITIALIZATION ---
// Set a default date for the deadline input
const today = new Date();
const futureDate = new Date(today.setDate(today.getDate() + 30));
document.getElementById('deadline').value = futureDate.toISOString().split('T')[0];
switchTab(1);
populateConfig();
});