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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 2 |
+
// Initialize local storage for app data
|
| 3 |
+
const initializeStorage = () => {
|
| 4 |
+
if (!localStorage.getItem('beAppData')) {
|
| 5 |
+
const initialData = {
|
| 6 |
+
reflections: [],
|
| 7 |
+
decisions: [],
|
| 8 |
+
mindData: {
|
| 9 |
+
values: [],
|
| 10 |
+
thinkingPatterns: [],
|
| 11 |
+
growthAreas: []
|
| 12 |
+
},
|
| 13 |
+
streak: 0,
|
| 14 |
+
daysActive: 0,
|
| 15 |
+
reflectionsCount: 0,
|
| 16 |
+
insightsCount: 0,
|
| 17 |
+
decisionsCount: 0
|
| 18 |
+
};
|
| 19 |
+
localStorage.setItem('beAppData', JSON.stringify(initialData));
|
| 20 |
+
}
|
| 21 |
+
return JSON.parse(localStorage.getItem('beAppData'));
|
| 22 |
+
};
|
| 23 |
+
|
| 24 |
+
// Initialize app data
|
| 25 |
+
let appData = initializeStorage();
|
| 26 |
+
updateStatistics();
|
| 27 |
+
|
| 28 |
+
// Reset data functionality
|
| 29 |
+
const resetDataBtn = document.getElementById('reset-data-btn');
|
| 30 |
+
if (resetDataBtn) {
|
| 31 |
+
resetDataBtn.addEventListener('click', () => {
|
| 32 |
+
if (confirm('Are you sure you want to reset all data? This action cannot be undone.')) {
|
| 33 |
+
localStorage.removeItem('beAppData');
|
| 34 |
+
appData = initializeStorage();
|
| 35 |
+
updateStatistics();
|
| 36 |
+
updateUI();
|
| 37 |
+
showNotification('All data has been reset successfully!');
|
| 38 |
+
}
|
| 39 |
+
});
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
// Tab switching functionality
|
| 43 |
+
const bottomNavBtns = document.querySelectorAll('.bottom-nav-btn');
|
| 44 |
+
const tabContents = document.querySelectorAll('.tab-content');
|
| 45 |
+
|
| 46 |
+
bottomNavBtns.forEach(btn => {
|
| 47 |
+
btn.addEventListener('click', () => {
|
| 48 |
+
const targetTab = btn.getAttribute('data-tab');
|
| 49 |
+
|
| 50 |
+
// Update button active states
|
| 51 |
+
bottomNavBtns.forEach(b => b.classList.remove('active'));
|
| 52 |
+
btn.classList.add('active');
|
| 53 |
+
|
| 54 |
+
// Update tab content visibility
|
| 55 |
+
tabContents.forEach(content => {
|
| 56 |
+
if (content.id === targetTab) {
|
| 57 |
+
content.classList.add('active');
|
| 58 |
+
} else {
|
| 59 |
+
content.classList.remove('active');
|
| 60 |
+
}
|
| 61 |
+
});
|
| 62 |
+
|
| 63 |
+
// Scroll to top when changing tabs for better UX
|
| 64 |
+
window.scrollTo({ top: 0, behavior: 'smooth' });
|
| 65 |
+
});
|
| 66 |
+
});
|
| 67 |
+
|
| 68 |
+
// Save reflection functionality
|
| 69 |
+
const saveReflectionBtn = document.getElementById('save-reflection-btn');
|
| 70 |
+
const reflectionInput = document.getElementById('reflection-input');
|
| 71 |
+
|
| 72 |
+
if (saveReflectionBtn && reflectionInput) {
|
| 73 |
+
saveReflectionBtn.addEventListener('click', () => {
|
| 74 |
+
const reflection = reflectionInput.value.trim();
|
| 75 |
+
if (reflection) {
|
| 76 |
+
// Save to local storage
|
| 77 |
+
appData.reflections.unshift({
|
| 78 |
+
text: reflection,
|
| 79 |
+
date: new Date().toISOString(),
|
| 80 |
+
mood: 'Reflective'
|
| 81 |
+
});
|
| 82 |
+
|
| 83 |
+
// Update counts
|
| 84 |
+
appData.reflectionsCount++;
|
| 85 |
+
appData.daysActive = Math.min(appData.daysActive + 1, appData.reflections.length);
|
| 86 |
+
appData.streak++;
|
| 87 |
+
|
| 88 |
+
localStorage.setItem('beAppData', JSON.stringify(appData));
|
| 89 |
+
|
| 90 |
+
// Clear input
|
| 91 |
+
reflectionInput.value = '';
|
| 92 |
+
|
| 93 |
+
// Update UI
|
| 94 |
+
updateStatistics();
|
| 95 |
+
updateReflections();
|
| 96 |
+
|
| 97 |
+
// Show feedback
|
| 98 |
+
showNotification('Reflection saved successfully!');
|
| 99 |
+
} else {
|
| 100 |
+
alert('Please enter your reflection before saving.');
|
| 101 |
+
}
|
| 102 |
+
});
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
// Decision assistant functionality
|
| 106 |
+
const decisionSteps = document.querySelectorAll('.decision-step');
|
| 107 |
+
const decisionTypeSelector = document.getElementById('decision-type-selector');
|
| 108 |
+
let selectedDecisionType = null;
|
| 109 |
+
|
| 110 |
+
// Decision Type Selection
|
| 111 |
+
if (decisionTypeSelector) {
|
| 112 |
+
decisionTypeSelector.addEventListener('click', (e) => {
|
| 113 |
+
const button = e.target.closest('.decision-type-btn');
|
| 114 |
+
if (button) {
|
| 115 |
+
// Remove selected class from all buttons
|
| 116 |
+
decisionTypeSelector.querySelectorAll('.decision-type-btn').forEach(btn => {
|
| 117 |
+
btn.classList.remove('selected', 'border-indigo-500', 'bg-indigo-100');
|
| 118 |
+
});
|
| 119 |
+
// Add selected class to the clicked button
|
| 120 |
+
button.classList.add('selected', 'border-indigo-500', 'bg-indigo-100');
|
| 121 |
+
selectedDecisionType = button.getAttribute('data-type');
|
| 122 |
+
}
|
| 123 |
+
});
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
const navigateToStep = (targetStepId) => {
|
| 127 |
+
decisionSteps.forEach(step => {
|
| 128 |
+
if (step.id === targetStepId) {
|
| 129 |
+
step.classList.remove('hidden');
|
| 130 |
+
} else {
|
| 131 |
+
step.classList.add('hidden');
|
| 132 |
+
}
|
| 133 |
+
});
|
| 134 |
+
|
| 135 |
+
// Scroll to the top of the decision maker card
|
| 136 |
+
const deciderCard = document.querySelector('#decider .bg-white');
|
| 137 |
+
if (deciderCard) {
|
| 138 |
+
deciderCard.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
| 139 |
+
}
|
| 140 |
+
};
|
| 141 |
+
|
| 142 |
+
// Navigation Button Event Listeners
|
| 143 |
+
document.getElementById('to-step-2')?.addEventListener('click', () => {
|
| 144 |
+
const description = document.getElementById('decision-description').value.trim();
|
| 145 |
+
if (!description) {
|
| 146 |
+
alert('Please describe the decision you are facing.');
|
| 147 |
+
return;
|
| 148 |
+
}
|
| 149 |
+
if (!selectedDecisionType) {
|
| 150 |
+
alert('Please select a decision type.');
|
| 151 |
+
return;
|
| 152 |
+
}
|
| 153 |
+
navigateToStep('decision-step-2');
|
| 154 |
+
});
|
| 155 |
+
|
| 156 |
+
document.getElementById('to-step-3')?.addEventListener('click', () => {
|
| 157 |
+
// Validate options
|
| 158 |
+
const options = document.querySelectorAll('.option-item');
|
| 159 |
+
let valid = true;
|
| 160 |
+
|
| 161 |
+
options.forEach(option => {
|
| 162 |
+
const title = option.querySelector('.option-title').value.trim();
|
| 163 |
+
const description = option.querySelector('.option-description').value.trim();
|
| 164 |
+
|
| 165 |
+
if (!title || !description) {
|
| 166 |
+
valid = false;
|
| 167 |
+
}
|
| 168 |
+
});
|
| 169 |
+
|
| 170 |
+
if (!valid) {
|
| 171 |
+
alert('Please complete all option details before proceeding.');
|
| 172 |
+
return;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
// Generate analysis
|
| 176 |
+
generateAnalysis();
|
| 177 |
+
navigateToStep('decision-step-3');
|
| 178 |
+
});
|
| 179 |
+
|
| 180 |
+
// Back buttons
|
| 181 |
+
document.querySelectorAll('.back-btn').forEach(button => {
|
| 182 |
+
button.addEventListener('click', () => {
|
| 183 |
+
const targetStepId = button.getAttribute('data-target');
|
| 184 |
+
navigateToStep(targetStepId);
|
| 185 |
+
});
|
| 186 |
+
});
|
| 187 |
+
|
| 188 |
+
// Add Option Button
|
| 189 |
+
const addOptionBtn = document.getElementById('add-option');
|
| 190 |
+
const optionContainer = document.getElementById('option-container');
|
| 191 |
+
let optionCounter = 2; // Start counting from 3 since 2 are already present
|
| 192 |
+
|
| 193 |
+
if (addOptionBtn && optionContainer) {
|
| 194 |
+
addOptionBtn.addEventListener('click', () => {
|
| 195 |
+
optionCounter++;
|
| 196 |
+
const newOption = document.createElement('div');
|
| 197 |
+
newOption.className = 'option-item p-4 border border-gray-300 rounded-lg bg-gray-50 relative slide-in';
|
| 198 |
+
newOption.innerHTML = `
|
| 199 |
+
<input type="text" class="option-title w-full p-2 border-b border-gray-300 mb-2 focus:outline-none focus:border-indigo-500 font-medium bg-transparent" placeholder="Option ${optionCounter} Title">
|
| 200 |
+
<textarea class="option-description w-full p-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 h-20 resize-none mt-1 transition duration-150 ease-in-out" placeholder="Describe this option..."></textarea>
|
| 201 |
+
<button class="remove-option absolute top-2 right-2 text-gray-400 hover:text-red-500 text-sm p-1" title="Remove option">×</button>
|
| 202 |
+
`;
|
| 203 |
+
optionContainer.appendChild(newOption);
|
| 204 |
+
|
| 205 |
+
// Add event listener to the new remove button
|
| 206 |
+
newOption.querySelector('.remove-option').addEventListener('click', handleRemoveOption);
|
| 207 |
+
});
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
// Remove Option Functionality
|
| 211 |
+
const handleRemoveOption = (event) => {
|
| 212 |
+
if (optionContainer.querySelectorAll('.option-item').length > 2) {
|
| 213 |
+
event.target.closest('.option-item').remove();
|
| 214 |
+
} else {
|
| 215 |
+
alert("At least two options are required.");
|
| 216 |
+
}
|
| 217 |
+
};
|
| 218 |
+
|
| 219 |
+
document.querySelectorAll('.remove-option').forEach(btn => {
|
| 220 |
+
btn.addEventListener('click', handleRemoveOption);
|
| 221 |
+
});
|
| 222 |
+
|
| 223 |
+
// Generate decision analysis
|
| 224 |
+
const generateAnalysis = () => {
|
| 225 |
+
const options = [];
|
| 226 |
+
document.querySelectorAll('.option-item').forEach(item => {
|
| 227 |
+
const title = item.querySelector('.option-title').value || 'Unnamed Option';
|
| 228 |
+
const description = item.querySelector('.option-description').value || 'No description provided.';
|
| 229 |
+
options.push({ title, description });
|
| 230 |
+
});
|
| 231 |
+
|
| 232 |
+
const decisionDesc = document.getElementById('decision-description')?.value || 'the decision';
|
| 233 |
+
const decisionType = selectedDecisionType || 'General';
|
| 234 |
+
|
| 235 |
+
// Generate analysis HTML
|
| 236 |
+
let prosConsHtml = `<p>Comparing options for <strong>${decisionDesc}</strong> (Type: ${decisionType}):</p>`;
|
| 237 |
+
let valueHtml = `<p>Considering your values related to a <strong>${decisionType}</strong> decision:</p>`;
|
| 238 |
+
let recommendationHtml = `<p>Recommendation for <strong>${decisionDesc}</strong>:</p>`;
|
| 239 |
+
|
| 240 |
+
options.forEach((opt, index) => {
|
| 241 |
+
// Extract pros and cons from description
|
| 242 |
+
const pros = [];
|
| 243 |
+
const cons = [];
|
| 244 |
+
|
| 245 |
+
// Simple analysis based on keywords in description
|
| 246 |
+
const words = opt.description.toLowerCase().split(/\s+/);
|
| 247 |
+
if (words.some(w => ['good', 'great', 'benefit', 'advantage', 'positive', 'pro'].includes(w))) {
|
| 248 |
+
pros.push('Positive aspects mentioned');
|
| 249 |
+
}
|
| 250 |
+
if (words.some(w => ['bad', 'drawback', 'downside', 'negative', 'con', 'concern'].includes(w))) {
|
| 251 |
+
cons.push('Concerns or drawbacks noted');
|
| 252 |
+
}
|
| 253 |
+
|
| 254 |
+
// Add a default if nothing detected
|
| 255 |
+
if (pros.length === 0) pros.push('Potential benefits could be explored further');
|
| 256 |
+
if (cons.length === 0) cons.push('Consider any potential downsides');
|
| 257 |
+
|
| 258 |
+
prosConsHtml += `
|
| 259 |
+
<div class="mt-2 p-2 border-l-2 border-indigo-200">
|
| 260 |
+
<strong>${opt.title}:</strong>
|
| 261 |
+
<div class="mt-1">
|
| 262 |
+
<span class="text-green-600 font-medium">Pros:</span> ${pros.join(', ')}
|
| 263 |
+
</div>
|
| 264 |
+
<div class="mt-1">
|
| 265 |
+
<span class="text-red-600 font-medium">Cons:</span> ${cons.join(', ')}
|
| 266 |
+
</div>
|
| 267 |
+
</div>
|
| 268 |
+
`;
|
| 269 |
+
|
| 270 |
+
// Value alignment based on decision type
|
| 271 |
+
const values = appData.mindData.values.length > 0 ?
|
| 272 |
+
appData.mindData.values :
|
| 273 |
+
['Growth', 'Balance', 'Security', 'Freedom', 'Connection'];
|
| 274 |
+
const alignedValue = values[index % values.length]; // Just for demonstration
|
| 275 |
+
|
| 276 |
+
valueHtml += `<p class="mt-1">- <strong>${opt.title}</strong> appears to align with your value of <strong>${alignedValue}</strong> based on the description.</p>`;
|
| 277 |
+
});
|
| 278 |
+
|
| 279 |
+
// Simple recommendation logic (alternate between options for demo)
|
| 280 |
+
const recommendedOption = options[0]; // Default to first option
|
| 281 |
+
recommendationHtml += `
|
| 282 |
+
<p class="mt-2">Based on the analysis, <strong>${recommendedOption.title}</strong> appears to be a strong option, particularly considering your values.</p>
|
| 283 |
+
<p class="mt-1"><strong>Considerations:</strong> Before finalizing your decision, reflect on how each option affects your long-term goals and whether there are any aspects you haven't fully explored.</p>
|
| 284 |
+
`;
|
| 285 |
+
|
| 286 |
+
// Update the UI
|
| 287 |
+
document.getElementById('pros-cons-analysis').innerHTML = prosConsHtml;
|
| 288 |
+
document.getElementById('value-alignment-analysis').innerHTML = valueHtml;
|
| 289 |
+
document.getElementById('ai-recommendation').innerHTML = recommendationHtml;
|
| 290 |
+
};
|
| 291 |
+
|
| 292 |
+
// Save Decision Button
|
| 293 |
+
document.getElementById('save-decision')?.addEventListener('click', () => {
|
| 294 |
+
const decisionDesc = document.getElementById('decision-description')?.value || 'Unnamed Decision';
|
| 295 |
+
const decisionType = selectedDecisionType || 'General';
|
| 296 |
+
|
| 297 |
+
// Get options
|
| 298 |
+
const options = [];
|
| 299 |
+
document.querySelectorAll('.option-item').forEach(item => {
|
| 300 |
+
const title = item.querySelector('.option-title').value || 'Unnamed Option';
|
| 301 |
+
const description = item.querySelector('.option-description').value || 'No description';
|
| 302 |
+
options.push({ title, description });
|
| 303 |
+
});
|
| 304 |
+
|
| 305 |
+
// Save to local storage
|
| 306 |
+
appData.decisions.unshift({
|
| 307 |
+
title: decisionDesc,
|
| 308 |
+
type: decisionType,
|
| 309 |
+
options: options,
|
| 310 |
+
date: new Date().toISOString(),
|
| 311 |
+
status: 'Pending'
|
| 312 |
+
});
|
| 313 |
+
|
| 314 |
+
appData.decisionsCount++;
|
| 315 |
+
localStorage.setItem('beAppData', JSON.stringify(appData));
|
| 316 |
+
|
| 317 |
+
// Update UI
|
| 318 |
+
updateStatistics();
|
| 319 |
+
updateDecisions();
|
| 320 |
+
|
| 321 |
+
// Show feedback and reset form
|
| 322 |
+
showNotification('Decision analysis saved successfully!');
|
| 323 |
+
navigateToStep('decision-step-1');
|
| 324 |
+
document.getElementById('decision-description').value = '';
|
| 325 |
+
decisionTypeSelector.querySelectorAll('.decision-type-btn').forEach(btn => {
|
| 326 |
+
btn.classList.remove('selected', 'border-indigo-500', 'bg-indigo-100');
|
| 327 |
+
});
|
| 328 |
+
selectedDecisionType = null;
|
| 329 |
+
});
|
| 330 |
+
|
| 331 |
+
// Chat functionality
|
| 332 |
+
const chatMessages = document.getElementById('chat-messages');
|
| 333 |
+
const chatInput = document.getElementById('chat-input');
|
| 334 |
+
const sendChatBtn = document.getElementById('send-chat-btn');
|
| 335 |
+
|
| 336 |
+
const addChatMessage = (message, isUser = true) => {
|
| 337 |
+
if (!message.trim()) return;
|
| 338 |
+
|
| 339 |
+
const messageElement = document.createElement('div');
|
| 340 |
+
messageElement.classList.add('chat-message', isUser ? 'user-message' : 'ai-message', 'slide-in');
|
| 341 |
+
|
| 342 |
+
const contentElement = document.createElement('p');
|
| 343 |
+
contentElement.classList.add('text-gray-800');
|
| 344 |
+
contentElement.textContent = message;
|
| 345 |
+
|
| 346 |
+
const timeElement = document.createElement('span');
|
| 347 |
+
timeElement.classList.add('text-xs', 'text-gray-500', 'mt-1', 'block', 'text-right');
|
| 348 |
+
timeElement.textContent = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
| 349 |
+
|
| 350 |
+
messageElement.appendChild(contentElement);
|
| 351 |
+
messageElement.appendChild(timeElement);
|
| 352 |
+
|
| 353 |
+
if (chatMessages) {
|
| 354 |
+
chatMessages.appendChild(messageElement);
|
| 355 |
+
// Scroll to the bottom
|
| 356 |
+
chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 357 |
+
}
|
| 358 |
+
};
|
| 359 |
+
|
| 360 |
+
const handleSendChat = () => {
|
| 361 |
+
if (!chatInput) return;
|
| 362 |
+
|
| 363 |
+
const message = chatInput.value;
|
| 364 |
+
if (message.trim()) {
|
| 365 |
+
addChatMessage(message, true);
|
| 366 |
+
chatInput.value = '';
|
| 367 |
+
|
| 368 |
+
// Simulate AI response after a short delay
|
| 369 |
+
setTimeout(() => {
|
| 370 |
+
// Enhanced AI responses based on message content
|
| 371 |
+
let aiResponse = '';
|
| 372 |
+
const lowerMessage = message.toLowerCase();
|
| 373 |
+
|
| 374 |
+
if (lowerMessage.includes('career') || lowerMessage.includes('job') || lowerMessage.includes('work')) {
|
| 375 |
+
aiResponse = `It sounds like you're thinking about your career path. Professional transitions can be challenging but also exciting opportunities for growth. What specific aspects of your career are you looking to change?`;
|
| 376 |
+
} else if (lowerMessage.includes('relationship') || lowerMessage.includes('partner') || lowerMessage.includes('friend')) {
|
| 377 |
+
aiResponse = `Relationships are such an important part of our wellbeing. I notice you're thinking about connections in your life. Would you like to explore how your values might guide your approach to this relationship?`;
|
| 378 |
+
} else if (lowerMessage.includes('stress') || lowerMessage.includes('anxiety') || lowerMessage.includes('worry')) {
|
| 379 |
+
aiResponse = `I hear that you're experiencing some challenging emotions. Remember that it's normal to feel this way sometimes. Would it help to discuss some simple mindfulness techniques that could help manage these feelings in the moment?`;
|
| 380 |
+
} else {
|
| 381 |
+
aiResponse = `Thanks for sharing that. I'm curious to learn more about how this relates to your personal growth journey. Could you tell me what outcome you're hoping for?`;
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
addChatMessage(aiResponse, false);
|
| 385 |
+
}, 1000);
|
| 386 |
+
}
|
| 387 |
+
};
|
| 388 |
+
|
| 389 |
+
if (sendChatBtn && chatInput) {
|
| 390 |
+
sendChatBtn.addEventListener('click', handleSendChat);
|
| 391 |
+
chatInput.addEventListener('keypress', (e) => {
|
| 392 |
+
if (e.key === 'Enter') {
|
| 393 |
+
handleSendChat();
|
| 394 |
+
}
|
| 395 |
+
});
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
// UI Update Functions
|
| 399 |
+
function updateStatistics() {
|
| 400 |
+
document.getElementById('streak-count').textContent = appData.streak;
|
| 401 |
+
document.getElementById('reflections-count').textContent = appData.reflectionsCount;
|
| 402 |
+
document.getElementById('insights-count').textContent = appData.insightsCount;
|
| 403 |
+
document.getElementById('decisions-count').textContent = appData.decisionsCount;
|
| 404 |
+
document.getElementById('days-active-count').textContent = appData.daysActive;
|
| 405 |
+
|
| 406 |
+
// Update progress circle
|
| 407 |
+
const progressCircle = document.querySelector('.progress-circle-value');
|
| 408 |
+
const progressText = document.querySelector('.progress-circle-text');
|
| 409 |
+
let progress = 0;
|
| 410 |
+
|
| 411 |
+
if (appData.streak > 0) {
|
| 412 |
+
progress = Math.min(Math.round((appData.streak / 7) * 100), 100);
|
| 413 |
+
progressCircle.style.strokeDashoffset = 100 - progress;
|
| 414 |
+
progressText.textContent = progress + '%';
|
| 415 |
+
} else {
|
| 416 |
+
progressCircle.style.strokeDashoffset = 100;
|
| 417 |
+
progressText.textContent = '0%';
|
| 418 |
+
}
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
function updateReflections() {
|
| 422 |
+
const container = document.getElementById('past-reflections');
|
| 423 |
+
const noReflectionsMsg = document.getElementById('no-reflections-message');
|
| 424 |
+
|
| 425 |
+
if (container) {
|
| 426 |
+
// Clear existing content except the no-reflections message
|
| 427 |
+
Array.from(container.children).forEach(child => {
|
| 428 |
+
if (child.id !== 'no-reflections-message') {
|
| 429 |
+
child.remove();
|
| 430 |
+
}
|
| 431 |
+
});
|
| 432 |
+
|
| 433 |
+
if (appData.reflections.length > 0) {
|
| 434 |
+
// Hide the no-reflections message
|
| 435 |
+
if (noReflectionsMsg) noReflectionsMsg.classList.add('hidden');
|
| 436 |
+
|
| 437 |
+
// Add reflection cards
|
| 438 |
+
appData.reflections.slice(0, 6).forEach(reflection => {
|
| 439 |
+
const date = new Date(reflection.date);
|
| 440 |
+
const timeAgo = getTimeAgo(date);
|
| 441 |
+
|
| 442 |
+
const card = document.createElement('div');
|
| 443 |
+
card.className = 'bg-white border border-gray-200 rounded-lg p-4 shadow-sm hover:shadow-md transition-shadow';
|
| 444 |
+
card.innerHTML = `
|
| 445 |
+
<div class="flex justify-between items-start mb-3">
|
| 446 |
+
<span class="text-xs text-gray-500">${timeAgo}</span>
|
| 447 |
+
<span class="text-xs font-medium text-indigo-600">Mood: ${reflection.mood || 'Reflective'}</span>
|
| 448 |
+
</div>
|
| 449 |
+
<p class="text-gray-700 text-sm">${reflection.text}</p>
|
| 450 |
+
`;
|
| 451 |
+
container.appendChild(card);
|
| 452 |
+
});
|
| 453 |
+
} else {
|
| 454 |
+
// Show the no-reflections message
|
| 455 |
+
if (noReflectionsMsg) noReflectionsMsg.classList.remove('hidden');
|
| 456 |
+
}
|
| 457 |
+
}
|
| 458 |
+
}
|
| 459 |
+
|
| 460 |
+
function updateDecisions() {
|
| 461 |
+
const container = document.getElementById('recent-decisions');
|
| 462 |
+
const noDecisionsMsg = document.getElementById('no-decisions-message');
|
| 463 |
+
|
| 464 |
+
if (container) {
|
| 465 |
+
// Clear existing content except the no-decisions message
|
| 466 |
+
Array.from(container.children).forEach(child => {
|
| 467 |
+
if (child.id !== 'no-decisions-message') {
|
| 468 |
+
child.remove();
|
| 469 |
+
}
|
| 470 |
+
});
|
| 471 |
+
|
| 472 |
+
if (appData.decisions.length > 0) {
|
| 473 |
+
// Hide the no-decisions message
|
| 474 |
+
if (noDecisionsMsg) noDecisionsMsg.classList.add('hidden');
|
| 475 |
+
|
| 476 |
+
// Add decision cards
|
| 477 |
+
appData.decisions.slice(0, 4).forEach((decision, index) => {
|
| 478 |
+
const date = new Date(decision.date);
|
| 479 |
+
const timeAgo = getTimeAgo(date);
|
| 480 |
+
|
| 481 |
+
const card = document.createElement('div');
|
| 482 |
+
card.className = 'decision-card bg-white border border-gray-200 rounded-lg p-5 shadow hover:shadow-md';
|
| 483 |
+
card.innerHTML = `
|
| 484 |
+
<div class="flex justify-between items-start mb-3">
|
| 485 |
+
<h3 class="font-semibold text-lg text-gray-800">${decision.title}</h3>
|
| 486 |
+
<span class="text-xs text-gray-500">${timeAgo}</span>
|
| 487 |
+
</div>
|
| 488 |
+
<p class="text-gray-600 text-sm mb-3">Analysis of ${decision.type} decision with ${decision.options.length} options.</p>
|
| 489 |
+
<div class="flex justify-between items-center mt-4">
|
| 490 |
+
<span class="px-3 py-1 bg-${index % 2 === 0 ? 'green' : 'yellow'}-100 text-${index % 2 === 0 ? 'green' : 'yellow'}-800 rounded-full text-xs font-medium">${index % 2 === 0 ? 'Resolved' : 'Pending'}</span>
|
| 491 |
+
<button class="text-indigo-600 hover:text-indigo-800 text-sm font-medium focus:outline-none transition duration-150 ease-in-out">View Details</button>
|
| 492 |
+
</div>
|
| 493 |
+
`;
|
| 494 |
+
container.appendChild(card);
|
| 495 |
+
});
|
| 496 |
+
} else {
|
| 497 |
+
// Show the no-decisions message
|
| 498 |
+
if (noDecisionsMsg) noDecisionsMsg.classList.remove('hidden');
|
| 499 |
+
}
|
| 500 |
+
}
|
| 501 |
+
}
|
| 502 |
+
|
| 503 |
+
function updateMindData() {
|
| 504 |
+
const valuesList = document.getElementById('values-list');
|
| 505 |
+
const thinkingPatternsList = document.getElementById('thinking-patterns-list');
|
| 506 |
+
|
| 507 |
+
if (valuesList) {
|
| 508 |
+
valuesList.innerHTML = '';
|
| 509 |
+
|
| 510 |
+
const values = appData.mindData.values.length > 0 ?
|
| 511 |
+
appData.mindData.values :
|
| 512 |
+
['Start reflecting to discover your values'];
|
| 513 |
+
|
| 514 |
+
values.forEach(value => {
|
| 515 |
+
const li = document.createElement('li');
|
| 516 |
+
li.textContent = value;
|
| 517 |
+
valuesList.appendChild(li);
|
| 518 |
+
});
|
| 519 |
+
}
|
| 520 |
+
|
| 521 |
+
if (thinkingPatternsList) {
|
| 522 |
+
thinkingPatternsList.innerHTML = '';
|
| 523 |
+
|
| 524 |
+
const patterns = appData.mindData.thinkingPatterns.length > 0 ?
|
| 525 |
+
appData.mindData.thinkingPatterns :
|
| 526 |
+
['Make decisions to identify your thinking patterns'];
|
| 527 |
+
|
| 528 |
+
patterns.forEach(pattern => {
|
| 529 |
+
const li = document.createElement('li');
|
| 530 |
+
li.textContent = pattern;
|
| 531 |
+
thinkingPatternsList.appendChild(li);
|
| 532 |
+
});
|
| 533 |
+
}
|
| 534 |
+
}
|
| 535 |
+
|
| 536 |
+
function updateUI() {
|
| 537 |
+
updateStatistics();
|
| 538 |
+
updateReflections();
|
| 539 |
+
updateDecisions();
|
| 540 |
+
updateMindData();
|
| 541 |
+
}
|
| 542 |
+
|
| 543 |
+
// Helper Functions
|
| 544 |
+
function getTimeAgo(date) {
|
| 545 |
+
const now = new Date();
|
| 546 |
+
const diffInSeconds = Math.floor((now - date) / 1000);
|
| 547 |
+
|
| 548 |
+
if (diffInSeconds < 60) return 'Just now';
|
| 549 |
+
if (diffInSeconds < 3600) return `${Math.floor(diffInSeconds / 60)} minutes ago`;
|
| 550 |
+
if (diffInSeconds < 86400) return `${Math.floor(diffInSeconds / 3600)} hours ago`;
|
| 551 |
+
if (diffInSeconds < 604800) return `${Math.floor(diffInSeconds / 86400)} days ago`;
|
| 552 |
+
|
| 553 |
+
return date.toLocaleDateString();
|
| 554 |
+
}
|
| 555 |
+
|
| 556 |
+
function showNotification(message) {
|
| 557 |
+
// Remove any existing notifications
|
| 558 |
+
const existingNotification = document.querySelector('.notification');
|
| 559 |
+
if (existingNotification) {
|
| 560 |
+
existingNotification.remove();
|
| 561 |
+
}
|
| 562 |
+
|
| 563 |
+
// Create and add the new notification
|
| 564 |
+
const notification = document.createElement('div');
|
| 565 |
+
notification.className = 'notification';
|
| 566 |
+
notification.textContent = message;
|
| 567 |
+
document.body.appendChild(notification);
|
| 568 |
+
|
| 569 |
+
// Remove the notification after 3 seconds
|
| 570 |
+
setTimeout(() => {
|
| 571 |
+
if (notification && notification.parentNode) {
|
| 572 |
+
notification.remove();
|
| 573 |
+
}
|
| 574 |
+
}, 3000);
|
| 575 |
+
}
|
| 576 |
+
|
| 577 |
+
// Initialize UI
|
| 578 |
+
updateUI();
|
| 579 |
+
});
|