-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
2765 lines (2400 loc) · 111 KB
/
Copy pathscript.js
File metadata and controls
2765 lines (2400 loc) · 111 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* CeeFusion – CEE & NEET Full-Stack Preparation Platform Router & Controllers
* Implements SPA routing, localStorage sync, profile verification, CEE Nepal 200 Qs Mock Test Engine,
* 30-Question Chapter Quizzes with negative marking, and category-divided syllabus rendering.
*/
document.addEventListener('DOMContentLoaded', () => {
// ==========================================================================
// GLOBAL APPLICATION STATE
// ==========================================================================
let appState = {
progress: {}, // { chapterId: { completed: false, quizScore: null } }
mockTests: [], // [ { id, date, score, correct, incorrect, unattempted, total, timeTaken, subjects: [] } ]
studySchedule: [], // [ { id, task, time, subject, done: false } ]
scratchpad: "", // Saved scratchpad text
};
// Live timed CEE Mock Exam active variables
let activeExam = {
questions: [], // Holds exactly 200 questions
currentIndex: 0,
answers: {}, // { index: selectedOptionIndex }
marked: {}, // { index: boolean } (Flagged for review)
visited: {}, // { index: boolean }
timeRemaining: 0, // seconds
totalDuration: 0, // seconds
timerInterval: null,
subjectStats: {}, // Tracks behavioral metrics per subject category
};
// Active chapter quiz variables
let activeQuiz = {
chapterId: null, // subjectKey-categoryKey-chapterKey
subjectKey: null,
categoryKey: null,
chapterKey: null,
questions: [], // Holds exactly 30 questions compiled procedurally
currentIndex: 0,
answers: {},
timeRemaining: 0, // seconds (100 minutes)
timerInterval: null,
score: 0,
correctCount: 0,
incorrectCount: 0,
};
// Drilldown chapter state
let activeDrilldown = {
subjectKey: null,
categoryKey: null,
chapterKey: null,
};
// Category User-Friendly Names mapping
const categoryNames = {
// Physics
mechanics: "Mechanics",
thermodynamics: "Properties of Matter & Thermodynamics",
waves: "Oscillations & Waves",
electromagnetism: "Electromagnetism",
optics: "Optics",
modern_physics: "Modern Physics",
// Chemistry
physical: "Physical Chemistry",
inorganic: "Inorganic Chemistry",
organic: "Organic Chemistry",
// Biology
diversity_structure: "Diversity & Structure",
cell_biology: "Cell Biology",
plant_physiology: "Plant Physiology",
human_physiology: "Human Physiology",
reproduction_genetics: "Reproduction & Genetics",
biotechnology_ecology: "Biotechnology & Ecology",
// Mathematics
algebra: "Algebra",
trigonometry: "Trigonometry",
geometry: "Coordinate Geometry"
};
// ==========================================================================
// SIGN-IN & SESSION SECURITY LOCKS
// ==========================================================================
function checkSession() {
const profile = localStorage.getItem('edupeak_user_profile');
const overlay = document.getElementById('sign-in-screen');
if (profile) {
// Hide sign-in screen immediately
overlay.classList.add('hidden');
overlay.style.opacity = '0';
overlay.style.pointerEvents = 'none';
const parsed = JSON.parse(profile);
updateUserProfileUI(parsed);
// Load progress state
loadState();
navigateTo('dashboard');
} else {
// Show and lock sign-in screen
overlay.classList.remove('hidden');
overlay.style.opacity = '1';
overlay.style.pointerEvents = 'auto';
}
}
function updateUserProfileUI(profile) {
const name = profile.name || "Guest User";
const email = profile.email || "guest@mail.com";
const exam = profile.targetExam || "cee";
// Calculate initials
const words = name.trim().split(/\s+/);
let initials = "GU";
if (words.length > 1) {
initials = (words[0][0] + words[words.length - 1][0]).toUpperCase();
} else if (words.length === 1 && words[0].length > 0) {
initials = words[0][0].toUpperCase() + (words[0][1] || "").toUpperCase();
}
// Exam badge label mapping
let examLabel = "CEE Nepal Aspirant";
if (exam === "neet") {
examLabel = "NEET Aspirant";
} else if (exam === "both") {
examLabel = "CEE & NEET Aspirant";
}
// Update Desktop Sidebar
const userAvatarInitials = document.getElementById('user-avatar-initials');
if (userAvatarInitials) userAvatarInitials.textContent = initials;
const userDisplayName = document.getElementById('user-display-name');
if (userDisplayName) userDisplayName.textContent = name;
const userDisplayBadge = document.getElementById('user-display-badge');
if (userDisplayBadge) {
userDisplayBadge.innerHTML = `<span class="w-1.5 h-1.5 rounded-full bg-emerald-500"></span> ${examLabel}`;
}
// Update Mobile Drawer
const mobileUserAvatarInitials = document.getElementById('mobile-user-avatar-initials');
if (mobileUserAvatarInitials) mobileUserAvatarInitials.textContent = initials;
const mobileUserDisplayName = document.getElementById('mobile-user-display-name');
if (mobileUserDisplayName) mobileUserDisplayName.textContent = name;
const mobileUserDisplayBadge = document.getElementById('mobile-user-display-badge');
if (mobileUserDisplayBadge) {
mobileUserDisplayBadge.innerHTML = `<span class="w-1.5 h-1.5 rounded-full bg-emerald-500"></span> ${examLabel}`;
}
// Update Mobile Header
const mobileHeaderAvatar = document.getElementById('mobile-header-avatar');
if (mobileHeaderAvatar) mobileHeaderAvatar.textContent = initials;
// Update Dashboard Welcome text
const welcomeUserName = document.getElementById('welcome-user-name');
if (welcomeUserName) {
welcomeUserName.textContent = words[0];
}
}
// Helper for authentication error field styling
function setFieldError(inputEl, errorEl, message) {
if (inputEl) inputEl.style.borderColor = '#ef4444';
if (errorEl) {
errorEl.textContent = message;
errorEl.classList.remove('hidden');
}
}
function resetFieldErrors() {
['signin-name', 'signin-email', 'signin-exam', 'signin-password'].forEach(id => {
const el = document.getElementById(id);
if (el) el.style.borderColor = '';
});
['error-signin-name', 'error-signin-email', 'error-signin-exam', 'error-signin-password'].forEach(id => {
const el = document.getElementById(id);
if (el) el.classList.add('hidden');
});
}
// Auth Tab Switching Logic
const tabSignup = document.getElementById('auth-tab-signup');
const tabLogin = document.getElementById('auth-tab-login');
const modeInput = document.getElementById('auth-mode-input');
const modalTitle = document.getElementById('auth-modal-title');
const modalSub = document.getElementById('auth-modal-subtitle');
const wrapperName = document.getElementById('wrapper-signin-name');
const wrapperExam = document.getElementById('wrapper-signin-exam');
const btnAuthSubmit = document.getElementById('btn-auth-submit');
if (tabSignup && tabLogin) {
tabSignup.addEventListener('click', () => {
resetFieldErrors();
if (modeInput) modeInput.value = 'signup';
tabSignup.className = "flex-1 py-2 text-sm font-bold text-center text-brand-primary border-b-2 border-brand-primary transition-all";
tabLogin.className = "flex-1 py-2 text-sm font-bold text-center text-gray-400 border-b-2 border-transparent hover:text-gray-200 transition-all";
if (modalTitle) modalTitle.textContent = "Create CeeFusion Account";
if (modalSub) modalSub.textContent = "Initialize your student profile and unlock exam revisions.";
if (wrapperName) wrapperName.style.display = 'block';
if (wrapperExam) wrapperExam.style.display = 'block';
if (btnAuthSubmit) btnAuthSubmit.innerHTML = `<i class="fa-solid fa-user-plus mr-1"></i> Create Account`;
});
tabLogin.addEventListener('click', () => {
resetFieldErrors();
if (modeInput) modeInput.value = 'login';
tabLogin.className = "flex-1 py-2 text-sm font-bold text-center text-brand-primary border-b-2 border-brand-primary transition-all";
tabSignup.className = "flex-1 py-2 text-sm font-bold text-center text-gray-400 border-b-2 border-transparent hover:text-gray-200 transition-all";
if (modalTitle) modalTitle.textContent = "Log In to CeeFusion";
if (modalSub) modalSub.textContent = "Enter your credentials to access your saved progress.";
if (wrapperName) wrapperName.style.display = 'none';
if (wrapperExam) wrapperExam.style.display = 'none';
if (btnAuthSubmit) btnAuthSubmit.innerHTML = `<i class="fa-solid fa-lock-open mr-1"></i> Log In`;
});
}
// Bind Sign-In / Sign-Up submit validation
const signinForm = document.getElementById('edupeak-signin-form');
if (signinForm) {
signinForm.addEventListener('submit', (e) => {
e.preventDefault();
resetFieldErrors();
const mode = modeInput ? modeInput.value : 'signup';
const nameInput = document.getElementById('signin-name');
const emailInput = document.getElementById('signin-email');
const examInput = document.getElementById('signin-exam');
const passwordInput = document.getElementById('signin-password');
const errName = document.getElementById('error-signin-name');
const errEmail = document.getElementById('error-signin-email');
const errExam = document.getElementById('error-signin-exam');
const errPassword = document.getElementById('error-signin-password');
let valid = true;
let registeredUsers = [];
try {
registeredUsers = JSON.parse(localStorage.getItem('registeredUsers')) || [];
} catch (err) {
registeredUsers = [];
}
const emailVal = emailInput.value.trim();
const passVal = passwordInput.value;
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/;
if (mode === 'signup') {
// 1. Full name validation: at least two words, each at least 2 chars
const nameVal = nameInput.value.trim();
const words = nameVal ? nameVal.split(/\s+/) : [];
if (words.length < 2 || !words.every(w => w.length >= 2)) {
if (valid) nameInput.focus();
setFieldError(nameInput, errName, "Full name must contain at least two words (min 2 letters each).");
valid = false;
}
// 2. Email validation
if (!emailRegex.test(emailVal)) {
if (valid) emailInput.focus();
setFieldError(emailInput, errEmail, "Please enter a valid email address.");
valid = false;
} else {
// 3. Duplicate email check
const exists = registeredUsers.some(u => u.email.toLowerCase() === emailVal.toLowerCase());
if (exists) {
if (valid) emailInput.focus();
setFieldError(emailInput, errEmail, "This email is already registered. Please log in instead.");
valid = false;
}
}
// 4. Target Exam
if (!examInput.value) {
if (valid) examInput.focus();
setFieldError(examInput, errExam, "Please select your target exam.");
valid = false;
}
// 5. Password validation: min 7 chars AND at least one number
if (!passVal || passVal.length < 7) {
if (valid) passwordInput.focus();
setFieldError(passwordInput, errPassword, "Password must be at least 7 characters long.");
valid = false;
} else if (!/\d/.test(passVal)) {
if (valid) passwordInput.focus();
setFieldError(passwordInput, errPassword, "Password must contain at least one number.");
valid = false;
}
if (valid) {
const newUser = {
name: nameVal,
email: emailVal,
targetExam: examInput.value,
password: passVal
};
registeredUsers.push(newUser);
localStorage.setItem('registeredUsers', JSON.stringify(registeredUsers));
localStorage.setItem('edupeak_user_profile', JSON.stringify(newUser));
updateUserProfileUI(newUser);
const overlay = document.getElementById('sign-in-screen');
overlay.style.opacity = '0';
overlay.style.pointerEvents = 'none';
setTimeout(() => overlay.classList.add('hidden'), 500);
loadState();
navigateTo('dashboard');
showToast("Account registered! Welcome, " + newUser.name, "success");
signinForm.reset();
} else {
showToast("Please check validation requirements.", "warning");
}
} else {
// LOGIN MODE
if (!emailRegex.test(emailVal)) {
if (valid) emailInput.focus();
setFieldError(emailInput, errEmail, "Please enter a valid email address.");
valid = false;
} else {
const userMatch = registeredUsers.find(u => u.email.toLowerCase() === emailVal.toLowerCase());
if (!userMatch) {
if (valid) emailInput.focus();
setFieldError(emailInput, errEmail, "No account found with this email.");
valid = false;
} else if (userMatch.password !== passVal) {
if (valid) passwordInput.focus();
setFieldError(passwordInput, errPassword, "Incorrect password.");
valid = false;
} else {
// Success Login
localStorage.setItem('edupeak_user_profile', JSON.stringify(userMatch));
updateUserProfileUI(userMatch);
const overlay = document.getElementById('sign-in-screen');
overlay.style.opacity = '0';
overlay.style.pointerEvents = 'none';
setTimeout(() => overlay.classList.add('hidden'), 500);
loadState();
navigateTo('dashboard');
showToast("Welcome back, " + userMatch.name, "success");
signinForm.reset();
return;
}
}
if (!valid) {
showToast("Login failed. Please check field errors.", "warning");
}
}
});
}
// Bind Sign-Out buttons
const signOutBtn = document.getElementById('btn-sign-out');
const mobileSignOutBtn = document.getElementById('mobile-btn-sign-out');
function handleSignOut() {
if (confirm("Are you sure you want to sign out? This locks the workspace.")) {
localStorage.removeItem('edupeak_user_profile');
localStorage.removeItem('edupeak_fs_state');
initializeDefaultState();
const overlay = document.getElementById('sign-in-screen');
overlay.classList.remove('hidden');
overlay.offsetHeight; // force reflow
overlay.style.opacity = '1';
overlay.style.pointerEvents = 'auto';
showToast("Signed out. Workspace locked.", "info");
navigateTo('dashboard');
}
}
if (signOutBtn) signOutBtn.addEventListener('click', handleSignOut);
if (mobileSignOutBtn) mobileSignOutBtn.addEventListener('click', handleSignOut);
// ==========================================================================
// STATE PERSISTENCE & LOCALSTORAGE SYNC
// ==========================================================================
function loadState() {
try {
const saved = localStorage.getItem('edupeak_fs_state');
if (saved) {
appState = JSON.parse(saved);
if (!appState.progress) appState.progress = {};
if (!appState.mockTests) appState.mockTests = [];
if (!appState.studySchedule) appState.studySchedule = [];
if (!appState.scratchpad) appState.scratchpad = "";
} else {
initializeDefaultState();
}
} catch (e) {
console.error("LocalStorage load error:", e);
initializeDefaultState();
}
}
function saveState() {
try {
localStorage.setItem('edupeak_fs_state', JSON.stringify(appState));
} catch (e) {
console.error("LocalStorage save error:", e);
}
}
function initializeDefaultState() {
appState.progress = {};
appState.mockTests = [];
appState.scratchpad = "";
// Sync progress tracking flags for all nested chapters in data.js
Object.keys(window.eduPeakData).forEach(subKey => {
if (subKey === 'mentalAgility') return;
const categories = window.eduPeakData[subKey];
Object.keys(categories).forEach(catKey => {
const cat = categories[catKey];
Object.keys(cat).forEach(chKey => {
const chId = `${subKey}-${catKey}-${chKey}`;
appState.progress[chId] = { completed: false, quizScore: null };
});
});
});
// Seed initial dummy attempt
appState.mockTests = [
{
id: 101,
date: "2026-05-28",
score: 68.5,
correct: 145,
incorrect: 34,
unattempted: 21,
total: 200,
timeTaken: "02:44:12",
subjects: ["Physics", "Chemistry", "Biology", "MAT"]
}
];
saveState();
}
// ==========================================================================
// TOAST NOTIFICATIONS
// ==========================================================================
function showToast(message, type = 'info') {
const portal = document.getElementById('global-toast-portal');
if (!portal) return;
const toast = document.createElement('div');
toast.className = `toast ${type}`;
let iconClass = 'fa-circle-info';
if (type === 'success') iconClass = 'fa-circle-check';
if (type === 'warning') iconClass = 'fa-circle-exclamation';
if (type === 'danger') iconClass = 'fa-triangle-exclamation';
toast.innerHTML = `
<i class="fa-solid ${iconClass}"></i>
<span>${message}</span>
`;
portal.appendChild(toast);
setTimeout(() => {
toast.style.opacity = '0';
setTimeout(() => toast.remove(), 300);
}, 4000);
}
// ==========================================================================
// SPA ROUTING SYSTEMS
// ==========================================================================
function navigateTo(routeId) {
closeMobileDrawer();
// Reset drilldown header states
document.getElementById('drilldown-nav-header').style.display = 'none';
document.getElementById('subject-main-syllabus-container').style.display = 'block';
document.getElementById('chapter-drilldown-container').style.display = 'none';
// Highlight active nav item
const navItems = document.querySelectorAll('.nav-item');
navItems.forEach(item => {
if (item.getAttribute('data-route') === routeId) {
item.classList.add('active');
item.setAttribute('aria-current', 'page');
} else {
item.classList.remove('active');
item.removeAttribute('aria-current');
}
});
// Switch view sections
const sections = document.querySelectorAll('.view-section');
let targetSectionId = `view-${routeId}`;
if (['physics', 'chemistry', 'biology', 'mathematics'].includes(routeId)) {
targetSectionId = 'view-subject';
}
sections.forEach(sec => {
if (sec.id === targetSectionId) {
sec.classList.add('active');
} else {
sec.classList.remove('active');
}
});
// Render corresponding controllers
if (routeId === 'dashboard') {
renderDashboard();
} else if (['physics', 'chemistry', 'biology', 'mathematics'].includes(routeId)) {
renderSubjectView(routeId);
} else if (routeId === 'mock-exam') {
renderMockHistory();
}
const activeSec = document.querySelector('.view-section.active');
if (activeSec) activeSec.scrollTop = 0;
}
// Bind Sidebar items
const sidebarButtons = document.querySelectorAll('.nav-item');
sidebarButtons.forEach(btn => {
btn.addEventListener('click', () => {
const target = btn.getAttribute('data-route');
navigateTo(target);
});
});
// Mobile navigation drawer
const hamburgerBtn = document.getElementById('hamburger-menu-btn');
const drawerCloseBtn = document.getElementById('drawer-close-btn');
const drawerOverlay = document.getElementById('drawer-overlay');
function openMobileDrawer() {
drawerOverlay.classList.add('active');
hamburgerBtn.setAttribute('aria-expanded', 'true');
}
function closeMobileDrawer() {
drawerOverlay.classList.remove('active');
hamburgerBtn.setAttribute('aria-expanded', 'false');
}
hamburgerBtn.addEventListener('click', openMobileDrawer);
drawerCloseBtn.addEventListener('click', closeMobileDrawer);
drawerOverlay.addEventListener('click', (e) => {
if (e.target === drawerOverlay) closeMobileDrawer();
});
// ==========================================================================
// HOME / DASHBOARD SCREEN BUILDER
// ==========================================================================
function renderDashboard() {
updateDashboardStats();
renderDashboardSubjectProgress();
renderDailySchedulerList();
}
function updateDashboardStats() {
let totalChapters = 0;
let completedChapters = 0;
let quizScoreSum = 0;
let quizScoreCount = 0;
Object.keys(appState.progress).forEach(chId => {
totalChapters++;
const p = appState.progress[chId];
if (p.completed) {
completedChapters++;
}
if (p.quizScore !== null) {
quizScoreSum += p.quizScore;
quizScoreCount++;
}
});
const overallPercent = totalChapters > 0 ? Math.round((completedChapters / totalChapters) * 100) : 0;
const averageQuiz = quizScoreCount > 0 ? Math.round(quizScoreSum / quizScoreCount) : 0;
const totalMocks = appState.mockTests ? appState.mockTests.length : 0;
document.getElementById('stat-total-progress').textContent = `${overallPercent}%`;
document.getElementById('stat-chapters-done').textContent = `${completedChapters}/${totalChapters}`;
document.getElementById('stat-avg-score').textContent = `${averageQuiz}%`;
document.getElementById('stat-exams-taken').textContent = totalMocks;
}
function renderDashboardSubjectProgress() {
const container = document.getElementById('subject-wheel-container');
if (!container) return;
container.innerHTML = '';
const subjects = [
{ key: 'physics', name: 'Physics', icon: 'fa-atom', color: '#06b6d4', desc: 'Mechanics, Electromagnetism, Waves & Modern Physics.' },
{ key: 'chemistry', name: 'Chemistry', icon: 'fa-flask', color: '#ec4899', desc: 'Physical, Organic, & Inorganic syllabus segments.' },
{ key: 'biology', name: 'Biology', icon: 'fa-leaf', color: '#10b981', desc: 'MEC CEE botany and zoology structural divisions.' },
{ key: 'mathematics', name: 'Mathematics', icon: 'fa-calculator', color: '#f59e0b', desc: 'Advanced algebraic and calculus concept maps.' }
];
subjects.forEach(sub => {
const subData = window.eduPeakData[sub.key];
let subChapters = 0;
let subDone = 0;
Object.keys(subData).forEach(catKey => {
const cat = subData[catKey];
Object.keys(cat).forEach(chKey => {
subChapters++;
const chId = `${sub.key}-${catKey}-${chKey}`;
if (appState.progress[chId] && appState.progress[chId].completed) {
subDone++;
}
});
});
const percent = subChapters > 0 ? Math.round((subDone / subChapters) * 100) : 0;
const circumference = 2 * Math.PI * 25; // 157
const strokeOffset = circumference - (circumference * percent) / 100;
const card = document.createElement('div');
card.className = 'sub-progress-card cursor-pointer';
card.setAttribute('data-subject', sub.key);
card.style.borderLeft = `4px solid ${sub.color}`;
card.setAttribute('role', 'button');
card.setAttribute('aria-label', `Study ${sub.name}. Progress is ${percent}% completed.`);
card.innerHTML = `
<div class="flex flex-col gap-2 max-w-[70%]">
<span class="text-lg font-black text-white flex items-center gap-2.5 font-heading">
<i class="fa-solid ${sub.icon}" style="color: ${sub.color};"></i> ${sub.name}
</span>
<span class="text-xs text-gray-400 font-semibold leading-relaxed">${sub.desc}</span>
<span class="text-xs text-gray-300 font-bold flex items-center gap-1 mt-1">
<span class="w-1.5 h-1.5 rounded-full" style="background: ${sub.color};"></span>
${subDone} of ${subChapters} Chapters Mastered
</span>
</div>
<div class="progress-circle-wrapper flex-shrink-0" aria-hidden="true">
<svg class="progress-circle-svg" viewBox="0 0 60 60">
<circle class="progress-circle-bg" cx="30" cy="30" r="25" />
<circle class="progress-circle-bar" cx="30" cy="30" r="25"
stroke="${sub.color}"
style="stroke-dashoffset: ${strokeOffset};" />
</svg>
<div class="progress-circle-text font-black" style="color: ${sub.color};">${percent}%</div>
</div>
`;
card.addEventListener('click', () => navigateTo(sub.key));
container.appendChild(card);
});
}
// Dashboard quick exam trigger
document.getElementById('btn-quick-mock-launch').addEventListener('click', () => {
navigateTo('mock-exam');
});
// ==========================================================================
// DAILY TIMELINE FOCUS SCHEDULER
// ==========================================================================
const schedBtn = document.getElementById('btn-generate-schedule');
if (schedBtn) {
schedBtn.addEventListener('click', buildDailySchedule);
}
function buildDailySchedule() {
const focus = document.getElementById('sched-select-focus').value;
appState.studySchedule = [];
const slots = [
{ id: 1, time: "07:30 AM - 09:30 AM", label: "Session 1: Detailed Notes study" },
{ id: 2, time: "11:00 AM - 01:00 PM", label: "Session 2: Formula & Equation revision" },
{ id: 3, time: "03:30 PM - 05:30 PM", label: "Session 3: 30-Question Chapter Quiz" },
{ id: 4, time: "07:30 PM - 09:30 PM", label: "Session 4: CEE Mock Exam simulation" }
];
const keys = ['physics', 'chemistry', 'biology', 'mathematics'];
slots.forEach((slot, index) => {
let subKey = focus;
if (focus === 'all') {
subKey = keys[index % keys.length];
}
const subData = window.eduPeakData[subKey];
const catKeys = Object.keys(subData);
const randCatKey = catKeys[Math.floor(Math.random() * catKeys.length)];
const cat = subData[randCatKey];
const chKeys = Object.keys(cat);
const randChKey = chKeys[Math.floor(Math.random() * chKeys.length)];
const chapter = cat[randChKey];
let action = "";
if (index === 0) {
action = `Analyze 150+ word notes and visual diagrams for: ${chapter.name}`;
} else if (index === 1) {
action = `Practice centered equations and formulas for: ${chapter.name}`;
} else if (index === 2) {
action = `Complete 30-question interactive timer quiz for: ${chapter.name}`;
} else {
action = `Perform timed 200 MCQ Mock Exam segment involving ${subKey.toUpperCase()}`;
}
appState.studySchedule.push({
id: slot.id,
time: slot.time,
task: action,
subject: subKey,
done: false
});
});
saveState();
renderDailySchedulerList();
showToast("Today's focus revision timetable compiled!", "success");
}
function renderDailySchedulerList() {
const listContainer = document.getElementById('planner-schedule-list');
if (!listContainer) return;
listContainer.innerHTML = '';
if (!appState.studySchedule || appState.studySchedule.length === 0) {
listContainer.innerHTML = `
<div class="text-center py-6 text-gray-500 text-sm">
<i class="fa-solid fa-calendar-plus text-2xl mb-2 text-gray-600 block"></i>
<span>No revision schedule compiled. Select focus to compile.</span>
</div>
`;
return;
}
const subColors = {
physics: '#06b6d4',
chemistry: '#ec4899',
biology: '#10b981',
mathematics: '#f59e0b'
};
appState.studySchedule.forEach(slot => {
const color = subColors[slot.subject] || '#874dff';
const row = document.createElement('div');
row.className = `schedule-row border-l-[4px] ${slot.done ? 'active' : ''}`;
row.style.borderLeftColor = color;
row.innerHTML = `
<label class="checkbox-container select-none cursor-pointer" aria-label="Mark task done">
<input type="checkbox" ${slot.done ? 'checked' : ''} data-slot-id="${slot.id}">
<div class="checkbox-custom" style="border-radius: 50%;">
<i class="fa-solid fa-check"></i>
</div>
</label>
<div class="flex-grow flex flex-col ${slot.done ? 'line-through opacity-50' : 'opacity-100'} transition-all">
<span class="text-xs font-extrabold ${slot.done ? 'text-gray-500' : 'text-gray-200'} leading-tight">${slot.task}</span>
<span class="text-[0.68rem] text-gray-500 font-semibold mt-1 flex items-center gap-1">
<i class="fa-regular fa-clock"></i> ${slot.time}
</span>
</div>
`;
const checkInput = row.querySelector('input');
checkInput.addEventListener('change', (e) => {
slot.done = e.target.checked;
saveState();
renderDailySchedulerList();
updateDashboardStats();
});
listContainer.appendChild(row);
});
}
// ==========================================================================
// SUBJECT VIEW RENDERER (CATEGORY-DIVIDED MAPPING)
// ==========================================================================
function renderSubjectView(subjectKey) {
const container = document.getElementById('subject-main-syllabus-container');
if (!container) return;
container.innerHTML = '';
const subData = window.eduPeakData[subjectKey];
if (!subData) return;
const subColors = {
physics: { color: '#06b6d4', icon: 'fa-atom', bgGlow: 'rgba(6, 182, 212, 0.12)' },
chemistry: { color: '#ec4899', icon: 'fa-flask', bgGlow: 'rgba(236, 72, 153, 0.12)' },
biology: { color: '#10b981', icon: 'fa-leaf', bgGlow: 'rgba(16, 185, 129, 0.12)' },
mathematics: { color: '#f59e0b', icon: 'fa-calculator', bgGlow: 'rgba(245, 158, 11, 0.12)' }
};
const cMeta = subColors[subjectKey];
// Subject Banner
const banner = document.createElement('div');
banner.className = 'subject-header-banner p-6 md:p-8 rounded-3xl flex items-center gap-6';
banner.style.background = `linear-gradient(135deg, ${cMeta.bgGlow} 0%, rgba(9, 13, 22, 0.4) 100%)`;
banner.style.borderColor = cMeta.color.replace(')', ', 0.15)');
const subNameFormatted = subjectKey.charAt(0).toUpperCase() + subjectKey.slice(1);
banner.innerHTML = `
<div class="subject-header-icon w-16 h-16 rounded-2xl flex items-center justify-center text-2xl text-white flex-shrink-0" style="background: ${cMeta.color}; box-shadow: 0 0 20px ${cMeta.color}40;">
<i class="fa-solid ${cMeta.icon}"></i>
</div>
<div class="subject-header-details">
<h1 class="text-2xl md:text-3.5xl font-extrabold tracking-tight font-heading text-white">${subNameFormatted} Syllabus</h1>
<p class="text-xs md:text-sm text-gray-400">Natively mapping all CEE/NEET Platform - Custom Visual Enhancement Styles categories.</p>
</div>
`;
container.appendChild(banner);
// Subject Progress Box
let chCount = 0;
let chDone = 0;
Object.keys(subData).forEach(catKey => {
const cat = subData[catKey];
Object.keys(cat).forEach(chKey => {
chCount++;
const chId = `${subjectKey}-${catKey}-${chKey}`;
if (appState.progress[chId] && appState.progress[chId].completed) {
chDone++;
}
});
});
const subPercent = chCount > 0 ? Math.round((chDone / chCount) * 100) : 0;
const progressBox = document.createElement('div');
progressBox.className = 'glass-card p-5';
progressBox.innerHTML = `
<div class="flex justify-between items-center mb-2.5 font-extrabold text-xs md:text-sm">
<span>Syllabus Coverage</span>
<span style="color: ${cMeta.color};">${subPercent}% Mastered (${chDone}/${chCount} Chapters)</span>
</div>
<div class="quiz-progress-bar-bg" style="margin: 0; height: 8px;">
<div class="quiz-progress-bar-filled" style="width: ${subPercent}%; background: ${cMeta.color};"></div>
</div>
`;
container.appendChild(progressBox);
// Render Chapters grouped by category
const categoriesSection = document.createElement('section');
categoriesSection.className = 'space-y-8';
Object.keys(subData).forEach(catKey => {
const cat = subData[catKey];
const catName = categoryNames[catKey] || catKey;
const catBox = document.createElement('div');
catBox.className = 'space-y-4';
catBox.innerHTML = `
<h3 class="text-base font-black text-gray-300 uppercase tracking-wider flex items-center gap-2 border-l-[3px] pl-3" style="border-left-color: ${cMeta.color};">
<span>${catName}</span>
</h3>
`;
const chaptersGrid = document.createElement('div');
chaptersGrid.className = 'grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6';
Object.keys(cat).forEach(chKey => {
const chapter = cat[chKey];
const chId = `${subjectKey}-${catKey}-${chKey}`;
const chProgress = appState.progress[chId] || { completed: false, quizScore: null };
let tagHTML = "";
const sampleTopics = chapter.formulas.slice(0, 2);
sampleTopics.forEach(t => {
tagHTML += `<span class="topic-tag text-[0.62rem] font-bold border border-white/5 py-1 px-2.5 rounded-full bg-white/2 truncate max-w-[130px] inline-block">${t}</span>`;
});
let scoreBadge = "";
if (chProgress.quizScore !== null) {
const bg = chProgress.quizScore >= 80 ? 'badge-success' : (chProgress.quizScore >= 45 ? 'badge-warning' : 'badge-danger');
scoreBadge = `<span class="badge ${bg} text-[0.65rem] py-0.5 px-2">Quiz: ${chProgress.quizScore}%</span>`;
}
const card = document.createElement('article');
card.className = 'chapter-card p-6 flex flex-col justify-between gap-5 cursor-pointer';
card.setAttribute('data-subject', subjectKey);
card.innerHTML = `
<div class="flex justify-between items-start gap-2">
<div class="space-y-1.5 flex-grow">
<span class="badge badge-info text-[0.62rem] py-0.5 px-2.5 font-bold uppercase tracking-wider">Chapter</span>
<h4 class="text-base md:text-lg font-black leading-snug text-white font-heading min-h-[2.8rem] line-clamp-2">${chapter.name}</h4>
</div>
${chProgress.completed ? `<i class="fa-solid fa-circle-check text-brand-success text-lg flex-shrink-0 mt-1"></i>` : ''}
</div>
<div class="flex flex-wrap gap-1.5 min-h-[32px] items-center">
${tagHTML}
</div>
<div class="flex justify-between items-center border-t border-white/5 pt-4 mt-auto gap-2">
<label class="checkbox-container cursor-pointer select-none text-xs font-extrabold min-h-[36px] flex items-center">
<input type="checkbox" ${chProgress.completed ? 'checked' : ''} data-chapter-id="${chId}">
<div class="checkbox-custom">
<i class="fa-solid fa-check"></i>
</div>
<span>Mastered</span>
</label>
<div class="flex items-center gap-2">
${scoreBadge}
<button class="btn-card-launch bg-[#161c2a] border border-white/10 hover:bg-brand-primary text-xs font-black py-2 px-3.5 rounded-xl flex items-center gap-1.5 text-white transition-all btn-study-chapter min-h-[38px]">
Study <i class="fa-solid fa-angle-right"></i>
</button>
</div>
</div>
`;
// Checkbox Mastered toggle
const checkInput = card.querySelector('input[type="checkbox"]');
checkInput.addEventListener('change', (e) => {
const checked = e.target.checked;
if (!appState.progress[chId]) appState.progress[chId] = { completed: false, quizScore: null };
appState.progress[chId].completed = checked;
saveState();
renderSubjectView(subjectKey);
updateDashboardStats();
showToast(`Chapter "${chapter.name}" marked as ${checked ? 'completed' : 'incomplete'}.`, "info");
});
// Study launch
const studyBtn = card.querySelector('.btn-study-chapter');
studyBtn.addEventListener('click', () => {
openThreePanelChapter(subjectKey, catKey, chKey);
});
chaptersGrid.appendChild(card);
});
catBox.appendChild(chaptersGrid);
categoriesSection.appendChild(catBox);
});
container.appendChild(categoriesSection);
}
// ==========================================================================
// DYNAMIC THREE-PANEL CONCEPT HUB NOTES GENERATOR
// ==========================================================================
function generateChapterNotes(subjectKey, categoryKey, chapterKey) {
const subject = subjectKey.charAt(0).toUpperCase() + subjectKey.slice(1);
const category = categoryNames[categoryKey] || categoryKey;
const chapter = window.eduPeakData[subjectKey]?.[categoryKey]?.[chapterKey];
if (!chapter) return '';
if (chapter.notes) {
return `
<div class="space-y-4">
<h4 class="text-sm font-bold text-white uppercase tracking-wider border-b border-white/5 pb-2 flex items-center gap-2">
<span class="w-2 h-2 rounded-full bg-brand-info"></span> 1. Theoretical Foundation
</h4>
<p class="text-xs md:text-sm text-gray-300 leading-relaxed font-normal">
${chapter.notes.theoretical}
</p>
<h4 class="text-sm font-bold text-white uppercase tracking-wider border-b border-white/5 pb-2 flex items-center gap-2">
<span class="w-2 h-2 rounded-full bg-brand-primary"></span> 2. Key Framework & Derivations
</h4>
<p class="text-xs md:text-sm text-gray-300 leading-relaxed font-normal">
${chapter.notes.framework}
</p>
<h4 class="text-sm font-bold text-white uppercase tracking-wider border-b border-white/5 pb-2 flex items-center gap-2">
<span class="w-2 h-2 rounded-full bg-brand-warning"></span> 3. MEC Exam Strategy & Common Traps
</h4>
<p class="text-xs md:text-sm text-gray-300 leading-relaxed font-normal">
${chapter.notes.strategy}
</p>
</div>
`;
}
const name = chapter.name;
const formulas = chapter.formulas;
let formulasExplanation = "";
if (formulas && formulas.length > 0) {
formulasExplanation = ` Core governing relationship: <b>${formulas[0]}</b>. Secondary analytical relation: <b>${formulas[1] || formulas[0]}</b>.`;
}
return `
<div class="space-y-4">
<h4 class="text-sm font-bold text-white uppercase tracking-wider border-b border-white/5 pb-2">1. Theoretical Foundation</h4>
<p class="text-xs md:text-sm text-gray-300 leading-relaxed">
${name} is a key topic in CEE ${subject} (${category}). Focus on fundamental definitions, microscopic models, and system properties.
</p>
<h4 class="text-sm font-bold text-white uppercase tracking-wider border-b border-white/5 pb-2">2. Key Framework & Derivations</h4>
<p class="text-xs md:text-sm text-gray-300 leading-relaxed">
${formulasExplanation} Maintain SI units, sign conventions, and dimensional consistency across multi-step calculations.
</p>
<h4 class="text-sm font-bold text-white uppercase tracking-wider border-b border-white/5 pb-2">3. MEC Exam Strategy & Common Traps</h4>
<p class="text-xs md:text-sm text-gray-300 leading-relaxed">
Verify unit prefixes (micro/nano) and watch out for CEE -0.25 negative marking on speculative numerical guesses.
</p>
</div>