seed-image-ai commited on
Commit
e13fc74
·
verified ·
1 Parent(s): 5a519f2

Upload index.html

Browse files
Files changed (1) hide show
  1. index.html +856 -0
index.html ADDED
@@ -0,0 +1,856 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="ar" dir="rtl" id="html-root">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title id="page-title">منصة الأداء - رؤية 2030</title>
7
+ <!-- Tailwind CSS -->
8
+ <script src="https://cdn.tailwindcss.com"></script>
9
+ <!-- Chart.js للرسوم البيانية -->
10
+ <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
11
+ <!-- Lucide Icons للأيقونات الاحترافية -->
12
+ <script src="https://unpkg.com/lucide@latest"></script>
13
+ <link href="https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700&display=swap" rel="stylesheet">
14
+ <style>
15
+ body { font-family: 'Cairo', sans-serif; background-color: #f8fafc; }
16
+ </style>
17
+ </head>
18
+ <body class="flex h-screen overflow-hidden">
19
+
20
+ <!-- القائمة الجانبية (Sidebar) -->
21
+ <aside class="w-64 bg-white border-l border-gray-200 flex flex-col justify-between hidden md:flex" id="sidebar">
22
+ <div>
23
+ <!-- ترويسة الشعار -->
24
+ <div class="p-6 flex items-center justify-between border-b border-gray-100">
25
+ <div class="text-right rtl:text-right ltr:text-left">
26
+ <h1 class="text-lg font-bold text-teal-700" id="nav-brand">منصة الأداء</h1>
27
+ <p class="text-xs text-gray-400" id="nav-sub">رؤية 2030</p>
28
+ </div>
29
+ <div class="w-9 h-9 rounded-xl bg-teal-600 flex items-center justify-center text-white font-bold">
30
+ <i data-lucide="sparkles" class="w-5 h-5"></i>
31
+ </div>
32
+ </div>
33
+
34
+ <!-- روابط التنقل -->
35
+ <nav class="p-4 space-y-2">
36
+ <button onclick="switchTab('dashboard')" id="btn-dashboard" class="w-full flex items-center gap-3 px-4 py-3 rounded-xl text-sm font-semibold transition bg-teal-700 text-white shadow-sm">
37
+ <i data-lucide="layout-dashboard" class="w-5 h-5"></i>
38
+ <span data-i18n="menu_dashboard">لوحة التحكم</span>
39
+ </button>
40
+ <button onclick="switchTab('kpis')" id="btn-kpis" class="w-full flex items-center gap-3 px-4 py-3 rounded-xl text-sm font-semibold transition text-gray-600 hover:bg-gray-50">
41
+ <i data-lucide="line-chart" class="w-5 h-5"></i>
42
+ <span data-i18n="menu_kpis">مؤشرات الأداء</span>
43
+ </button>
44
+ <button class="w-full flex items-center gap-3 px-4 py-3 rounded-xl text-sm font-semibold text-gray-600 hover:bg-gray-50">
45
+ <i data-lucide="check-square" class="w-5 h-5"></i>
46
+ <span data-i18n="menu_tasks">إدارة المهام</span>
47
+ </button>
48
+ <button class="w-full flex items-center gap-3 px-4 py-3 rounded-xl text-sm font-semibold text-gray-600 hover:bg-gray-50">
49
+ <i data-lucide="file-text" class="w-5 h-5"></i>
50
+ <span data-i18n="menu_reports">التقارير</span>
51
+ </button>
52
+ </nav>
53
+ </div>
54
+
55
+ <!-- معلومات المستخدم في أسفل القائمة -->
56
+ <div class="p-4 border-t border-gray-100 flex items-center gap-3">
57
+ <div class="w-10 h-10 rounded-full bg-teal-700 text-white flex items-center justify-center font-bold">أ</div>
58
+ <div class="text-right rtl:text-right ltr:text-left">
59
+ <h4 class="text-sm font-bold text-gray-800" data-i18n="user_name">أحمد العتيبي</h4>
60
+ <p class="text-xs text-gray-500" data-i18n="user_role">مدير الأداء</p>
61
+ </div>
62
+ </div>
63
+ </aside>
64
+
65
+ <!-- المحتوى الرئيسي -->
66
+ <main class="flex-1 flex flex-col h-screen overflow-y-auto">
67
+
68
+ <!-- الشريط العلوي (Navbar) -->
69
+ <header class="bg-white border-b border-gray-200 px-8 py-4 flex items-center justify-between sticky top-0 z-10">
70
+ <div class="flex items-center gap-4 w-1/3 relative">
71
+ <input type="text" id="search-input" placeholder="البحث عن مؤشرات، مهام، أو تقارير..." class="w-full bg-gray-50 border border-gray-200 rounded-xl px-4 py-2 pr-10 text-sm focus:outline-none focus:border-teal-600">
72
+ <i data-lucide="search" class="w-4 h-4 text-gray-400 absolute right-3 top-3"></i>
73
+ </div>
74
+
75
+ <div class="flex items-center gap-4">
76
+ <button onclick="toggleLanguage()" class="bg-gray-100 hover:bg-gray-200 text-gray-700 font-bold px-3 py-1.5 rounded-xl text-xs transition flex items-center gap-1.5">
77
+ <i data-lucide="globe" class="w-4 h-4"></i>
78
+ <span id="lang-btn-text">English</span>
79
+ </button>
80
+ <i data-lucide="bell" class="w-5 h-5 text-gray-500 cursor-pointer"></i>
81
+ </div>
82
+ </header>
83
+
84
+ <!-- محتوى التطبيق -->
85
+ <div class="p-8 space-y-8">
86
+
87
+ <!-- ================= الواجهة الأولى: لوحة التحكم ================= -->
88
+ <section id="view-dashboard" class="space-y-8">
89
+ <div>
90
+ <h2 class="text-xl font-bold text-gray-800" data-i18n="dash_title">لوحة التحكم</h2>
91
+ <p class="text-sm text-gray-500" data-i18n="dash_subtitle">نظرة شاملة على مؤشرات الأداء الرئيسية</p>
92
+ </div>
93
+
94
+ <!-- البطاقات الأربع العلوية -->
95
+ <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6">
96
+ <div class="bg-white p-6 rounded-2xl border border-gray-100 shadow-sm flex flex-col justify-between">
97
+ <div class="flex justify-between items-start">
98
+ <div class="w-12 h-12 rounded-2xl bg-teal-50 flex items-center justify-center text-teal-600">
99
+ <i data-lucide="target" class="w-6 h-6"></i>
100
+ </div>
101
+ <span class="text-xs font-bold text-emerald-600 bg-emerald-50 px-2 py-1 rounded-lg">12%+ ↗</span>
102
+ </div>
103
+ <div class="mt-4">
104
+ <h3 class="text-2xl font-bold text-gray-800" id="card-total-val">0</h3>
105
+ <p class="text-xs text-gray-500 mt-1" data-i18n="card_total">إجمالي المؤشرات</p>
106
+ </div>
107
+ </div>
108
+
109
+ <div class="bg-white p-6 rounded-2xl border border-gray-100 shadow-sm flex flex-col justify-between">
110
+ <div class="flex justify-between items-start">
111
+ <div class="w-12 h-12 rounded-2xl bg-emerald-50 flex items-center justify-center text-emerald-600">
112
+ <i data-lucide="check-circle-2" class="w-6 h-6"></i>
113
+ </div>
114
+ <span class="text-xs font-bold text-emerald-600 bg-emerald-50 px-2 py-1 rounded-lg">8%+ ↗</span>
115
+ </div>
116
+ <div class="mt-4">
117
+ <h3 class="text-2xl font-bold text-gray-800" id="card-good-val">0</h3>
118
+ <p class="text-xs text-gray-500 mt-1" data-i18n="card_completed">المؤشرات المكتملة</p>
119
+ </div>
120
+ </div>
121
+
122
+ <div class="bg-white p-6 rounded-2xl border border-gray-100 shadow-sm flex flex-col justify-between">
123
+ <div class="flex justify-between items-start">
124
+ <div class="w-12 h-12 rounded-2xl bg-red-50 flex items-center justify-center text-red-600">
125
+ <i data-lucide="alert-circle" class="w-6 h-6"></i>
126
+ </div>
127
+ <span class="text-xs font-bold text-red-600 bg-red-50 px-2 py-1 rounded-lg">2%- ↘</span>
128
+ </div>
129
+ <div class="mt-4">
130
+ <h3 class="text-2xl font-bold text-gray-800" id="card-late-val">0</h3>
131
+ <p class="text-xs text-gray-500 mt-1" data-i18n="card_delayed">المؤشرات المتأخرة</p>
132
+ </div>
133
+ </div>
134
+
135
+ <div class="bg-white p-6 rounded-2xl border border-gray-100 shadow-sm flex flex-col justify-between">
136
+ <div class="flex justify-between items-start">
137
+ <div class="w-12 h-12 rounded-2xl bg-teal-50 flex items-center justify-center text-teal-600">
138
+ <i data-lucide="trending-up" class="w-6 h-6"></i>
139
+ </div>
140
+ <span class="text-xs font-bold text-teal-600 bg-teal-50 px-2 py-1 rounded-lg">5%+ ↗</span>
141
+ </div>
142
+ <div class="mt-4">
143
+ <h3 class="text-2xl font-bold text-gray-800" id="card-avg-val">0%</h3>
144
+ <p class="text-xs text-gray-500 mt-1" data-i18n="card_rate">نسبة الإنجاز</p>
145
+ </div>
146
+ </div>
147
+ </div>
148
+
149
+ <!-- قسم توزيع الحالات + أداء المؤشرات الديناميكي -->
150
+ <div class="grid grid-cols-1 lg:grid-cols-3 gap-6">
151
+ <div class="bg-white p-6 rounded-2xl border border-gray-100 shadow-sm">
152
+ <h3 class="font-bold text-gray-800 mb-4" data-i18n="status_dist">توزيع الحالات</h3>
153
+ <div class="flex flex-col items-center justify-center py-4">
154
+ <div class="w-40 h-40">
155
+ <canvas id="statusDoughnutChart"></canvas>
156
+ </div>
157
+ </div>
158
+ <div class="flex justify-around text-xs text-gray-600 mt-4">
159
+ <span class="flex items-center gap-1"><i class="w-2.5 h-2.5 rounded-full bg-emerald-500 inline-block"></i> <span data-i18n="status_good">جيد</span> (<span id="count-good">0</span>)</span>
160
+ <span class="flex items-center gap-1"><i class="w-2.5 h-2.5 rounded-full bg-amber-500 inline-block"></i> <span data-i18n="status_medium">متوسط</span> (<span id="count-medium">0</span>)</span>
161
+ <span class="flex items-center gap-1"><i class="w-2.5 h-2.5 rounded-full bg-red-500 inline-block"></i> <span data-i18n="status_late">متأخر</span> (<span id="count-late">0</span>)</span>
162
+ </div>
163
+ </div>
164
+
165
+ <div class="bg-white p-6 rounded-2xl border border-gray-100 shadow-sm lg:col-span-2">
166
+ <h3 class="font-bold text-gray-800 mb-6" data-i18n="kpi_performance">أداء المؤشرات الرئيسية</h3>
167
+ <div id="dashboard-progress-bars" class="space-y-5"></div>
168
+ </div>
169
+ </div>
170
+
171
+ <!-- مخطط تطور الأداء الخطي -->
172
+ <div class="bg-white p-6 rounded-2xl border border-gray-100 shadow-sm space-y-4">
173
+ <h3 class="font-bold text-gray-800" data-i18n="perf_evolution">تطور الأداء (خلال 60 يوماً)</h3>
174
+ <div class="w-full h-64">
175
+ <canvas id="performanceChart"></canvas>
176
+ </div>
177
+ </div>
178
+
179
+ <!-- التحليلات الذكية -->
180
+ <div class="bg-teal-50/50 p-6 rounded-2xl border border-teal-100 space-y-4">
181
+ <div class="flex flex-wrap items-center justify-between gap-3">
182
+ <h3 class="font-bold text-gray-800 text-lg flex items-center gap-2">
183
+ <i data-lucide="sparkles" class="w-5 h-5 text-teal-600"></i>
184
+ <span data-i18n="ai_insights_title">التحليلات الذكية</span>
185
+ </h3>
186
+ <button id="show-ai-insights-btn" type="button" onclick="toggleAiInsights()" class="bg-teal-700 hover:bg-teal-800 text-white px-4 py-2 rounded-xl text-sm font-bold shadow-sm transition flex items-center gap-2">
187
+ <i data-lucide="sparkles" class="w-4 h-4"></i>
188
+ <span data-i18n="show_ai_insights_btn">إظهار التحليلات بالذكاء الاصطناعي</span>
189
+ </button>
190
+ </div>
191
+ <div class="grid grid-cols-1 md:grid-cols-3 gap-6 hidden" id="ai-insights-container" aria-live="polite"></div>
192
+ </div>
193
+ </section>
194
+
195
+ <!-- ================= الواجهة الثانية: إدارة المؤشرات ================= -->
196
+ <section id="view-kpis" class="space-y-6 hidden">
197
+ <div class="flex justify-between items-center">
198
+ <div>
199
+ <h2 class="text-xl font-bold text-gray-800" data-i18n="kpi_mgmt_title">إدارة مؤشرات الأداء</h2>
200
+ <p class="text-sm text-gray-500" data-i18n="kpi_mgmt_sub">إنشاء ومتابعة وتحليل مؤشرات الأداء الرئيسية</p>
201
+ </div>
202
+ <div class="flex items-center gap-3">
203
+ <button onclick="toggleNewKpiForm()" class="bg-teal-700 text-white px-4 py-2 rounded-xl text-sm font-bold shadow-sm hover:bg-teal-800 transition flex items-center gap-1.5">
204
+ <i data-lucide="plus" class="w-4 h-4"></i> إنشاء مؤشر جديد
205
+ </button>
206
+ <!-- زر توليد Qwen التحليلي الفوري والمستند للداتا -->
207
+ <button onclick="generateQwenAiKpi()" class="bg-teal-50 text-teal-700 border border-teal-200 px-4 py-2 rounded-xl text-sm font-bold shadow-sm hover:bg-teal-100 transition flex items-center gap-1.5">
208
+ <i data-lucide="sparkles" class="w-4 h-4 text-teal-600"></i>
209
+ <span data-i18n="ai_gen_btn">توليد مؤشرات بالذكاء الاصطناعي (Qwen)</span>
210
+ </button>
211
+ </div>
212
+ </div>
213
+
214
+ <!-- صندوق عرض رد تحليل نموذج Qwen الفعلي المربوط بالداتا -->
215
+ <div id="qwen-result-box" class="bg-teal-900 text-white p-6 rounded-2xl shadow-lg hidden space-y-3">
216
+ <div class="flex justify-between items-center border-b border-teal-700 pb-3">
217
+ <h4 class="font-bold text-teal-200 flex items-center gap-2">✨ تحليل وتوليد نموذج Qwen 2.5 (مستند لبيانات الملف)</h4>
218
+ <button onclick="document.getElementById('qwen-result-box').classList.add('hidden')" class="text-teal-300 hover:text-white text-xs">إغلاق ✕</button>
219
+ </div>
220
+ <div id="qwen-output-content" class="text-sm whitespace-pre-line leading-relaxed text-teal-50 space-y-2">
221
+ جاري تحليل البيانات عبر محرك Qwen الذكي...
222
+ </div>
223
+ </div>
224
+
225
+ <!-- نموذج إنشاء مؤشر جديد -->
226
+ <div id="new-kpi-form-card" class="bg-white p-6 rounded-2xl border border-gray-100 shadow-sm space-y-6 hidden">
227
+ <h3 class="font-bold text-gray-800 text-lg" data-i18n="form_title">إنشاء مؤشر أداء جديد</h3>
228
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
229
+ <div class="space-y-2">
230
+ <label class="text-xs font-bold text-gray-700" data-i18n="label_name">اسم المؤشر</label>
231
+ <input type="text" id="input-kpi-name" placeholder="أدخل اسم المؤشر" class="w-full bg-gray-50 border border-gray-200 rounded-xl px-4 py-2 text-sm focus:outline-none focus:border-teal-600">
232
+ </div>
233
+ <div class="space-y-2">
234
+ <label class="text-xs font-bold text-gray-700" data-i18n="label_dept">الجهة المسؤولة</label>
235
+ <input type="text" id="input-kpi-dept" placeholder="أدخل اسم الجهة" class="w-full bg-gray-50 border border-gray-200 rounded-xl px-4 py-2 text-sm focus:outline-none focus:border-teal-600">
236
+ </div>
237
+ </div>
238
+ <div class="space-y-2">
239
+ <label class="text-xs font-bold text-gray-700" data-i18n="label_desc">الوصف</label>
240
+ <textarea id="input-kpi-desc" rows="3" placeholder="أدخل وصف المؤشر" class="w-full bg-gray-50 border border-gray-200 rounded-xl px-4 py-2 text-sm focus:outline-none focus:border-teal-600"></textarea>
241
+ </div>
242
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
243
+ <div class="space-y-2">
244
+ <label class="text-xs font-bold text-gray-700" data-i18n="label_target">القيمة المستهدفة</label>
245
+ <input type="number" id="input-kpi-target" placeholder="90" class="w-full bg-gray-50 border border-gray-200 rounded-xl px-4 py-2 text-sm focus:outline-none focus:border-teal-600">
246
+ </div>
247
+ <div class="space-y-2">
248
+ <label class="text-xs font-bold text-gray-700" data-i18n="label_date">تاريخ الإنجاز</label>
249
+ <input type="text" id="input-kpi-date" placeholder="يوم/شهر/سنة" class="w-full bg-gray-50 border border-gray-200 rounded-xl px-4 py-2 text-sm focus:outline-none focus:border-teal-600">
250
+ </div>
251
+ </div>
252
+ <div class="flex justify-end gap-3 pt-2">
253
+ <button onclick="toggleNewKpiForm()" class="bg-gray-100 text-gray-700 px-5 py-2 rounded-xl text-sm font-bold hover:bg-gray-200 transition" data-i18n="btn_cancel">إلغاء</button>
254
+ <button onclick="saveNewKpi()" class="bg-teal-700 text-white px-5 py-2 rounded-xl text-sm font-bold shadow-sm hover:bg-teal-800 transition" data-i18n="btn_save">حفظ المؤشر</button>
255
+ </div>
256
+ </div>
257
+
258
+ <div id="kpi-cards-container" class="space-y-4"></div>
259
+ </section>
260
+
261
+ </div>
262
+ </main>
263
+
264
+ <!-- البرمجية والتوليد الذكي المستند للبيانات الفعليّة -->
265
+ <script>
266
+ const translations = {
267
+ ar: {
268
+ page_title: "منصة الأداء - رؤية 2030",
269
+ nav_brand: "منصة الأداء",
270
+ nav_sub: "رؤية 2030",
271
+ menu_dashboard: "لوحة التحكم",
272
+ menu_kpis: "مؤشرات الأداء",
273
+ menu_tasks: "إدارة المهام",
274
+ menu_reports: "التقارير",
275
+ user_name: "أحمد العتيبي",
276
+ user_role: "مدير الأداء",
277
+ search_placeholder: "البحث عن مؤشرات، مهام، أو تقارير...",
278
+ dash_title: "لوحة التحكم",
279
+ dash_subtitle: "نظرة شاملة على مؤشرات الأداء الرئيسية",
280
+ card_total: "إجمالي المؤشرات",
281
+ card_completed: "المؤشرات المكتملة",
282
+ card_delayed: "المؤشرات المتأخرة",
283
+ card_rate: "نسبة الإنجاز",
284
+ status_dist: "توزيع الحالات",
285
+ status_general: "الحالة العامة",
286
+ status_good: "جيد",
287
+ status_medium: "متوسط",
288
+ status_late: "متأخر",
289
+ kpi_performance: "أداء المؤشرات الرئيسية",
290
+ perf_evolution: "تطور الأداء (خلال 60 يوماً)",
291
+ ai_insights_title: "التحليلات الذكية",
292
+ show_ai_insights_btn: "إظهار التحليلات بالذكاء الاصطناعي",
293
+ kpi_mgmt_title: "إدارة مؤشرات الأداء",
294
+ kpi_mgmt_sub: "إنشاء ومتابعة وتحليل مؤشرات الأداء الرئيسية",
295
+ new_kpi_btn: "إنشاء مؤشر جديد",
296
+ ai_gen_btn: "توليد مؤشرات بالذكاء الاصطناعي (Qwen)",
297
+ form_title: "إنشاء مؤشر أداء جديد",
298
+ label_name: "اسم المؤشر",
299
+ label_dept: "الجهة المسؤولة",
300
+ label_desc: "الوصف",
301
+ label_target: "القيمة المستهدفة",
302
+ label_date: "تاريخ الإنجاز",
303
+ btn_cancel: "إلغاء",
304
+ btn_save: "حفظ المؤشر",
305
+ target_label: "الهدف",
306
+ dept_label: "الجهة المسؤولة",
307
+ progress_label: "نسبة التقدم"
308
+ },
309
+ en: {
310
+ page_title: "Performance Platform - Vision 2030",
311
+ nav_brand: "Performance Platform",
312
+ nav_sub: "Vision 2030",
313
+ menu_dashboard: "Dashboard",
314
+ menu_kpis: "KPIs Management",
315
+ menu_tasks: "Tasks Management",
316
+ menu_reports: "Reports",
317
+ user_name: "Ahmed Al-Otaibi",
318
+ user_role: "Performance Director",
319
+ search_placeholder: "Search for KPIs, tasks, or reports...",
320
+ dash_title: "Dashboard",
321
+ dash_subtitle: "Comprehensive overview of key performance indicators",
322
+ card_total: "Total KPIs",
323
+ card_completed: "Completed KPIs",
324
+ card_delayed: "Delayed KPIs",
325
+ card_rate: "Completion Rate",
326
+ status_dist: "Status Distribution",
327
+ status_general: "Overall Status",
328
+ status_good: "Good",
329
+ status_medium: "Medium",
330
+ status_late: "Late",
331
+ kpi_performance: "Key Indicators Performance",
332
+ perf_evolution: "Performance Evolution (60 Days)",
333
+ ai_insights_title: "Smart Analytics",
334
+ show_ai_insights_btn: "Show AI insights",
335
+ kpi_mgmt_title: "KPIs Management",
336
+ kpi_mgmt_sub: "Create, monitor, and analyze key performance indicators",
337
+ new_kpi_btn: "New KPI",
338
+ ai_gen_btn: "AI KPI Generation (Qwen)",
339
+ form_title: "Create New KPI",
340
+ label_name: "KPI Name",
341
+ label_dept: "Responsible Dept",
342
+ label_desc: "Description",
343
+ label_target: "Target Value",
344
+ label_date: "Completion Date",
345
+ btn_cancel: "Cancel",
346
+ btn_save: "Save KPI",
347
+ target_label: "Target",
348
+ dept_label: "Responsible Dept",
349
+ progress_label: "Progress Rate"
350
+ }
351
+ };
352
+
353
+ let currentLang = 'ar';
354
+ let currentKpiData = [];
355
+ let lineChartInstance = null;
356
+ let doughnutChartInstance = null;
357
+
358
+ // ضع هنا رابط Cloudflare Worker بعد نشره. لا تضع HF_TOKEN في هذا الملف مطلقًا.
359
+ const AI_API_URL = "";
360
+ let aiInsightsCacheKey = "";
361
+ let aiInsightsRequestId = 0;
362
+ let latestAiKpiSuggestions = [];
363
+
364
+
365
+ async function loadExternalData() {
366
+ const fileName = currentLang === 'ar' ? 'data_ar.json' : 'data_en.json';
367
+ try {
368
+ const response = await fetch(fileName);
369
+ if (!response.ok) throw new Error('تعذر تحميل ملف البيانات');
370
+ currentKpiData = await response.json();
371
+ renderAll();
372
+ } catch (error) {
373
+ console.error("Error fetching JSON:", error);
374
+ }
375
+ }
376
+
377
+ function toggleLanguage() {
378
+ currentLang = currentLang === 'ar' ? 'en' : 'ar';
379
+ const root = document.getElementById('html-root');
380
+ root.lang = currentLang;
381
+ root.dir = currentLang === 'ar' ? 'rtl' : 'ltr';
382
+
383
+ document.getElementById('lang-btn-text').innerText = currentLang === 'ar' ? 'English' : 'عربي';
384
+ document.getElementById('search-input').placeholder = translations[currentLang].search_placeholder;
385
+ const insightsButtonText = document.querySelector("#show-ai-insights-btn span[data-i18n='show_ai_insights_btn']");
386
+ if (insightsButtonText) insightsButtonText.textContent = document.getElementById("ai-insights-container").classList.contains("hidden")
387
+ ? (currentLang === "ar" ? "إظهار التحليلات بالذكاء الاصطناعي" : "Show AI insights")
388
+ : (currentLang === "ar" ? "إخفاء التحليلات الذكية" : "Hide AI insights");
389
+
390
+ document.querySelectorAll('[data-i18n]').forEach(el => {
391
+ const key = el.getAttribute('data-i18n');
392
+ if (translations[currentLang][key]) {
393
+ el.innerText = translations[currentLang][key];
394
+ }
395
+ });
396
+
397
+ loadExternalData();
398
+ }
399
+
400
+ function toggleNewKpiForm() {
401
+ document.getElementById('new-kpi-form-card').classList.toggle('hidden');
402
+ }
403
+
404
+
405
+ // يرسل البيانات الفعلية إلى Backend آمن، ولا يستدعي النموذج مباشرة من المتصفح.
406
+ async function callAiApi(path, payload) {
407
+ const apiBase = AI_API_URL ? AI_API_URL.replace(/\/+$/, "") : "";
408
+ const response = await fetch(`${apiBase}${path}`, {
409
+ method: "POST",
410
+ headers: { "Content-Type": "application/json" },
411
+ body: JSON.stringify(payload)
412
+ });
413
+
414
+ let result;
415
+ try {
416
+ result = await response.json();
417
+ } catch {
418
+ throw new Error(currentLang === "ar"
419
+ ? "الخادم أعاد استجابة غير مفهومة."
420
+ : "The server returned an unreadable response.");
421
+ }
422
+
423
+ if (!response.ok) {
424
+ throw new Error(result.error || result.detail || (currentLang === "ar"
425
+ ? `تعذر الاتصال بخدمة الذكاء الاصطناعي (HTTP ${response.status}).`
426
+ : `AI request failed (HTTP ${response.status}).`));
427
+ }
428
+ return result;
429
+ }
430
+
431
+ // نرسل بيانات المؤشرات والاتجاهات الأخيرة فقط لتقليل حجم الطلب.
432
+ function buildAiKpiPayload() {
433
+ return currentKpiData.map(k => ({
434
+ kpi_id: k.kpi_id || "",
435
+ kpi_name: k.kpi_name || "",
436
+ description: k.description || "",
437
+ department: k.department || "",
438
+ target: Number(k.target),
439
+ latest_value: Number(k.latest_value),
440
+ status: k.status || "",
441
+ daily_history: Array.isArray(k.daily_history)
442
+ ? k.daily_history.slice(-15).map(d => ({
443
+ date: d.date || "",
444
+ day: d.day ?? "",
445
+ value: Number(d.value)
446
+ }))
447
+ : []
448
+ }));
449
+ }
450
+
451
+ function appendTextElement(parent, tagName, className, text) {
452
+ const el = document.createElement(tagName);
453
+ if (className) el.className = className;
454
+ el.textContent = text == null ? "" : String(text);
455
+ parent.appendChild(el);
456
+ return el;
457
+ }
458
+
459
+ function showAiError(container, message) {
460
+ container.replaceChildren();
461
+ const card = document.createElement("div");
462
+ card.className = "bg-white p-5 rounded-2xl border border-red-200 shadow-sm text-sm text-red-700";
463
+ card.setAttribute("role", "alert");
464
+ card.textContent = message;
465
+ container.appendChild(card);
466
+ }
467
+
468
+ function renderAiInsights(insights) {
469
+ const container = document.getElementById("ai-insights-container");
470
+ const colors = [
471
+ { border: "border-r-emerald-500", title: "text-emerald-600" },
472
+ { border: "border-r-amber-500", title: "text-amber-600" },
473
+ { border: "border-r-blue-500", title: "text-blue-600" }
474
+ ];
475
+ container.replaceChildren();
476
+
477
+ insights.slice(0, 3).forEach((insight, index) => {
478
+ const card = document.createElement("div");
479
+ card.className = `bg-white p-5 rounded-2xl border border-gray-100 shadow-sm border-r-4 ${colors[index % colors.length].border} space-y-2`;
480
+ const fallbackTitles = currentLang === "ar"
481
+ ? ["تحسين ملحوظ", "تنبيه", "توصية"]
482
+ : ["Notable Improvement", "Alert", "Recommendation"];
483
+ appendTextElement(card, "h4", `font-bold ${colors[index % colors.length].title} text-sm`,
484
+ fallbackTitles[index] || insight.title || (currentLang === "ar" ? `رؤية تحليلية ${index + 1}` : `Insight ${index + 1}`));
485
+ appendTextElement(card, "p", "text-xs text-gray-700 leading-6", insight.finding || "");
486
+ if (insight.evidence) {
487
+ appendTextElement(card, "p", "text-xs text-gray-500 leading-6",
488
+ (currentLang === "ar" ? "الدليل من البيانات: " : "Evidence: ") + insight.evidence);
489
+ }
490
+ if (insight.recommendation) {
491
+ appendTextElement(card, "p", "text-xs text-teal-800 leading-6",
492
+ (currentLang === "ar" ? "الإجراء المقترح: " : "Suggested action: ") + insight.recommendation);
493
+ }
494
+ container.appendChild(card);
495
+ });
496
+ }
497
+
498
+ async function toggleAiInsights() {
499
+ const container = document.getElementById("ai-insights-container");
500
+ const buttonText = document.querySelector("#show-ai-insights-btn span[data-i18n='show_ai_insights_btn']");
501
+ const isHidden = container.classList.contains("hidden");
502
+ if (!isHidden) {
503
+ container.classList.add("hidden");
504
+ if (buttonText) buttonText.textContent = currentLang === "ar" ? "إظهار التحليلات بالذكاء الاصطناعي" : "Show AI insights";
505
+ return;
506
+ }
507
+ container.classList.remove("hidden");
508
+ if (buttonText) buttonText.textContent = currentLang === "ar" ? "إخفاء التحليلات الذكية" : "Hide AI insights";
509
+ await updateAiInsights(true);
510
+ }
511
+
512
+ async function updateAiInsights(force = false) {
513
+ const container = document.getElementById("ai-insights-container");
514
+ if (!currentKpiData || currentKpiData.length === 0) {
515
+ container.replaceChildren();
516
+ return;
517
+ }
518
+
519
+ const payloadKpis = buildAiKpiPayload();
520
+ const requestKey = JSON.stringify({ language: currentLang, kpis: payloadKpis });
521
+ if (!force && requestKey === aiInsightsCacheKey) return;
522
+ aiInsightsCacheKey = requestKey;
523
+
524
+ const requestId = ++aiInsightsRequestId;
525
+ container.replaceChildren();
526
+ const loading = document.createElement("div");
527
+ loading.className = "md:col-span-3 bg-white p-5 rounded-2xl border border-teal-100 text-sm text-teal-800";
528
+ loading.setAttribute("role", "status");
529
+ loading.textContent = currentLang === "ar"
530
+ ? "⏳ يرسل التطبيق بيانات المؤشرات إلى Qwen لتحليلها. قد يستغرق الرد بعض الوقت..."
531
+ : "⏳ Sending KPI data to Qwen for analysis. This may take a little while...";
532
+ container.appendChild(loading);
533
+
534
+ try {
535
+ const result = await callAiApi("/api/insights", {
536
+ language: currentLang,
537
+ kpis: payloadKpis
538
+ });
539
+ if (requestId !== aiInsightsRequestId) return;
540
+ if (!Array.isArray(result.insights) || result.insights.length !== 3) {
541
+ throw new Error(currentLang === "ar"
542
+ ? "لم يرجع النموذج ثلاثة تحليلات بالشكل المتوقع. حاولي مرة أخرى."
543
+ : "The model did not return exactly three insights. Please try again.");
544
+ }
545
+ renderAiInsights(result.insights);
546
+ } catch (error) {
547
+ if (requestId !== aiInsightsRequestId) return;
548
+ aiInsightsCacheKey = ""; // يسمح بإعادة المحاولة لاحقًا
549
+ showAiError(container, (currentLang === "ar" ? "تعذر توليد التحليلات: " : "Could not generate insights: ") + error.message);
550
+ }
551
+ }
552
+
553
+ function renderSuggestedKpis(indicators) {
554
+ const outputContent = document.getElementById("qwen-output-content");
555
+ outputContent.replaceChildren();
556
+ appendTextElement(outputContent, "p", "font-bold text-teal-100 mb-3",
557
+ currentLang === "ar"
558
+ ? "اقترح Qwen المؤشرات التالية بناءً على البيانات الحالية. راجعي كل اقتراح قبل إضافته."
559
+ : "Qwen suggested these KPIs from the current data. Review each suggestion before adding it.");
560
+
561
+ const grid = document.createElement("div");
562
+ grid.className = "grid grid-cols-1 lg:grid-cols-3 gap-4 mt-4";
563
+
564
+ indicators.forEach((item, index) => {
565
+ const card = document.createElement("div");
566
+ card.className = "bg-white text-gray-800 p-4 rounded-xl shadow-sm space-y-2";
567
+ appendTextElement(card, "h5", "font-bold text-teal-800", item.kpi_name || (currentLang === "ar" ? "مؤشر مقترح" : "Suggested KPI"));
568
+ appendTextElement(card, "p", "text-xs leading-6 text-gray-600", item.description || "");
569
+ appendTextElement(card, "p", "text-xs", `${currentLang === "ar" ? "الجهة المقترحة: " : "Suggested department: "}${item.department || (currentLang === "ar" ? "تُحدد لاحقً��" : "To be determined")}`);
570
+ if (item.formula) appendTextElement(card, "p", "text-xs leading-5", `${currentLang === "ar" ? "طريقة القياس: " : "Measurement: "}${item.formula}`);
571
+ appendTextElement(card, "p", "text-xs font-bold text-teal-800",
572
+ `${currentLang === "ar" ? "الهدف المقترح: " : "Suggested target: "}${item.target ?? "—"}%`);
573
+ if (item.rationale) appendTextElement(card, "p", "text-xs leading-5 text-gray-600",
574
+ `${currentLang === "ar" ? "سبب الاقتراح: " : "Rationale: "}${item.rationale}`);
575
+ if (item.data_needed) appendTextElement(card, "p", "text-xs leading-5 text-gray-500",
576
+ `${currentLang === "ar" ? "البيانات المطلوبة: " : "Data needed: "}${item.data_needed}`);
577
+
578
+ const button = document.createElement("button");
579
+ button.type = "button";
580
+ button.className = "w-full mt-2 bg-teal-700 hover:bg-teal-800 text-white text-xs font-bold px-3 py-2 rounded-lg transition";
581
+ button.textContent = currentLang === "ar" ? "استخدام هذا الاقتراح" : "Use this suggestion";
582
+ button.addEventListener("click", () => applyAiKpiSuggestion(index));
583
+ card.appendChild(button);
584
+ grid.appendChild(card);
585
+ });
586
+ outputContent.appendChild(grid);
587
+ }
588
+
589
+ function applyAiKpiSuggestion(index) {
590
+ const item = latestAiKpiSuggestions[index];
591
+ if (!item) return;
592
+
593
+ document.getElementById("input-kpi-name").value = item.kpi_name || "";
594
+ document.getElementById("input-kpi-dept").value = item.department || "";
595
+ document.getElementById("input-kpi-desc").value = [
596
+ item.description || "",
597
+ item.formula ? (currentLang === "ar" ? "طريقة القياس: " : "Measurement: ") + item.formula : "",
598
+ item.rationale ? (currentLang === "ar" ? "مبرر الاقتراح: " : "Rationale: ") + item.rationale : ""
599
+ ].filter(Boolean).join("\n\n");
600
+ document.getElementById("input-kpi-target").value = Number.isFinite(Number(item.target)) ? Number(item.target) : 90;
601
+ if (document.getElementById("new-kpi-form-card").classList.contains("hidden")) {
602
+ toggleNewKpiForm();
603
+ }
604
+ document.getElementById("new-kpi-form-card").scrollIntoView({ behavior: "smooth", block: "start" });
605
+ }
606
+
607
+ async function generateQwenAiKpi() {
608
+ const resultBox = document.getElementById("qwen-result-box");
609
+ const outputContent = document.getElementById("qwen-output-content");
610
+ resultBox.classList.remove("hidden");
611
+ outputContent.replaceChildren();
612
+ appendTextElement(outputContent, "p", "text-teal-100",
613
+ currentLang === "ar"
614
+ ? "⏳ يرسل التطبيق المؤشرات الحالية إلى Qwen لتوليد اقتراحات جديدة..."
615
+ : "⏳ Sending the current KPIs to Qwen to generate new suggestions...");
616
+
617
+ if (!currentKpiData || currentKpiData.length === 0) {
618
+ outputContent.textContent = currentLang === "ar" ? "لا توجد بيانات لتحليلها." : "There is no data to analyze.";
619
+ return;
620
+ }
621
+
622
+ try {
623
+ const result = await callAiApi("/api/generate-kpis", {
624
+ language: currentLang,
625
+ kpis: buildAiKpiPayload()
626
+ });
627
+ if (!Array.isArray(result.indicators) || result.indicators.length !== 3) {
628
+ throw new Error(currentLang === "ar"
629
+ ? "لم يرجع النموذج ثلاثة مؤشرات بالشكل المتوقع. حاولي مرة أخرى."
630
+ : "The model did not return exactly three KPIs. Please try again.");
631
+ }
632
+ latestAiKpiSuggestions = result.indicators;
633
+ renderSuggestedKpis(latestAiKpiSuggestions);
634
+ } catch (error) {
635
+ outputContent.replaceChildren();
636
+ const errorBox = document.createElement("div");
637
+ errorBox.className = "bg-red-50 text-red-800 rounded-xl p-4";
638
+ errorBox.setAttribute("role", "alert");
639
+ errorBox.textContent = (currentLang === "ar" ? "تعذر توليد المؤشرات: " : "Could not generate KPIs: ") + error.message;
640
+ outputContent.appendChild(errorBox);
641
+ }
642
+ }
643
+
644
+ function saveNewKpi() {
645
+ const name = document.getElementById('input-kpi-name').value;
646
+ const dept = document.getElementById('input-kpi-dept').value;
647
+ const desc = document.getElementById('input-kpi-desc').value;
648
+ const target = parseFloat(document.getElementById('input-kpi-target').value) || 90;
649
+
650
+ if(!name) {
651
+ alert(currentLang === 'ar' ? 'الرجاء إدخال اسم المؤشر' : 'Please enter KPI name');
652
+ return;
653
+ }
654
+
655
+ const newKpi = {
656
+ kpi_id: "KPI_0" + (currentKpiData.length + 1),
657
+ kpi_name: name,
658
+ description: desc || (currentLang === 'ar' ? 'وصف المؤشر الجديد' : 'New KPI description'),
659
+ department: dept || (currentLang === 'ar' ? 'الإدارة العامة' : 'General Department'),
660
+ target: target,
661
+ status: currentLang === 'ar' ? 'جيد' : 'Good',
662
+ latest_value: Math.round(target * 0.9),
663
+ daily_history: Array.from({length: 60}, (_, i) => ({ day: i+1, value: Math.round(target * 0.8) }))
664
+ };
665
+
666
+ currentKpiData.push(newKpi);
667
+ toggleNewKpiForm();
668
+ renderAll();
669
+
670
+ document.getElementById('input-kpi-name').value = '';
671
+ document.getElementById('input-kpi-dept').value = '';
672
+ document.getElementById('input-kpi-desc').value = '';
673
+ document.getElementById('input-kpi-target').value = '';
674
+ document.getElementById('input-kpi-date').value = '';
675
+ }
676
+
677
+ function updateSummaryCards() {
678
+ if(!currentKpiData || currentKpiData.length === 0) return;
679
+
680
+ let goodCount = 0, mediumCount = 0, lateCount = 0, totalValSum = 0;
681
+
682
+ currentKpiData.forEach(item => {
683
+ totalValSum += item.latest_value;
684
+ const statusStr = item.status.toLowerCase();
685
+ if (statusStr.includes('good') || statusStr.includes('جيد')) goodCount++;
686
+ else if (statusStr.includes('needs') || statusStr.includes('متابعة') || statusStr.includes('متوسط')) mediumCount++;
687
+ else lateCount++;
688
+ });
689
+
690
+ const totalKpis = currentKpiData.length;
691
+ const avgRate = (totalValSum / totalKpis).toFixed(1);
692
+
693
+ document.getElementById('card-total-val').innerText = totalKpis;
694
+ document.getElementById('card-good-val').innerText = goodCount;
695
+ document.getElementById('card-late-val').innerText = lateCount;
696
+ document.getElementById('card-avg-val').innerText = `${avgRate}%`;
697
+
698
+ document.getElementById('count-good').innerText = goodCount;
699
+ document.getElementById('count-medium').innerText = mediumCount;
700
+ document.getElementById('count-late').innerText = lateCount;
701
+
702
+ renderDoughnutChart(goodCount, mediumCount, lateCount);
703
+ }
704
+
705
+ function renderDoughnutChart(good, medium, late) {
706
+ const ctx = document.getElementById('statusDoughnutChart').getContext('2d');
707
+ if (doughnutChartInstance) doughnutChartInstance.destroy();
708
+
709
+ doughnutChartInstance = new Chart(ctx, {
710
+ type: 'doughnut',
711
+ data: {
712
+ labels: [translations[currentLang].status_good, translations[currentLang].status_medium, translations[currentLang].status_late],
713
+ datasets: [{
714
+ data: [good, medium, late],
715
+ backgroundColor: ['#10B981', '#F59E0B', '#EF4444'],
716
+ borderWidth: 2,
717
+ hoverOffset: 4
718
+ }]
719
+ },
720
+ options: {
721
+ responsive: true,
722
+ maintainAspectRatio: false,
723
+ plugins: { legend: { display: false } },
724
+ cutout: '75%'
725
+ }
726
+ });
727
+ }
728
+
729
+ function renderDashboardProgress() {
730
+ const container = document.getElementById('dashboard-progress-bars');
731
+ container.innerHTML = '';
732
+
733
+ currentKpiData.forEach(item => {
734
+ let color = item.latest_value >= 80 ? 'bg-emerald-500' : (item.latest_value >= 60 ? 'bg-amber-500' : 'bg-red-500');
735
+ const targetText = translations[currentLang].target_label;
736
+ container.innerHTML += `
737
+ <div>
738
+ <div class="flex justify-between text-sm mb-1">
739
+ <span class="font-bold text-gray-700">${item.kpi_name}</span>
740
+ <span class="text-gray-500">${targetText}: ${item.target}% (<span class="font-bold text-gray-800">${item.latest_value}%</span>)</span>
741
+ </div>
742
+ <div class="w-full bg-gray-100 h-3 rounded-full overflow-hidden">
743
+ <div class="${color} h-full rounded-full transition-all duration-500" style="width: ${item.latest_value}%"></div>
744
+ </div>
745
+ </div>
746
+ `;
747
+ });
748
+ }
749
+
750
+ function renderKPIsList() {
751
+ const container = document.getElementById('kpi-cards-container');
752
+ container.innerHTML = '';
753
+
754
+ currentKpiData.forEach(item => {
755
+ let isGood = item.latest_value >= 80;
756
+ let isMedium = item.latest_value >= 60 && item.latest_value < 80;
757
+ let badgeColor = isGood ? 'bg-emerald-50 text-emerald-600' : (isMedium ? 'bg-amber-50 text-amber-600' : 'bg-red-50 text-red-600');
758
+ const t = translations[currentLang];
759
+
760
+ container.innerHTML += `
761
+ <div class="bg-white p-6 rounded-2xl border border-gray-100 shadow-sm space-y-4">
762
+ <div class="flex justify-between items-start">
763
+ <div>
764
+ <div class="flex items-center gap-3">
765
+ <h3 class="font-bold text-gray-800 text-lg">${item.kpi_name}</h3>
766
+ <span class="text-xs font-bold px-3 py-1 rounded-full ${badgeColor}">${item.status}</span>
767
+ </div>
768
+ <p class="text-xs text-gray-500 mt-1">${item.description}</p>
769
+ </div>
770
+ <div class="flex gap-2 text-gray-400">
771
+ <button class="hover:text-teal-600 p-1"><i data-lucide="edit-2" class="w-4 h-4"></i></button>
772
+ <button class="hover:text-red-600 p-1"><i data-lucide="trash-2" class="w-4 h-4"></i></button>
773
+ </div>
774
+ </div>
775
+
776
+ <div class="grid grid-cols-2 gap-4 text-xs text-gray-500 bg-gray-50 p-3 rounded-xl">
777
+ <div>${t.dept_label}: <span class="font-bold text-gray-700">${item.department}</span></div>
778
+ <div>${t.target_label}: <span class="font-bold text-gray-700">${item.target}%</span></div>
779
+ </div>
780
+
781
+ <div>
782
+ <div class="flex justify-between text-xs mb-1 text-gray-500">
783
+ <span>${t.progress_label}</span>
784
+ <span class="font-bold text-gray-700">${item.latest_value}%</span>
785
+ </div>
786
+ <div class="w-full bg-gray-100 h-2.5 rounded-full overflow-hidden">
787
+ <div class="bg-emerald-500 h-full rounded-full" style="width: ${item.latest_value}%"></div>
788
+ </div>
789
+ </div>
790
+ </div>
791
+ `;
792
+ });
793
+
794
+ lucide.createIcons();
795
+ }
796
+
797
+ function renderPerformanceChart() {
798
+ const ctx = document.getElementById('performanceChart').getContext('2d');
799
+ if (lineChartInstance) lineChartInstance.destroy();
800
+
801
+ if (!currentKpiData || currentKpiData.length === 0) return;
802
+
803
+ const labels = currentKpiData[0].daily_history.map(d => d.date || `Day ${d.day}`);
804
+ const palette = ['#0D9488', '#3B82F6', '#F59E0B', '#EF4444', '#8B5CF6'];
805
+
806
+ const datasets = currentKpiData.map((kpi, idx) => ({
807
+ label: kpi.kpi_name,
808
+ data: kpi.daily_history.map(d => d.value),
809
+ borderColor: palette[idx % palette.length],
810
+ backgroundColor: palette[idx % palette.length],
811
+ tension: 0.3,
812
+ borderWidth: 2,
813
+ pointRadius: 0
814
+ }));
815
+
816
+ lineChartInstance = new Chart(ctx, {
817
+ type: 'line',
818
+ data: { labels: labels, datasets: datasets },
819
+ options: {
820
+ responsive: true,
821
+ maintainAspectRatio: false,
822
+ plugins: { legend: { position: 'bottom' } },
823
+ scales: {
824
+ x: { grid: { display: false } },
825
+ y: { min: 0, max: 100 }
826
+ }
827
+ }
828
+ });
829
+ }
830
+
831
+ function switchTab(tab) {
832
+ if(tab === 'dashboard') {
833
+ document.getElementById('view-dashboard').classList.remove('hidden');
834
+ document.getElementById('view-kpis').classList.add('hidden');
835
+ document.getElementById('btn-dashboard').className = "w-full flex items-center gap-3 px-4 py-3 rounded-xl text-sm font-semibold transition bg-teal-700 text-white shadow-sm";
836
+ document.getElementById('btn-kpis').className = "w-full flex items-center gap-3 px-4 py-3 rounded-xl text-sm font-semibold transition text-gray-600 hover:bg-gray-50";
837
+ } else {
838
+ document.getElementById('view-dashboard').classList.add('hidden');
839
+ document.getElementById('view-kpis').classList.remove('hidden');
840
+ document.getElementById('btn-kpis').className = "w-full flex items-center gap-3 px-4 py-3 rounded-xl text-sm font-semibold transition bg-teal-700 text-white shadow-sm";
841
+ document.getElementById('btn-dashboard').className = "w-full flex items-center gap-3 px-4 py-3 rounded-xl text-sm font-semibold transition text-gray-600 hover:bg-gray-50";
842
+ }
843
+ }
844
+
845
+ function renderAll() {
846
+ updateSummaryCards();
847
+ renderDashboardProgress();
848
+ renderKPIsList();
849
+ renderPerformanceChart();
850
+ lucide.createIcons();
851
+ }
852
+
853
+ loadExternalData();
854
+ </script>
855
+ </body>
856
+ </html>