-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteacher-dashboard.html
More file actions
963 lines (887 loc) · 52.2 KB
/
teacher-dashboard.html
File metadata and controls
963 lines (887 loc) · 52.2 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Teacher dashboard for MGIT Feedback System — view student feedback and analytics for your subjects." />
<meta name="keywords" content="feedback, students, teachers, MGIT" />
<meta property="og:title" content="Teacher Dashboard — MGIT Feedback System" />
<meta property="og:description" content="Teacher dashboard for MGIT Feedback System." />
<meta property="og:url" content="https://mgitfeedback.me/teacher-dashboard.html" />
<meta property="og:type" content="website" />
<link rel="canonical" href="https://mgitfeedback.me/teacher-dashboard.html" />
<title>Teacher Dashboard — Feedback System</title>
<link rel="icon" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>👨🏫</text></svg>" />
<!-- Preconnect for Google Fonts (reduces FCP) -->
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<!-- Preload main stylesheet (reduces render-blocking) -->
<link rel="preload" href="css/style.css?v=2" as="style" />
<link rel="stylesheet" href="css/style.css?v=2" />
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js">
function showToast(msg, type) {
const t = document.createElement('div');
t.style.cssText = 'position:fixed;bottom:20px;right:20px;padding:12px 20px;border-radius:10px;color:#fff;font-size:14px;z-index:9999;animation:fadeIn 0.3s;';
t.style.background = type === 'success' ? '#22c55e' : type === 'error' ? '#dc2626' : '#92400e';
t.textContent = msg;
document.body.appendChild(t);
setTimeout(() => t.remove(), 3000);
}
</script>
</head>
<body>
<div class="bg-orbs"></div>
<button class="mobile-menu-btn" onclick="document.querySelector('.sidebar').classList.toggle('open');document.querySelector('.sidebar-overlay').classList.toggle('show');" aria-label="Menu">☰</button>
<div class="page-wrapper dashboard-layout">
<div class="sidebar-overlay" onclick="document.querySelector('.sidebar').classList.remove('open');this.classList.remove('show');"></div>
<nav class="sidebar">
<div class="sidebar-header">
<div class="sidebar-logo">SF</div>
<div>
<div class="sidebar-title">Feedback System</div>
<div class="sidebar-subtitle" id="collegeName">Portal</div>
</div>
</div>
<div class="sidebar-nav">
<div class="nav-group-label">My Dashboard</div>
<div class="nav-item active" onclick="showSection('overview')"><span class="nav-icon">📊</span> Overview</div>
<div class="nav-item" onclick="showSection('comments')"><span class="nav-icon">💬</span> Student Comments</div>
<div class="nav-item" onclick="showSection('breakdown')"><span class="nav-icon">📋</span> Score Breakdown</div>
<div class="nav-group-label" style="margin-top:16px;">Analytics</div>
<div class="nav-item" onclick="showSection('department')"><span class="nav-icon">🏛</span> Department Feedback</div>
<div class="nav-item" onclick="showSection('sections')"><span class="nav-icon">📛</span> Section-wise Feedback</div>
<div class="nav-group-label" style="margin-top:16px;">Account</div>
<div class="nav-item" onclick="showSection('profile')"><span class="nav-icon">👤</span> My Profile</div>
</div>
<div class="sidebar-footer">
<div class="user-avatar" id="sidebarAvatar">T</div>
<div class="user-info">
<div class="user-name" id="sidebarName">Teacher</div>
<div class="user-role" id="sidebarSubject">Teacher</div>
<div id="sidebarDeptSection" style="font-size:10px;color:rgba(255,255,255,0.5);margin-top:2px;"></div>
</div>
<button class="btn-logout" onclick="logout()" title="Logout" aria-label="Logout">⬡</button>
</div>
</nav>
<main class="main-content">
<!-- Profile Section -->
<div id="sectionProfile" style="display:none;">
<div class="topbar">
<div>
<div class="breadcrumb">Teacher Dashboard › <span>My Profile</span></div>
<div class="page-title">👤 Teacher Profile</div>
<div class="page-subtitle">Your personal and academic information</div>
</div>
</div>
<div id="profileContent"></div>
</div>
<!-- Overview -->
<div id="sectionOverview">
<div class="topbar">
<div>
<div class="breadcrumb">Teacher Dashboard › <span>Overview</span></div>
<div class="page-title" id="welcomeTitle">My Feedback Dashboard</div>
<div class="page-subtitle" id="subjectBadgeWrap"></div>
</div>
<button class="btn btn-secondary btn-sm" onclick="downloadReport()">📊 Download Report</button>
</div>
<div id="noDataMsg" class="empty-state" style="display:none;">
<div class="empty-icon">📭</div>
<div class="empty-title">No Feedback Yet</div>
<div class="empty-desc">No students have submitted feedback yet. Results will appear here once submissions come in.</div>
</div>
<div id="dashboardData">
<!-- Performance Alert Banner -->
<div id="improvementWarning" style="display:none; margin-bottom:24px;">
<div style="
background: linear-gradient(135deg, rgba(239,68,68,0.12) 0%, rgba(220,38,38,0.05) 100%);
border: 1.5px solid rgba(239,68,68,0.35);
border-radius: 16px;
padding: 0;
overflow: hidden;
box-shadow: 0 4px 24px rgba(239,68,68,0.12);
animation: warnPulse 3s ease-in-out infinite;
">
<!-- Top stripe -->
<div style="height:4px; background:linear-gradient(90deg,#ef4444,#f97316,#ef4444); background-size:200% 100%; animation: shiftGrad 2s linear infinite;"></div>
<div style="padding:20px 24px;">
<div style="display:flex; align-items:flex-start; gap:18px; flex-wrap:wrap;">
<!-- Icon -->
<div style="
width:52px; height:52px; border-radius:14px; flex-shrink:0;
background:linear-gradient(135deg,#ef4444,#dc2626);
display:flex; align-items:center; justify-content:center;
font-size:22px; box-shadow:0 4px 12px rgba(239,68,68,0.4);
">⚠️</div>
<!-- Text -->
<div style="flex:1; min-width:220px;">
<div style="display:flex; align-items:center; gap:10px; margin-bottom:6px; flex-wrap:wrap;">
<span style="font-weight:800; font-size:16px; color:#f87171; letter-spacing:0.3px;">Improvement Required</span>
<span id="thresholdBadge" style="font-size:11px; font-weight:700; padding:3px 10px; border-radius:20px; background:rgba(239,68,68,0.15); color:#f87171; border:1px solid rgba(239,68,68,0.3);">Below Target</span>
</div>
<p style="font-size:13px; color:var(--text-sub); line-height:1.6; margin:0 0 14px;">
Your current average score is <strong id="warnScoreText" style="color:#f87171;"></strong> — below the institution's minimum of <strong id="warnThreshText" style="color:var(--warning);"></strong>. Focus on your lowest-rated categories to improve.
</p>
<!-- Gap progress bar -->
<div style="margin-bottom:14px;">
<div style="display:flex; justify-content:space-between; margin-bottom:5px; font-size:11px; color:var(--text-muted);">
<span>Your Score</span><span>Minimum Target</span>
</div>
<div style="height:8px; border-radius:6px; background:rgba(255,255,255,0.05); overflow:hidden; position:relative;">
<div id="warnProgressBar" style="height:100%; border-radius:6px; background:linear-gradient(90deg,#ef4444,#f97316); transition:width 0.8s ease;"></div>
<div id="warnTargetLine" style="position:absolute; top:0; bottom:0; width:2px; background:rgba(251,191,36,0.8);"></div>
</div>
</div>
<!-- Tips -->
<div style="display:flex; gap:8px; flex-wrap:wrap;">
<span style="font-size:11px; padding:4px 10px; border-radius:20px; background:rgba(239,68,68,0.1); color:#fca5a5; border:1px solid rgba(239,68,68,0.2);">📋 Review Score Breakdown</span>
<span style="font-size:11px; padding:4px 10px; border-radius:20px; background:rgba(239,68,68,0.1); color:#fca5a5; border:1px solid rgba(239,68,68,0.2);">💬 Read Student Comments</span>
<span style="font-size:11px; padding:4px 10px; border-radius:20px; background:rgba(239,68,68,0.1); color:#fca5a5; border:1px solid rgba(239,68,68,0.2);">👤 Meet with HOD</span>
</div>
</div>
</div>
</div>
</div>
</div>
<style>
@keyframes warnPulse { 0%,100%{box-shadow:0 4px 24px rgba(239,68,68,0.12)} 50%{box-shadow:0 4px 32px rgba(239,68,68,0.25)} }
@keyframes shiftGrad { 0%{background-position:200% 0} 100%{background-position:-200% 0} }
</style>
<div class="stats-grid animate-in">
<div class="stat-card"><div class="stat-icon">📨</div><div class="stat-value" id="statResponses">0</div><div class="stat-label">Total Responses</div></div>
<div class="stat-card"><div class="stat-icon">⭐</div><div class="stat-value" id="statAvg">—</div><div class="stat-label">Overall Average</div></div>
<div class="stat-card"><div class="stat-icon">🏆</div><div class="stat-value" id="statBest">—</div><div class="stat-label">Best Category</div></div>
<div class="stat-card"><div class="stat-icon">📈</div><div class="stat-value" id="statTrend">—</div><div class="stat-label">Latest Trend</div></div>
</div>
<div class="charts-grid animate-in delay-1">
<!-- Row 1: Radar + Doughnut -->
<div class="chart-card">
<div class="chart-title">📡 Category Performance Radar</div>
<div style="font-size:11px;color:var(--text-muted);margin-bottom:10px;">How you score across each evaluation area</div>
<div class="chart-canvas-wrap"><canvas id="radarChart"></canvas></div>
</div>
<div class="chart-card">
<div class="chart-title">🍩 Score Distribution</div>
<div style="font-size:11px;color:var(--text-muted);margin-bottom:10px;">How many students rated 1–5 overall</div>
<div class="chart-canvas-wrap"><canvas id="doughnutChart"></canvas></div>
</div>
<!-- Row 2: Polar Area + Bar -->
<div class="chart-card">
<div class="chart-title">📍 Polar: Category Comparison</div>
<div style="font-size:11px;color:var(--text-muted);margin-bottom:10px;">Relative strength of each feedback category</div>
<div class="chart-canvas-wrap"><canvas id="polarChart"></canvas></div>
</div>
<div class="chart-card">
<div class="chart-title">📊 Rating Distribution by Category</div>
<div style="font-size:11px;color:var(--text-muted);margin-bottom:10px;">Average feedback score per category</div>
<div class="chart-canvas-wrap"><canvas id="barChart"></canvas></div>
</div>
<!-- Row 3: Full-width trend -->
<div class="chart-card" style="grid-column: 1 / -1;">
<div class="chart-title">📈 Average Score Trend Over Time</div>
<div style="font-size:11px;color:var(--text-muted);margin-bottom:10px;">Track whether your scores are improving per submission</div>
<div class="chart-canvas-wrap"><canvas id="trendChart"></canvas></div>
</div>
</div>
</div>
</div>
<!-- Comments -->
<div id="sectionComments" style="display:none;">
<div class="topbar">
<div>
<div class="breadcrumb">Teacher Dashboard › <span>Comments</span></div>
<div class="page-title">Student Feedback Comments</div>
<div class="page-subtitle">All qualitative feedback — identities protected per anonymity settings</div>
</div>
</div>
<div id="commentsList"></div>
<div id="noComments" class="empty-state" style="display:none;">
<div class="empty-icon">💬</div>
<div class="empty-title">No Comments Yet</div>
<div class="empty-desc">Students haven't added open-ended comments yet.</div>
</div>
</div>
<!-- Breakdown -->
<div id="sectionBreakdown" style="display:none;">
<div class="topbar">
<div>
<div class="breadcrumb">Teacher Dashboard › <span>Score Breakdown</span></div>
<div class="page-title">Section-wise Score Breakdown</div>
<div class="page-subtitle">Average scores per evaluation category</div>
</div>
</div>
<div id="breakdownList"></div>
</div>
<!-- Department Feedback -->
<div id="sectionDepartment" style="display:none;">
<div class="topbar">
<div>
<div class="breadcrumb">Teacher Dashboard › <span>Department Feedback</span></div>
<div class="page-title">🏛 Department-wide Analysis</div>
<div class="page-subtitle" id="deptFeedbackSubtitle">Comparison of all teachers in your department</div>
</div>
</div>
<div id="deptFeedbackContent"></div>
</div>
<!-- Section-wise Feedback -->
<div id="sectionSections" style="display:none;">
<div class="topbar">
<div>
<div class="breadcrumb">Teacher Dashboard › <span>Section-wise Feedback</span></div>
<div class="page-title">📛 Section-wise Score Analysis</div>
<div class="page-subtitle">Feedback breakdown from each student section</div>
</div>
</div>
<div id="sectionFeedbackContent"></div>
</div>
</div>
<div class="toast-container" id="toastContainer"></div>
<script src="js/demo-isolator.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.14.1/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.14.1/firebase-firestore-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/10.14.1/firebase-auth-compat.js"></script>
<script src="js/firebase-config.js"></script>
<script src="js/data.js"></script>
<script src="js/auth.js"></script>
<script src="js/charts.js"></script>
<script src="js/firebase-sync.js"></script>
<script>
fbInit();
const session = requireAuth('teacher');
startSessionListener();
const teacher = getUserById(session.userId);
const subject = teacher ? getSubjectById(teacher.subjectId) : null;
const stats = getTeacherStats(session.userId);
document.getElementById('sidebarAvatar').textContent = session.name.charAt(0).toUpperCase();
document.getElementById('sidebarName').textContent = session.name;
document.getElementById('sidebarSubject').textContent = subject ? subject.name : 'Teacher';
document.getElementById('collegeName').textContent = getSettings().collegeName;
document.getElementById('welcomeTitle').textContent = 'Welcome, ' + session.name.split(' ')[0];
// Set subject badge in topbar (with dept + section)
if (teacher) {
let badgeHtml = subject ? `<span class="badge badge-purple">📚 ${subject.name}</span>` : '';
if (teacher.department) badgeHtml += ` <span class="badge badge-blue">🏛 ${teacher.department}</span>`;
if (teacher.section) badgeHtml += ` <span class="badge badge-purple" style="font-size:11px;">📛 ${teacher.section}</span>`;
document.getElementById('subjectBadgeWrap').innerHTML = badgeHtml;
}
const deptSection = teacher ? (teacher.section ? `${teacher.department || ''} · ${teacher.section}` : (teacher.department || '')) : '';
if (deptSection) document.getElementById('sidebarDeptSection').textContent = deptSection;
const ALL_SECTIONS = ['overview','comments','breakdown','department','sections','profile'];
function showSection(sec, skipHistory) {
ALL_SECTIONS.forEach(s => {
document.getElementById('section' + s.charAt(0).toUpperCase() + s.slice(1)).style.display = s === sec ? '' : 'none';
});
document.querySelectorAll('.nav-item').forEach(el => {
const m = el.getAttribute('onclick') && el.getAttribute('onclick').match(/'([^']+)'/);
if (m) el.classList.toggle('active', m[1] === sec);
});
if (sec === 'comments') renderComments();
if (sec === 'breakdown') renderBreakdown();
if (sec === 'department') renderDeptFeedback();
if (sec === 'sections') renderSectionFeedback();
if (sec === 'profile') renderProfile();
// Close sidebar on mobile
document.querySelector('.sidebar').classList.remove('open');
document.querySelector('.sidebar-overlay').classList.remove('show');
// Push browser history so back button works
if (!skipHistory) history.pushState({section: sec}, '', '#' + sec);
}
// Handle browser back button
window.addEventListener('popstate', function(e) {
if (e.state && e.state.section) showSection(e.state.section, true);
});
// Set initial history state
history.replaceState({section: 'overview'}, '', '#overview');
if (!stats) {
document.getElementById('noDataMsg').style.display = '';
document.getElementById('dashboardData').style.display = 'none';
} else {
const threshold = getSettings().minThreshold || 3.5;
const isUnder = stats.overallAvg < threshold;
if (isUnder) {
document.getElementById('improvementWarning').style.display = 'block';
document.getElementById('warnScoreText').textContent = stats.overallAvg + '/5';
document.getElementById('warnThreshText').textContent = threshold + '/5';
// Progress bar: your score as % of 5, target line as % of 5
const scorePct = (stats.overallAvg / 5 * 100).toFixed(1);
const threshPct = (threshold / 5 * 100).toFixed(1);
document.getElementById('warnProgressBar').style.width = scorePct + '%';
document.getElementById('warnTargetLine').style.left = threshPct + '%';
}
document.getElementById('statResponses').textContent = stats.totalResponses;
const avgEl = document.getElementById('statAvg');
avgEl.textContent = stats.overallAvg + '/5';
if (isUnder) avgEl.style.color = 'var(--danger)';
const bestCat = Object.entries(stats.sectionAverages).sort((a, b) => b[1] - a[1])[0];
document.getElementById('statBest').textContent = bestCat ? bestCat[1] + '/5' : '—';
const trendLast = stats.trendData.length ? stats.trendData[stats.trendData.length - 1].avg : null;
document.getElementById('statTrend').textContent = trendLast ? trendLast + '/5' : '—';
setTimeout(() => {
renderRadar('radarChart', session.userId);
renderBar('barChart', session.userId);
renderTrend('trendChart', session.userId);
renderDoughnutChart();
renderPolarChart();
}, 100);
}
// ─── New Chart: Doughnut (Score Distribution 1-5) ───────────────────────
function renderDoughnutChart() {
if (!stats) return;
const responses = getResponsesForTeacher(session.userId);
const freq = {1:0,2:0,3:0,4:0,5:0};
responses.forEach(r => Object.values(r.scores||{}).flat().forEach(v => { if (freq[v]!==undefined) freq[v]++; }));
const ctx = document.getElementById('doughnutChart').getContext('2d');
new Chart(ctx, {
type: 'doughnut',
data: {
labels: ['⭐ 1 - Poor','⭐⭐ 2 - Fair','⭐⭐⭐ 3 - Good','⭐⭐⭐⭐ 4 - Very Good','⭐⭐⭐⭐⭐ 5 - Excellent'],
datasets: [{
data: Object.values(freq),
backgroundColor: ['rgba(239,68,68,0.8)','rgba(249,115,22,0.8)','rgba(234,179,8,0.8)','rgba(34,197,94,0.8)','rgba(146,64,14,0.8)'],
borderColor: 'rgba(0,0,0,0.2)',
borderWidth: 2,
hoverOffset: 8,
}]
},
options: {
responsive: true, maintainAspectRatio: true,
plugins: {
legend: { position:'bottom', labels: { color:'rgba(255,255,255,0.7)', font:{size:10}, padding:10 } },
tooltip: { callbacks: { label: ctx => ` ${ctx.parsed} ratings` } }
},
cutout: '60%',
}
});
}
// ─── New Chart: Polar Area (Category Strengths) ──────────────────────────
function renderPolarChart() {
if (!stats) return;
const entries = Object.entries(stats.sectionAverages);
const ctx = document.getElementById('polarChart').getContext('2d');
new Chart(ctx, {
type: 'polarArea',
data: {
labels: entries.map(([k]) => k),
datasets: [{
data: entries.map(([,v]) => v),
backgroundColor: entries.map((_, i) => `hsla(${i * 60 + 200},80%,65%,0.6)`),
borderColor: entries.map((_, i) => `hsla(${i * 60 + 200},80%,65%,1)`),
borderWidth: 2,
}]
},
options: {
responsive: true, maintainAspectRatio: true,
scales: { r: { ticks: { display: false }, grid: { color:'rgba(255,255,255,0.1)' }, pointLabels: { color:'rgba(255,255,255,0.7)', font:{size:10} }, min:0, max:5 } },
plugins: { legend: { position:'bottom', labels: { color:'rgba(255,255,255,0.7)', font:{size:10}, padding:10 } } }
}
});
}
// ─── Profile Section ─────────────────────────────────────────────────────
function renderProfile() {
const user = teacher || {};
const responses = getResponsesForTeacher(session.userId);
const allScores = responses.flatMap(r => Object.values(r.scores||{}).flat());
const overallAvg = allScores.length ? (allScores.reduce((a,b)=>a+b,0)/allScores.length).toFixed(2) : null;
const initials = (user.name||'T').split(' ').map(w=>w[0]).join('').substring(0,2).toUpperCase();
const threshold = getSettings().minThreshold || 3.5;
const isUnder = overallAvg && parseFloat(overallAvg) < threshold;
const enrollments = JSON.parse(localStorage.getItem('sfft_enrollments')||'[]').filter(e => e.teacherId === session.userId);
const students = enrollments.map(e => getUserById(e.studentId)).filter(Boolean);
document.getElementById('profileContent').innerHTML = `
<div style="display:grid;grid-template-columns:240px 1fr;gap:24px;align-items:start;">
<!-- Left card: Avatar + quick stats -->
<div style="display:flex;flex-direction:column;gap:16px;">
<div class="section-card animate-in" style="text-align:center;padding:28px 20px;">
<div style="width:80px;height:80px;border-radius:50%;background:linear-gradient(135deg,var(--accent),var(--accent-light));display:flex;align-items:center;justify-content:center;font-weight:800;color:#fff;font-size:30px;margin:0 auto 14px;">${initials}</div>
<div style="font-weight:800;font-size:16px;margin-bottom:4px;">${user.name||'Teacher'}</div>
<div style="font-size:12px;color:var(--text-muted);margin-bottom:12px;">${user.email||''}</div>
${subject ? `<span class="badge badge-purple" style="margin-bottom:6px;display:inline-block;">📚 ${subject.name}</span>` : ''}
${user.department ? `<span class="badge badge-blue" style="margin-bottom:6px;display:inline-block;">🏛 ${user.department}</span>` : ''}
${user.section ? `<span class="badge badge-purple" style="font-size:11px;display:inline-block;">📛 ${user.section}</span>` : ''}
</div>
<!-- Performance summary mini card -->
<div class="section-card animate-in" style="padding:16px 18px;">
<div style="font-size:12px;color:var(--text-muted);font-weight:600;margin-bottom:12px;">PERFORMANCE SUMMARY</div>
${[
['Total Responses', responses.length],
['Overall Avg', overallAvg ? overallAvg + '/5' : '—'],
['Students Enrolled', students.length],
['Status', isUnder ? '⚠️ Needs Improvement' : '✅ On Track'],
].map(([k,v]) => `<div style="display:flex;justify-content:space-between;padding:8px 0;border-bottom:1px solid var(--border-light);font-size:13px;">
<span style="color:var(--text-muted);">${k}</span>
<span style="font-weight:700;color:${k==='Status'?(isUnder?'var(--danger)':'var(--success)'):''}">${v}</span>
</div>`).join('')}
</div>
</div>
<!-- Right card: Detailed info -->
<div class="section-card animate-in">
<div class="section-card-header"><div class="section-card-title">Personal & Academic Information</div></div>
<div class="section-card-body">
${[
['Full Name', user.name || '—'],
['Email Address', user.email || '—'],
['Department', user.department || '—'],
['Section', user.section || '—'],
['Subject', subject ? subject.name : '—'],
['Role', 'Teacher'],
].map(([k,v]) => `<div style="display:flex;justify-content:space-between;align-items:center;padding:13px 0;border-bottom:1px solid var(--border-light);">
<span style="font-size:13px;color:var(--text-muted);">${k}</span>
<span style="font-weight:600;font-size:13px;">${v}</span>
</div>`).join('')}
</div>
<div class="section-card-header" style="border-top:1px solid var(--border-light);margin-top:8px;"><div class="section-card-title">Enrolled Students</div></div>
<div class="section-card-body" style="padding:0;">
${students.length ? `<table><thead><tr><th>Name</th><th>Department</th><th>Section</th><th>Feedback</th></tr></thead><tbody>
${students.map(s => `<tr>
<td style="font-weight:600;">${s.name}</td>
<td>${s.department||'—'}</td>
<td>${s.section ? `<span class="badge badge-purple" style="font-size:11px;">${s.section}</span>` : '—'}</td>
<td>${getResponses().find(r=>r.studentId===s.id&&r.teacherId===session.userId) ? '<span class="badge badge-green" style="font-size:10px;">✅ Submitted</span>' : '<span class="badge badge-orange" style="font-size:10px;">⏳ Pending</span>'}</td>
</tr>`).join('')}
</tbody></table>` : '<div class="empty-state" style="padding:20px;"><div class="empty-icon">🎓</div><div class="empty-title">No students enrolled yet</div></div>'}
</div>
</div>
</div>
<!-- Change Password Section -->
<div class="section-card animate-in" style="margin-top:20px;">
<div class="section-card-header"><div class="section-card-title">🔒 Change Password</div></div>
<div class="section-card-body">
<div style="max-width:400px;">
<div class="form-group">
<label>Current Password</label>
<input type="password" id="cpCurrent" placeholder="Enter current password" />
</div>
<div class="form-group">
<label>New Password</label>
<input type="password" id="cpNew" placeholder="Min 6 characters" />
</div>
<div class="form-group">
<label>Confirm New Password</label>
<input type="password" id="cpConfirm" placeholder="Re-enter new password" />
</div>
<div id="cpMsg" style="font-size:13px;margin-bottom:10px;"></div>
<button class="btn btn-primary btn-sm" onclick="handleChangePassword()">🔒 Update Password</button>
</div>
</div>
</div>`;
}
function handleChangePassword() {
var msgEl = document.getElementById('cpMsg');
msgEl.textContent = '';
msgEl.style.color = '';
var cur = document.getElementById('cpCurrent').value;
var np = document.getElementById('cpNew').value;
var conf = document.getElementById('cpConfirm').value;
if (!cur) { msgEl.textContent = 'Please enter your current password.'; msgEl.style.color = 'var(--danger)'; return; }
if (!np || np.length < 6) { msgEl.textContent = 'New password must be at least 6 characters.'; msgEl.style.color = 'var(--danger)'; return; }
if (np !== conf) { msgEl.textContent = 'New passwords do not match.'; msgEl.style.color = 'var(--danger)'; return; }
try {
changePassword(session.userId, cur, np);
msgEl.textContent = '\u2705 Password changed successfully!';
msgEl.style.color = '#22c55e';
document.getElementById('cpCurrent').value = '';
document.getElementById('cpNew').value = '';
document.getElementById('cpConfirm').value = '';
} catch(e) {
msgEl.textContent = e.message;
msgEl.style.color = 'var(--danger)';
}
}
function renderComments() {
const responses = getResponsesForTeacher(session.userId).filter(r => r.comments);
const list = document.getElementById('commentsList');
if (!responses.length) { list.innerHTML = ''; document.getElementById('noComments').style.display = ''; return; }
document.getElementById('noComments').style.display = 'none';
list.innerHTML = responses.map(r => {
const s = getUserById(r.studentId);
const label = r.anonymous ? 'Anonymous Student' : (s ? s.name : 'Unknown');
return `
<div class="section-card" style="margin-bottom:14px;">
<div class="section-card-body">
<div style="display:flex; align-items:center; gap:10px; margin-bottom:10px;">
<div style="width:32px;height:32px;border-radius:50%;background:rgba(146,64,14,0.1);display:flex;align-items:center;justify-content:center;font-size:13px;">
${r.anonymous ? '🔒' : '🎓'}
</div>
<div>
<div style="font-size:13px; font-weight:600;">${label}</div>
<div style="font-size:11px; color:var(--text-muted);">${new Date(r.submittedAt).toLocaleDateString()}</div>
</div>
</div>
<p style="font-size:14px; color:var(--text-sub); line-height:1.6; font-style:italic;">"${r.comments}"</p>
</div>
</div>`;
}).join('');
}
function renderBreakdown() {
if (!stats) { document.getElementById('breakdownList').innerHTML = '<div class="empty-state"><div class="empty-icon">📊</div><div class="empty-title">No data yet</div></div>'; return; }
const entries = Object.entries(stats.sectionAverages);
document.getElementById('breakdownList').innerHTML = entries.map(([section, avg]) => {
const pct = ((avg / 5) * 100).toFixed(0);
const color = avg >= 4 ? 'var(--success)' : avg >= 3 ? 'var(--warning)' : 'var(--danger)';
return `
<div class="section-card" style="margin-bottom:14px;">
<div class="section-card-body">
<div style="display:flex; align-items:center; justify-content:space-between; margin-bottom:8px;">
<div style="font-weight:600; font-size:14px;">${section}</div>
<div style="font-size:18px; font-weight:800; color:${color};">${avg}/5</div>
</div>
<div class="progress-bar" style="height:8px; border-radius:4px;">
<div class="progress-fill" style="width:${pct}%; background:${color};"></div>
</div>
</div>
</div>`;
}).join('');
}
function renderDeptFeedback() {
const myDept = teacher ? teacher.department : null;
const el = document.getElementById('deptFeedbackContent');
const subtitle = document.getElementById('deptFeedbackSubtitle');
if (!myDept) {
el.innerHTML = `<div class="empty-state"><div class="empty-icon">🏛</div><div class="empty-title">No Department Set</div><div class="empty-desc">Ask your admin to assign a department to your profile.</div></div>`;
return;
}
subtitle.textContent = `All teachers in the ${myDept} department`;
const deptTeachers = getTeachers().filter(t => t.department === myDept);
if (!deptTeachers.length) {
el.innerHTML = `<div class="empty-state"><div class="empty-icon">🏛</div><div class="empty-title">No data</div></div>`; return;
}
// Sort teachers by avg score to determine rank (scores hidden, only rank shown)
const ranked = deptTeachers.map(t => {
const s = getTeacherStats(t.id);
return { t, avg: s ? s.overallAvg : null, resp: s ? s.totalResponses : 0 };
}).sort((a, b) => {
if (a.avg === null && b.avg === null) return 0;
if (a.avg === null) return 1;
if (b.avg === null) return -1;
return b.avg - a.avg;
});
// Assign ranks (teachers with same avg get same rank)
let currentRank = 0;
let lastAvg = null;
ranked.forEach((r, i) => {
if (r.avg !== null) {
if (r.avg !== lastAvg) { currentRank = i + 1; lastAvg = r.avg; }
r.rank = currentRank;
} else {
r.rank = null;
}
});
const rows = ranked.map(({ t, avg, resp, rank }) => {
const sub = getSubjectById(t.subjectId);
const isMe = t.id === session.userId;
const rankColor = rank === 1 ? '#fbbf24' : rank === 2 ? '#94a3b8' : rank === 3 ? '#cd7f32' : 'var(--text-sub)';
const rankIcon = rank === 1 ? '🥇' : rank === 2 ? '🥈' : rank === 3 ? '🥉' : '';
return `<tr style="${isMe ? 'background:rgba(146,64,14,0.04);' : ''}">
<td style="font-weight:${isMe?700:500};">${t.name}${isMe ? ' <span class="badge badge-purple" style="font-size:10px;">You</span>' : ''}</td>
<td>${sub ? sub.name : '—'}</td>
<td>${t.section ? `<span class="badge badge-purple" style="font-size:11px;">${t.section}</span>` : '—'}</td>
<td style="text-align:center;">${resp}</td>
<td style="font-weight:700;color:${rankColor};text-align:center;">${rank !== null ? rankIcon + ' #' + rank : '—'}</td>
</tr>`;
}).join('');
// Summary cards (no avg score shown)
const totalResps = deptTeachers.reduce((sum, t) => sum + (getTeacherStats(t.id)?.totalResponses || 0), 0);
const topT = ranked.find(r => r.rank === 1);
el.innerHTML = `
<div class="stats-grid animate-in" style="margin-bottom:20px;">
<div class="stat-card"><div class="stat-icon">👨🏫</div><div class="stat-value">${deptTeachers.length}</div><div class="stat-label">Teachers in ${myDept}</div></div>
<div class="stat-card"><div class="stat-icon">📨</div><div class="stat-value">${totalResps}</div><div class="stat-label">Total Responses</div></div>
<div class="stat-card"><div class="stat-icon">🏆</div><div class="stat-value" style="font-size:14px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">${topT ? topT.t.name.split(' ')[0] : '—'}</div><div class="stat-label">Top Rated Teacher</div></div>
</div>
<div class="section-card animate-in">
<div class="section-card-header"><div class="section-card-title">📊 ${myDept} Department Rankings</div></div>
<div class="section-card-body" style="padding:0;">
<table><thead><tr><th>Teacher</th><th>Subject</th><th>Section</th><th style="text-align:center;">Responses</th><th style="text-align:center;">Rank</th></tr></thead>
<tbody>${rows}</tbody></table>
</div>
</div>`;
}
function renderSectionFeedback() {
const myDept = teacher ? teacher.department : null;
const el = document.getElementById('sectionFeedbackContent');
const allResponses = getResponsesForTeacher(session.userId);
if (!allResponses.length) {
el.innerHTML = `<div class="empty-state"><div class="empty-icon">📛</div><div class="empty-title">No Feedback Yet</div><div class="empty-desc">No students have submitted feedback so far.</div></div>`;
return;
}
// Group responses by student's section
const bySection = {};
allResponses.forEach(r => {
const student = getUserById(r.studentId);
const sec = (student && student.section) ? student.section : 'Unknown Section';
if (!bySection[sec]) bySection[sec] = [];
bySection[sec].push(r);
});
el.innerHTML = Object.entries(bySection).sort().map(([sec, resps]) => {
const allScores = resps.flatMap(r => Object.values(r.scores || {}).flat());
const avg = allScores.length ? (allScores.reduce((a,b) => a+b,0)/allScores.length).toFixed(2) : '—';
const pct = allScores.length ? ((parseFloat(avg)/5)*100).toFixed(0) : 0;
const color = parseFloat(avg) >= 4 ? 'var(--success)' : parseFloat(avg) >= 3 ? 'var(--warning)' : 'var(--danger)';
// Category breakdown for this section
const catData = {};
resps.forEach(r => {
Object.entries(r.scores || {}).forEach(([cat, scores]) => {
if (!catData[cat]) catData[cat] = [];
catData[cat].push(...scores);
});
});
const catRows = Object.entries(catData).map(([cat, scores]) => {
const catAvg = (scores.reduce((a,b) => a+b,0)/scores.length).toFixed(2);
const catPct = ((parseFloat(catAvg)/5)*100).toFixed(0);
const catColor = parseFloat(catAvg) >= 4 ? 'var(--success)' : parseFloat(catAvg) >= 3 ? 'var(--warning)' : 'var(--danger)';
return `<div style="margin-bottom:8px;">
<div style="display:flex;justify-content:space-between;margin-bottom:3px;font-size:12px;">
<span>${cat}</span><span style="font-weight:700;color:${catColor};">${catAvg}/5</span>
</div>
<div style="height:6px;background:var(--border-light);border-radius:6px;overflow:hidden;">
<div style="height:100%;width:${catPct}%;background:${catColor};border-radius:6px;"></div>
</div>
</div>`;
}).join('');
return `
<div class="section-card animate-in" style="margin-bottom:18px;">
<div class="section-card-header">
<div class="section-card-title">📛 ${sec}</div>
<div style="display:flex;gap:8px;align-items:center;">
<span style="font-size:12px;color:var(--text-muted);">${resps.length} response${resps.length!==1?'s':''}</span>
<span style="font-size:16px;font-weight:800;color:${color};">${avg}/5</span>
</div>
</div>
<div class="section-card-body">
<div style="height:8px;background:var(--border-light);border-radius:8px;overflow:hidden;margin-bottom:16px;">
<div style="height:100%;width:${pct}%;background:${color};border-radius:8px;transition:width 0.7s;"></div>
</div>
${catRows}
</div>
</div>`;
}).join('');
}
function downloadReport() {
const responses = getResponsesForTeacher(session.userId);
if (!responses.length) { alert('No responses to export yet.'); return; }
const settings = getSettings();
const threshold = settings.minThreshold || 3.5;
const collegeName = settings.collegeName || 'Institution';
const teacherObj = getUserById(session.userId);
const dept = teacherObj ? (teacherObj.department || '') : '';
const section = teacherObj ? (teacherObj.section || '') : '';
const subject = teacherObj ? (teacherObj.subject || '') : '';
const statData = getTeacherStats(session.userId);
const sections = Object.keys(responses[0].scores || {});
const reportDate = new Date().toLocaleDateString('en-IN', {year:'numeric',month:'long',day:'numeric'});
// Compute section averages
const sectionAvgs = {};
sections.forEach(s => {
const allVals = responses.flatMap(r => r.scores[s] || []);
sectionAvgs[s] = allVals.length ? (allVals.reduce((a,b)=>a+b,0)/allVals.length).toFixed(2) : 0;
});
const allScores = responses.flatMap(r => Object.values(r.scores||{}).flat());
const overallAvg = allScores.length ? (allScores.reduce((a,b)=>a+b,0)/allScores.length).toFixed(2) : '0';
const isUnder = parseFloat(overallAvg) < threshold;
// Distribution
const dist = [0,0,0,0,0];
allScores.forEach(v => { if(v>=1&&v<=5) dist[Math.round(v)-1]++; });
const maxDist = Math.max(...dist, 1);
// Bar chart colors
const barColors = ['#ef4444','#f97316','#eab308','#22c55e','#10b981'];
const catColors = ['#92400e','#0891b2','#059669','#d97706','#dc2626','#7c3aed','#ec4899','#b45309'];
// Best & worst categories
const sortedCats = Object.entries(sectionAvgs).sort((a,b)=>b[1]-a[1]);
const bestCat = sortedCats[0] || ['N/A','0'];
const worstCat = sortedCats[sortedCats.length-1] || ['N/A','0'];
// Build SVG bar chart for categories
const catBarH = 32, catGap = 12, catW = 420;
const catChartH = sections.length * (catBarH + catGap) + 10;
let catSVG = `<svg width="100%" height="${catChartH}" viewBox="0 0 600 ${catChartH}">`;
sections.forEach((s, i) => {
const val = parseFloat(sectionAvgs[s]) || 0;
const pct = (val / 5) * catW;
const y = i * (catBarH + catGap) + 5;
const color = catColors[i % catColors.length];
catSVG += `<rect x="170" y="${y}" width="${pct}" height="${catBarH}" rx="6" fill="${color}" opacity="0.85"/>`;
catSVG += `<text x="165" y="${y + catBarH/2 + 5}" text-anchor="end" font-size="12" fill="#334155" font-weight="500">${s.length > 22 ? s.slice(0,22)+'...' : s}</text>`;
catSVG += `<text x="${172 + pct + 6}" y="${y + catBarH/2 + 5}" font-size="13" fill="#1e293b" font-weight="700">${val}/5</text>`;
});
catSVG += '</svg>';
// Build SVG bar chart for score distribution
const distBarW = 70, distGap = 20, distH = 160;
const distChartW = 5 * (distBarW + distGap) + 40;
let distSVG = `<svg width="100%" height="${distH + 40}" viewBox="0 0 ${distChartW} ${distH + 40}">`;
dist.forEach((count, i) => {
const h = maxDist > 0 ? (count / maxDist) * (distH - 20) : 0;
const x = i * (distBarW + distGap) + 30;
const y = distH - h;
distSVG += `<rect x="${x}" y="${y}" width="${distBarW}" height="${h}" rx="6" fill="${barColors[i]}" opacity="0.85"/>`;
distSVG += `<text x="${x + distBarW/2}" y="${y - 6}" text-anchor="middle" font-size="14" fill="#1e293b" font-weight="700">${count}</text>`;
distSVG += `<text x="${x + distBarW/2}" y="${distH + 18}" text-anchor="middle" font-size="13" fill="#64748b">${i+1} Star${i>0?'s':''}</text>`;
});
distSVG += `<line x1="25" y1="${distH}" x2="${distChartW - 10}" y2="${distH}" stroke="#e2e8f0" stroke-width="1"/>`;
distSVG += '</svg>';
// Build per-response table rows
const tableRows = responses.map((r, i) => {
const student = r.anonymous ? null : getUserById(r.studentId);
const sScores = sections.map(s => {
const vals = r.scores[s] || [];
return vals.length ? (vals.reduce((a,b)=>a+b,0)/vals.length).toFixed(2) : 'N/A';
});
const all = Object.values(r.scores||{}).flat();
const avg = all.length ? (all.reduce((a,b)=>a+b,0)/all.length).toFixed(2) : 'N/A';
const avgNum = parseFloat(avg);
const avgColor = avgNum >= 4 ? '#10b981' : avgNum >= 3 ? '#f59e0b' : '#ef4444';
return `<tr>
<td style="text-align:center;font-weight:600;">${i+1}</td>
<td>${r.submittedAt ? new Date(r.submittedAt).toLocaleDateString() : 'N/A'}</td>
<td>${r.anonymous ? '<em>Anonymous</em>' : (student ? (student.rollNo||student.email) : 'Unknown')}</td>
<td>${r.anonymous ? 'Hidden' : (student ? (student.section||'N/A') : 'N/A')}</td>
${sScores.map(sc => `<td style="text-align:center;">${sc}</td>`).join('')}
<td style="text-align:center;font-weight:700;color:${avgColor};">${avg}</td>
<td style="font-size:11px;max-width:140px;overflow:hidden;text-overflow:ellipsis;">${r.comments||'—'}</td>
</tr>`;
}).join('');
// Summary row
const summaryScores = sections.map(s => {
const vals = responses.flatMap(r => r.scores[s]||[]);
return vals.length ? (vals.reduce((a,b)=>a+b,0)/vals.length).toFixed(2) : 'N/A';
});
// Comments list
const commentsList = responses.filter(r => r.comments).map((r,i) => {
const student = r.anonymous ? null : getUserById(r.studentId);
return `<div style="background:#f8fafc;border-left:4px solid #92400e;padding:10px 14px;border-radius:8px;margin-bottom:10px;">
<div style="font-size:12px;color:#64748b;margin-bottom:4px;">${r.anonymous ? 'Anonymous Student' : (student?student.name:'Student')} — ${new Date(r.submittedAt).toLocaleDateString()}</div>
<div style="font-size:14px;color:#1e293b;">"${r.comments}"</div>
</div>`;
}).join('');
// Generate the full HTML report
const html = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Feedback Report — ${session.name}</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');
* { margin:0; padding:0; box-sizing:border-box; }
body { font-family:'Inter',system-ui,sans-serif; color:#1e293b; background:#fff; padding:0; }
@media print { body { padding:0; } .no-print { display:none!important; } }
.container { max-width:900px; margin:0 auto; padding:30px 36px; }
/* Header */
.report-header { text-align:center; padding:28px 20px; border-bottom:3px solid #92400e; margin-bottom:28px; }
.report-header h1 { font-size:22px; font-weight:800; color:#92400e; margin-bottom:4px; letter-spacing:-0.5px; }
.report-header .college { font-size:16px; font-weight:600; color:#334155; }
.report-header .subtitle { font-size:13px; color:#64748b; margin-top:6px; }
/* Info grid */
.info-grid { display:grid; grid-template-columns:1fr 1fr; gap:6px 32px; background:#f8fafc; padding:18px 22px; border-radius:12px; margin-bottom:24px; border:1px solid #e2e8f0; }
.info-grid .item { display:flex; gap:8px; font-size:13px; padding:4px 0; }
.info-grid .label { font-weight:600; color:#64748b; min-width:120px; }
.info-grid .value { font-weight:600; color:#1e293b; }
/* Status banner */
.status-banner { padding:16px 20px; border-radius:12px; margin-bottom:24px; display:flex; align-items:center; gap:14px; }
.status-pass { background:linear-gradient(135deg,#f0fdf4,#dcfce7); border:1.5px solid #86efac; }
.status-fail { background:linear-gradient(135deg,#fef2f2,#fee2e2); border:1.5px solid #fca5a5; }
.status-icon { width:44px; height:44px; border-radius:50%; display:flex; align-items:center; justify-content:center; font-size:22px; }
/* Summary cards */
.cards { display:grid; grid-template-columns:repeat(4,1fr); gap:14px; margin-bottom:28px; }
.card { background:#f8fafc; border:1px solid #e2e8f0; border-radius:12px; padding:16px; text-align:center; }
.card .num { font-size:26px; font-weight:800; color:#92400e; }
.card .lbl { font-size:11px; color:#64748b; margin-top:2px; font-weight:600; text-transform:uppercase; letter-spacing:0.5px; }
/* Section headers */
.section-title { font-size:16px; font-weight:700; color:#1e293b; margin:24px 0 14px; padding-bottom:8px; border-bottom:2px solid #e2e8f0; display:flex; align-items:center; gap:8px; }
/* Charts side by side */
.chart-grid { display:grid; grid-template-columns:1.2fr 1fr; gap:20px; margin-bottom:24px; }
.chart-box { background:#f8fafc; border:1px solid #e2e8f0; border-radius:12px; padding:18px; }
.chart-box h3 { font-size:13px; font-weight:700; color:#64748b; text-transform:uppercase; letter-spacing:0.5px; margin-bottom:12px; }
/* Table */
table { width:100%; border-collapse:collapse; font-size:12px; }
th { background:#92400e; color:#fff; padding:10px 8px; text-align:left; font-weight:600; font-size:11px; text-transform:uppercase; letter-spacing:0.3px; }
td { padding:9px 8px; border-bottom:1px solid #e2e8f0; }
tr:nth-child(even) { background:#f8fafc; }
tr.summary-row { background:#ede9fe; font-weight:700; }
/* Footer */
.report-footer { text-align:center; padding:20px 0; margin-top:24px; border-top:2px solid #e2e8f0; font-size:11px; color:#94a3b8; }
.print-btn { position:fixed; top:16px; right:16px; background:#92400e; color:#fff; border:none; padding:10px 20px; border-radius:8px; font-weight:600; cursor:pointer; font-size:13px; z-index:100; }
.print-btn:hover { background:#6d28d9; }
</style>
</head>
<body>
<button class="print-btn no-print" onclick="window.print()">🖨 Print / Save PDF</button>
<div class="container">
<!-- Header -->
<div class="report-header">
<h1>📊 Teacher Feedback Report</h1>
<div class="college">${collegeName}</div>
<div class="subtitle">Generated on ${reportDate}</div>
</div>
<!-- Teacher Info -->
<div class="info-grid">
<div class="item"><span class="label">👤 Teacher Name</span><span class="value">${session.name}</span></div>
<div class="item"><span class="label">🏫 Department</span><span class="value">${dept || 'N/A'}</span></div>
<div class="item"><span class="label">📚 Subject</span><span class="value">${subject || (teacherObj?.subjects?.join(', ') || 'N/A')}</span></div>
<div class="item"><span class="label">📋 Section</span><span class="value">${section || 'N/A'}</span></div>
<div class="item"><span class="label">📄 Total Responses</span><span class="value">${responses.length}</span></div>
<div class="item"><span class="label">🎯 Min. Threshold</span><span class="value">${threshold}/5</span></div>
</div>
<!-- Status Banner -->
<div class="status-banner ${isUnder ? 'status-fail' : 'status-pass'}">
<div class="status-icon" style="background:${isUnder ? '#fecaca' : '#bbf7d0'};">${isUnder ? '⚠️' : '✅'}</div>
<div>
<div style="font-weight:700;font-size:15px;color:${isUnder ? '#dc2626' : '#16a34a'};">${isUnder ? 'Improvement Required' : 'Performance On Track'}</div>
<div style="font-size:13px;color:#475569;">Overall Average: <strong style="font-size:16px;color:${isUnder ? '#dc2626' : '#16a34a'};">${overallAvg}/5</strong> ${isUnder ? '— Below minimum threshold of '+threshold+'/5' : '— Meets or exceeds the minimum threshold of '+threshold+'/5'}</div>
</div>
</div>
<!-- Summary Cards -->
<div class="cards">
<div class="card"><div class="num">${responses.length}</div><div class="lbl">Total Responses</div></div>
<div class="card"><div class="num" style="color:${isUnder?'#ef4444':'#92400e'};">${overallAvg}/5</div><div class="lbl">Overall Average</div></div>
<div class="card"><div class="num" style="font-size:18px;color:#10b981;">${bestCat[0].length>18?bestCat[0].slice(0,18)+'...':bestCat[0]}</div><div class="lbl">🏆 Best: ${bestCat[1]}/5</div></div>
<div class="card"><div class="num" style="font-size:18px;color:#ef4444;">${worstCat[0].length>18?worstCat[0].slice(0,18)+'...':worstCat[0]}</div><div class="lbl">⚠️ Lowest: ${worstCat[1]}/5</div></div>
</div>
<!-- Charts -->
<div class="chart-grid">
<div class="chart-box">
<h3>📊 Category-wise Performance</h3>
${catSVG}
</div>
<div class="chart-box">
<h3>🌟 Score Distribution (1-5)</h3>
${distSVG}
</div>
</div>
<!-- Detailed Table -->
<div class="section-title">📋 Detailed Response Data</div>
<div style="overflow-x:auto;margin-bottom:24px;">
<table>
<thead><tr>
<th>#</th><th>Date</th><th>Student</th><th>Section</th>
${sections.map(s => `<th style="font-size:10px;">${s.length>16?s.slice(0,16)+'...':s}</th>`).join('')}
<th>Overall</th><th>Comments</th>
</tr></thead>
<tbody>
${tableRows}
<tr class="summary-row">
<td colspan="4" style="text-align:right;font-weight:700;color:#92400e;">AVERAGE</td>
${summaryScores.map(sc => `<td style="text-align:center;font-weight:700;color:#92400e;">${sc}</td>`).join('')}
<td style="text-align:center;font-weight:800;font-size:14px;color:#92400e;">${overallAvg}</td>
<td></td>
</tr>
</tbody>
</table>
</div>
${commentsList ? `
<div class="section-title">💬 Student Comments</div>
${commentsList}
` : ''}
<div class="report-footer">
<div style="font-weight:600;color:#64748b;">This report was auto-generated by the ${collegeName} Feedback System</div>
<div style="margin-top:4px;">Confidential — For authorized use only — ${reportDate}</div>
</div>
</div>
</body>
</html>`;
// Open in new tab for printing / download
const blob = new Blob([html], {type: 'text/html;charset=utf-8'});
const url = URL.createObjectURL(blob);
window.open(url, '_blank');
showToast('Report opened! Use Print to save as PDF.', 'success');
}
</script>
</body>
</html>