';
}
function pwebToggleActiveGoal(goalId) {
const goal = pwebSession.goals.find(g => g.id === goalId);
if (goal) {
const checkbox = document.getElementById(`active-check-${goal.id}`);
goal.completed = checkbox.checked;
// Optionally re-render or just style the label
const label = checkbox.nextElementSibling;
if (label) label.style.textDecoration = goal.completed ? 'line-through' : 'none';
}
}
function pwebLogDistraction() {
const note = document.getElementById('pweb-distraction-note').value.trim();
pwebSession.distractions.push({ time: new Date(), note: note });
document.getElementById('pweb-distraction-count').textContent = pwebSession.distractions.length;
const logListEl = document.getElementById('pweb-distraction-log-list');
if (pwebSession.distractions.length === 1 && logListEl.firstChild.textContent.includes("No distractions")) {
logListEl.innerHTML = ''; // Clear "No distractions" message
}
const li = document.createElement('li');
const timeStr = new Date().toLocaleTimeString([], {hour:'2-digit', minute:'2-digit'});
li.textContent = `[${timeStr}] ${note || "Distraction logged"}`;
logListEl.appendChild(li);
document.getElementById('pweb-distraction-note').value = '';
}
// Pomodoro Timer Logic
function pwebUpdateTimerDisplay() {
const minutes = Math.floor(pwebTimerSecondsRemaining / 60);
const seconds = pwebTimerSecondsRemaining % 60;
document.getElementById('pweb-active-timer-display').textContent =
`${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
}
function pwebSetTimer(seconds) {
pwebTimerSecondsRemaining = seconds;
pwebUpdateTimerDisplay();
}
function pwebToggleTimer() {
const button = document.getElementById('pweb-timer-startpause');
if (pwebTimerInterval) { // Timer is running, so pause
clearInterval(pwebTimerInterval);
pwebTimerInterval = null;
button.textContent = "Resume";
} else { // Timer is paused or not started
if (pwebTimerSecondsRemaining <=0) { // If timer ended, reset to current block type
pwebIsPomodoroWorkTime ? pwebSetTimer(pwebSession.strategyConfig.work * 60) : pwebSetTimer(pwebSession.strategyConfig.break * 60);
}
pwebTimerInterval = setInterval(() => {
pwebTimerSecondsRemaining--;
pwebUpdateTimerDisplay();
if (pwebTimerSecondsRemaining <= 0) {
pwebClearTimer();
button.textContent = "Start Next"; // Or just "Start" if auto-advancing (not implemented here)
// Alert or visual cue for block end - not doing audio
document.getElementById('pweb-active-timer-display').textContent = "00:00 - Block Ended!";
}
}, 1000);
button.textContent = "Pause";
}
}
function pwebClearTimer() {
clearInterval(pwebTimerInterval);
pwebTimerInterval = null;
}
function pwebResetCurrentBlock() {
pwebClearTimer();
pwebIsPomodoroWorkTime ? pwebSetTimer(pwebSession.strategyConfig.work * 60) : pwebSetTimer(pwebSession.strategyConfig.break * 60);
document.getElementById('pweb-timer-startpause').textContent = "Start";
}
function pwebSkipToNext() {
pwebClearTimer();
pwebIsPomodoroWorkTime = !pwebIsPomodoroWorkTime;
if(pwebIsPomodoroWorkTime) pwebPomodoroCycleCount++; // New work cycle starts
const intervalType = pwebIsPomodoroWorkTime ? "Work" : "Break";
const duration = pwebIsPomodoroWorkTime ? pwebSession.strategyConfig.work : pwebSession.strategyConfig.break;
document.getElementById('pweb-active-current-interval').textContent = `Current Interval: ${intervalType} ${pwebIsPomodoroWorkTime ? `(Cycle ${pwebPomodoroCycleCount + 1})` : ''}`;
pwebSetTimer(duration * 60);
document.getElementById('pweb-timer-startpause').textContent = "Start";
}
// Session Review (Tab 3)
function pwebEndSession() {
pwebClearTimer(); // Stop timer if running
pwebPrepareReviewTab();
pwebOpenTab(null, 'pweb-review');
}
function pwebPrepareReviewTab() {
if (!pwebSession.date) { // Ensure session was started
document.getElementById('pweb-review-session-info').textContent = "No active session data. Please plan and start a session first.";
document.getElementById('pweb-review-goal-list').innerHTML = '';
document.getElementById('pweb-review-distraction-count').textContent = '0';
document.getElementById('pweb-booster-insights-list').innerHTML = '
No session data to analyze.
';
return;
}
pwebSession.review.generated = true; // Mark that review tab is prepared
document.getElementById('pweb-review-session-info').textContent = `Reviewing session from ${new Date(pwebSession.date+"T00:00:00").toLocaleDateString()} (Duration: ${pwebSession.duration} min).`;
const reviewGoalListEl = document.getElementById('pweb-review-goal-list');
reviewGoalListEl.innerHTML = '';
pwebSession.goals.forEach(goal => {
const li = document.createElement('li');
li.innerHTML = `
`;
reviewGoalListEl.appendChild(li);
});
document.getElementById('pweb-review-strategy-used').textContent = document.getElementById('pweb-strategy-select').selectedOptions[0].text;
document.getElementById('pweb-review-distraction-count').textContent = pwebSession.distractions.length;
// Reset review form fields (or load saved if implementing persistence for review itself)
document.getElementById('pweb-review-strategy-rating').value = '3';
document.getElementById('pweb-review-strategy-worked').value = '';
document.getElementById('pweb-review-strategy-challenging').value = '';
document.getElementById('pweb-review-focus').value = '3';
document.getElementById('pweb-review-efficiency').value = '3';
// Generate insights after review input (or preliminary ones, then update)
pwebGenerateBoosterInsights(); // Call this to initially populate, then again if review inputs change
}
function pwebGenerateBoosterInsights() { // Can be called from review form onchange if desired, or just once
pwebSession.review.strategyRating = parseInt(document.getElementById('pweb-review-strategy-rating').value);
pwebSession.review.strategyWorked = document.getElementById('pweb-review-strategy-worked').value.trim();
pwebSession.review.strategyChallenging = document.getElementById('pweb-review-strategy-challenging').value.trim();
pwebSession.review.focusRating = parseInt(document.getElementById('pweb-review-focus').value);
pwebSession.review.efficiencyRating = parseInt(document.getElementById('pweb-review-efficiency').value);
let insights = [];
const goalsCompleted = pwebSession.goals.filter(g => g.completed).length;
const totalGoals = pwebSession.goals.length;
if(pwebSession.review.strategyRating >= 4 && pwebSession.review.focusRating >=4){
insights.push(`The chosen strategy ('${document.getElementById('pweb-strategy-select').selectedOptions[0].text}') combined with your high focus seems very effective for you!`);
} else if (pwebSession.review.strategyRating <= 2) {
insights.push(`It seems the chosen strategy ('${document.getElementById('pweb-strategy-select').selectedOptions[0].text}') wasn't very effective. Consider why (see your 'challenges' notes) and perhaps try a different one next time.`);
}
if(pwebSession.distractions.length > 3 && pwebSession.review.focusRating <=2){
insights.push(`The ${pwebSession.distractions.length} distractions logged likely impacted your focus. Prioritizing a distraction minimization plan could be beneficial.`);
} else if (pwebSession.distractions.length <= 1 && pwebSession.review.focusRating >= 4) {
insights.push("Excellent job minimizing distractions and maintaining focus!");
}
if(totalGoals > 0 && goalsCompleted === totalGoals && pwebSession.review.efficiencyRating >=4){
insights.push("Congratulations on completing all your session goals efficiently!");
} else if (totalGoals > 0 && goalsCompleted < totalGoals / 2) {
insights.push("Less than half of the session goals were completed. Reflect on whether the goals were too ambitious for the session, if the strategy needs adjustment, or if external factors played a role.");
}
if (pwebSession.strategy === 'eat_the_frog' && pwebSession.strategyConfig.frogTask) {
const frogGoal = pwebSession.goals.find(g => g.text.toLowerCase().includes(pwebSession.strategyConfig.frogTask.toLowerCase()));
if (frogGoal && frogGoal.completed) {
insights.push("You successfully 'ate the frog'! Tackling the most challenging task first often sets a productive tone for the rest of the session.");
} else if (frogGoal && !frogGoal.completed){
insights.push("The 'frog' task remained incomplete. It might need to be broken down further or be the sole focus of a future dedicated session.");
}
}
if (insights.length === 0) {
insights.push("Reflect on your ratings and notes to draw personal conclusions. Consistent use of this tool can help identify patterns over time.");
}
const insightsListEl = document.getElementById('pweb-booster-insights-list');
insightsListEl.innerHTML = '';
insights.forEach(insight => {
const li = document.createElement('li');
li.textContent = insight;
insightsListEl.appendChild(li);
});
pwebSession.review.insightsGenerated = insights; // Store generated insights
}
// Add event listeners to review form elements to regenerate insights on change
['pweb-review-strategy-rating', 'pweb-review-strategy-worked', 'pweb-review-strategy-challenging', 'pweb-review-focus', 'pweb-review-efficiency'].forEach(id => {
const el = document.getElementById(id);
if(el) el.addEventListener('change', pwebGenerateBoosterInsights);
});
// PDF Download
function pwebDownloadPDFReport() {
if (!pwebSession.date || !pwebSession.review.generated) {
alert("Please complete a session and its review before downloading a report.");
return;
}
// Ensure insights are based on latest review inputs
pwebGenerateBoosterInsights();
let pdfHTML = `
Work Efficiency Session Report
`;
pdfHTML += `
Date: ${new Date(pwebSession.date+"T00:00:00").toLocaleDateString()} | Duration: ${pwebSession.duration} min