File size: 48,066 Bytes
25d2b3e
 
 
 
 
 
 
 
 
ae93751
25d2b3e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ae93751
25d2b3e
 
 
ae93751
25d2b3e
ae93751
25d2b3e
ae93751
25d2b3e
 
ae93751
 
25d2b3e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ae93751
 
 
25d2b3e
 
 
 
 
 
 
 
 
 
 
 
ae93751
 
25d2b3e
 
 
 
 
 
 
 
 
 
 
 
ae93751
 
25d2b3e
 
 
 
 
 
 
 
 
 
 
 
ae93751
25d2b3e
 
ae93751
25d2b3e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ae93751
25d2b3e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
نظام واهبي للذكاء الاصطناعي لتحليل العقود والمناقصات
تطبيق Streamlit الرئيسي الذي يجمع جميع الوحدات والمكونات
"""

import os
import sys
import streamlit as st
import pandas as pd
import numpy as np

# تهيئة حالة الجلسة لكل وحدات النظام
if 'page' not in st.session_state:
    st.session_state.page = 'home'
if 'analysis_type' not in st.session_state:
    st.session_state.analysis_type = None
if 'show_document_upload' not in st.session_state:
    st.session_state.show_document_upload = False
if 'report_type' not in st.session_state:
    st.session_state.report_type = None
if 'show_report_form' not in st.session_state:
    st.session_state.show_report_form = False
if 'analysis_result' not in st.session_state:
    st.session_state.analysis_result = None
if 'current_document' not in st.session_state:
    st.session_state.current_document = None
if 'current_document_text' not in st.session_state:
    st.session_state.current_document_text = None
if 'loaded_files' not in st.session_state:
    st.session_state.loaded_files = []
if 'notifications' not in st.session_state:
    st.session_state.notifications = []

# وظيفة لتهيئة حزم NLTK المطلوبة عند بدء التطبيق
def initialize_nltk_resources():
    """تنزيل وتهيئة موارد NLTK المطلوبة"""
    try:
        # محاولة تنزيل حزم NLTK الأساسية
        import nltk
        
        # تحديد المسار المخصص لتنزيل NLTK data
        nltk_data_path = os.path.join(os.path.expanduser("~"), "nltk_data")
        os.makedirs(nltk_data_path, exist_ok=True)
        nltk.data.path.append(nltk_data_path)
        
        # قائمة بالحزم المطلوبة
        required_packages = ['punkt', 'stopwords', 'wordnet', 'omw-1.4']
        for package in required_packages:
            try:
                if package == 'punkt':
                    nltk.data.find('tokenizers/punkt')
                elif package == 'stopwords':
                    nltk.data.find('corpora/stopwords')
                elif package == 'wordnet':
                    nltk.data.find('corpora/wordnet')
                else:
                    nltk.data.find(f'corpora/{package}')
            except LookupError:
                print(f"تنزيل حزمة NLTK: {package}")
                nltk.download(package, download_dir=nltk_data_path, quiet=False)
        
        print("تم تهيئة موارد NLTK بنجاح.")
    except Exception as e:
        print(f"خطأ في تهيئة NLTK: {e}")
        st.error(f"حدث خطأ أثناء تهيئة موارد NLTK: {e}")

# تهيئة موارد NLTK عند بدء التطبيق
initialize_nltk_resources()

# مسار نسبي للملفات الثابتة (للتأكد من العمل في بيئات مختلفة)
def get_static_path(file_path):
    """مسار ملف ثابت يعمل سواء كان التشغيل من المجلد الرئيسي أو من المجلد الفرعي"""
    # قائمة المسارات المحتملة
    possible_paths = [
        # المسار المباشر (في حالة تشغيل التطبيق من نفس المجلد)
        file_path,
        # المسار النسبي من مجلد التطبيق (tender-analysis-system)
        os.path.join(os.path.dirname(__file__), file_path),
        # المسار النسبي من المجلد الأعلى
        os.path.join(os.path.dirname(os.path.dirname(__file__)), "tender-analysis-system", file_path),
    ]
    
    # اختبار كل مسار محتمل
    for path in possible_paths:
        if os.path.exists(path):
            return path
    
    # إذا لم يتم العثور على الملف، إعادة المسار الأصلي
    return file_path

# إعداد إعدادات الصفحة
try:
    st.set_page_config(
        page_title="نظام WAHBi للذكاء الاصطناعي | التعاقدات والمناقصات",
        page_icon="📊",
        layout="wide",
        initial_sidebar_state="expanded"
    )
except Exception as e:
    print(f"خطأ في إعداد الصفحة: {e}")
    # يحدث هذا غالبًا عند استخدام st.set_page_config أكثر من مرة

# استيراد ملفات CSS الجديدة
try:
    # تحديد مسارات الملفات
    main_css_path = get_static_path("utils/css/main.css")
    rtl_css_path = get_static_path("utils/css/rtl.css")
    enhanced_css_path = get_static_path("utils/css/enhanced.css")
    
    # تحميل ملف CSS الرئيسي
    if os.path.exists(main_css_path):
        with open(main_css_path, "r", encoding='utf-8') as f:
            main_css = f.read()
            st.markdown(f"<style>{main_css}</style>", unsafe_allow_html=True)
            print(f"تم تحميل ملف CSS الرئيسي بنجاح من: {main_css_path}")
    else:
        print(f"تعذر العثور على ملف CSS الرئيسي: {main_css_path}")
        
    # تحميل ملف دعم الاتجاه من اليمين إلى اليسار
    if os.path.exists(rtl_css_path):
        with open(rtl_css_path, "r", encoding='utf-8') as f:
            rtl_css = f.read()
            st.markdown(f"<style>{rtl_css}</style>", unsafe_allow_html=True)
            print(f"تم تحميل ملف CSS للتوجيه RTL بنجاح من: {rtl_css_path}")
    else:
        print(f"تعذر العثور على ملف CSS للتوجيه RTL: {rtl_css_path}")
    
    # تحميل ملف التحسينات المتقدمة
    if os.path.exists(enhanced_css_path):
        with open(enhanced_css_path, "r", encoding='utf-8') as f:
            enhanced_css = f.read()
            st.markdown(f"<style>{enhanced_css}</style>", unsafe_allow_html=True)
            print(f"تم تحميل ملف CSS المحسن بنجاح من: {enhanced_css_path}")
    else:
        print(f"تعذر العثور على ملف CSS المحسن: {enhanced_css_path}")
        
except Exception as e:
    st.warning(f"حدث خطأ أثناء تحميل ملفات CSS: {str(e)}")
    print(f"خطأ في تحميل ملفات CSS: {str(e)}")

# إضافة Font Awesome وأي أصول خارجية أخرى
st.markdown("""
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
""", unsafe_allow_html=True)

# إضافة CSS المخصص
st.markdown("""
<style>
    /* تعديل الاتجاه للدعم العربي */
    .css-18e3th9, .css-1d391kg, .stMarkdown, .stTextArea, .stButton, .stTextInput, .stSelectbox, .stRadio {
        direction: rtl;
        text-align: right;
    }
    
    /* تحسين مظهر العناوين */
    h1, h2, h3, h4 {
        color: #1E88E5;
    }
    
    /* تخصيص عنوان التطبيق */
    .app-title {
        font-size: 2.2rem;
        font-weight: bold;
        text-align: center;
        color: #1E88E5;
        margin-bottom: 1rem;
        text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
        background: linear-gradient(90deg, #1976D2, #64B5F6);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
    }
    
    /* تخصيص الشريط الجانبي */
    .sidebar .sidebar-content {
        background-color: #f8f9fa;
    }
    
    /* تخصيص الأقسام */
    .section-card {
        background-color: #f9f9f9;
        border-radius: 10px;
        padding: 20px;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        margin-bottom: 20px;
    }
    
    /* تخصيص الأزرار */
    .stButton>button {
        border-radius: 5px;
        background-color: #1E88E5;
        color: white;
        font-weight: bold;
        border: none;
        padding: 0.5rem 1rem;
        transition: all 0.3s ease;
    }
    
    .stButton>button:hover {
        background-color: #1565C0;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    }
    
    /* تخصيص المؤشرات */
    .indicator {
        padding: 1rem;
        border-radius: 10px;
        background-color: #f5f5f5;
        text-align: center;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    }
    
    .indicator-value {
        font-size: 2rem;
        font-weight: bold;
        margin-bottom: 0.5rem;
    }
    
    .indicator-label {
        font-size: 1rem;
        color: #666;
    }
    
    /* تخصيص البطاقات */
    .card {
        background-color: white;
        border-radius: 10px;
        padding: 15px;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        margin-bottom: 15px;
        border-right: 4px solid #1E88E5;
    }
    
    .card-title {
        font-weight: bold;
        color: #1E88E5;
        margin-bottom: 10px;
    }
    
    .card-metrics {
        display: flex;
        justify-content: space-between;
    }
    
    .card-metric {
        text-align: center;
    }
    
    .card-metric-value {
        font-weight: bold;
        font-size: 1.5rem;
    }
    
    .card-metric-label {
        font-size: 0.8rem;
        color: #666;
    }
</style>
""", unsafe_allow_html=True)

# استيراد المكونات والوحدات
from utils.components.sidebar import render_sidebar
from utils.helpers import create_directory_if_not_exists, get_data_folder

# استيراد وحدات التطبيق
from modules.pricing.pricing_app import PricingApp
from modules.projects.projects_app import ProjectsApp
from modules.resources.resources_app import ResourcesApp
from modules.risk_assessment.risk_assessment_app import RiskAssessmentApp
from modules.project_tracker.tracker_app import TrackerApp
from modules.maps.maps_app import MapsApp
from modules.notifications.notifications_app import NotificationsApp
from modules.voice_narration.voice_narration_app import VoiceNarrationApp
from modules.achievements.achievements_app import AchievementsApp
from modules.ai_finetuning.finetuning_app import FinetuningApp
from modules.document_comparison.comparison_app import DocumentComparisonApp

# إنشاء مجلدات البيانات الضرورية
create_directory_if_not_exists(get_data_folder())
create_directory_if_not_exists(os.path.join(get_data_folder(), "projects"))
create_directory_if_not_exists(os.path.join(get_data_folder(), "documents"))
create_directory_if_not_exists(os.path.join(get_data_folder(), "analysis"))

def main():
    """الدالة الرئيسية للتطبيق"""
    
    # تقديم الشريط الجانبي وتلقي الوحدة المختارة
    selected_module = render_sidebar()
    
    # إذا كان المستخدم غير مصرح له، قم بإظهار شاشة تسجيل الدخول
    if "is_authenticated" in st.session_state and not st.session_state.is_authenticated:
        render_login_screen()
        return
    
    # إظهار الوحدة المختارة
    if selected_module == "الرئيسية":
        render_homepage()
        
    elif selected_module == "إدارة المشاريع":
        projects_app = ProjectsApp()
        projects_app.render()
        
    elif selected_module == "التسعير المتكاملة":
        pricing_app = PricingApp()
        pricing_app.render()
        
    elif selected_module == "الموارد والتكاليف":
        resources_app = ResourcesApp()
        resources_app.render()
        
    elif selected_module == "تحليل المستندات":
        # تقديم واجهة تحليل المستندات
        render_document_analysis()
        
    elif selected_module == "مقارنة المستندات":
        # تقديم واجهة مقارنة المستندات
        comparison_app = DocumentComparisonApp()
        comparison_app.render()
        
    elif selected_module == "تقييم مخاطر العقود":
        risk_app = RiskAssessmentApp()
        risk_app.render()
        
    elif selected_module == "التقارير والتحليلات":
        # تقديم واجهة التقارير والتحليلات
        render_reports_and_analytics()
        
    elif selected_module == "متتبع حالة المشروع":
        tracker_app = TrackerApp()
        tracker_app.render()
        
    elif selected_module == "خريطة المشاريع":
        maps_app = MapsApp()
        maps_app.render()
        
    elif selected_module == "نظام الإشعارات":
        notifications_app = NotificationsApp()
        notifications_app.render()
        
    elif selected_module == "الترجمة الصوتية":
        voice_app = VoiceNarrationApp()
        voice_app.render()
        
    elif selected_module == "نظام الإنجازات":
        achievements_app = AchievementsApp()
        achievements_app.render()
        
    elif selected_module == "المساعد الذكي":
        # تقديم واجهة المساعد الذكي
        render_ai_assistant()
        
    elif selected_module == "ضبط نماذج الذكاء الاصطناعي":
        finetuning_app = FinetuningApp()
        finetuning_app.render()
        
    else:
        st.error("الوحدة المطلوبة غير موجودة")


def render_login_screen():
    """عرض شاشة تسجيل الدخول"""
    st.markdown("<h1 class='app-title'>نظام WAHBi للذكاء الاصطناعي</h1>", unsafe_allow_html=True)
    
    st.markdown("""
    <div class="section-card">
        <h2>تسجيل الدخول</h2>
        <p>يرجى إدخال بيانات الاعتماد الخاصة بك للوصول إلى النظام.</p>
    </div>
    """, unsafe_allow_html=True)
    
    col1, col2, col3 = st.columns([1, 2, 1])
    
    with col2:
        username = st.text_input("اسم المستخدم")
        password = st.text_input("كلمة المرور", type="password")
        
        if st.button("تسجيل الدخول"):
            # تنفيذ منطق المصادقة
            if username == "admin" and password == "admin":  # بيانات اعتماد مؤقتة للتطوير
                st.session_state.is_authenticated = True
                st.session_state.user_info = {
                    "id": 1,
                    "username": "admin",
                    "full_name": "مدير النظام",
                    "email": "[email protected]",
                    "role": "مدير",
                    "department": "الإدارة",
                    "last_login": "2023-01-01 09:00:00"
                }
                st.rerun()
            else:
                st.error("اسم المستخدم أو كلمة المرور غير صحيحة")
    
    st.markdown("""
    <div style="text-align: center; margin-top: 50px; color: #666;">
        <p>نظام WAHBi للذكاء الاصطناعي © 2025 شركة شبه الجزيرة للمقاولات</p>
        <p>جميع الحقوق محفوظة</p>
    </div>
    """, unsafe_allow_html=True)


def render_homepage():
    """عرض الصفحة الرئيسية للتطبيق"""
    st.markdown("<h1 class='app-title'>نظام WAHBi للذكاء الاصطناعي</h1>", unsafe_allow_html=True)
    st.markdown("<div style='text-align: center; margin-bottom: 20px;'>نظام متكامل لتحليل العقود والمناقصات باستخدام تقنيات الذكاء الاصطناعي المتقدمة</div>", unsafe_allow_html=True)
    
    # عرض مؤشرات الأداء الرئيسية
    col1, col2, col3, col4 = st.columns(4)
    
    with col1:
        st.markdown("""
        <div class="indicator">
            <div class="indicator-value" style="color: #1E88E5;">24</div>
            <div class="indicator-label">المناقصات النشطة</div>
        </div>
        """, unsafe_allow_html=True)
    
    with col2:
        st.markdown("""
        <div class="indicator">
            <div class="indicator-value" style="color: #43A047;">8</div>
            <div class="indicator-label">مشاريع قيد التنفيذ</div>
        </div>
        """, unsafe_allow_html=True)
    
    with col3:
        st.markdown("""
        <div class="indicator">
            <div class="indicator-value" style="color: #FB8C00;">12</div>
            <div class="indicator-label">مستندات قيد التحليل</div>
        </div>
        """, unsafe_allow_html=True)
    
    with col4:
        st.markdown("""
        <div class="indicator">
            <div class="indicator-value" style="color: #E53935;">5</div>
            <div class="indicator-label">تنبيهات تتطلب الاهتمام</div>
        </div>
        """, unsafe_allow_html=True)
    
    # عرض المشاريع الأخيرة والوصول السريع
    col1, col2 = st.columns([2, 1])
    
    with col1:
        st.markdown("### المناقصات الأخيرة")
        
        st.markdown("""
        <div class="card">
            <div class="card-title">إنشاء طريق سريع بمنطقة الرياض</div>
            <div>رقم المناقصة: TR-2025-134</div>
            <div>الجهة المالكة: وزارة النقل</div>
            <div>تاريخ الإغلاق: 15 أبريل 2025</div>
            <div class="card-metrics" style="margin-top: 10px;">
                <div class="card-metric">
                    <div class="card-metric-value" style="color: #4CAF50;">85%</div>
                    <div class="card-metric-label">نسبة الإنجاز</div>
                </div>
                <div class="card-metric">
                    <div class="card-metric-value" style="color: #FFC107;">متوسطة</div>
                    <div class="card-metric-label">المخاطر</div>
                </div>
                <div class="card-metric">
                    <div class="card-metric-value" style="color: #2196F3;">مرتفعة</div>
                    <div class="card-metric-label">الأولوية</div>
                </div>
            </div>
        </div>
        
        <div class="card">
            <div class="card-title">تطوير شبكة الصرف الصحي بالمنطقة الشرقية</div>
            <div>رقم المناقصة: WS-2025-089</div>
            <div>الجهة المالكة: وزارة المياه</div>
            <div>تاريخ الإغلاق: 22 أبريل 2025</div>
            <div class="card-metrics" style="margin-top: 10px;">
                <div class="card-metric">
                    <div class="card-metric-value" style="color: #4CAF50;">62%</div>
                    <div class="card-metric-label">نسبة الإنجاز</div>
                </div>
                <div class="card-metric">
                    <div class="card-metric-value" style="color: #F44336;">مرتفعة</div>
                    <div class="card-metric-label">المخاطر</div>
                </div>
                <div class="card-metric">
                    <div class="card-metric-value" style="color: #2196F3;">مرتفعة</div>
                    <div class="card-metric-label">الأولوية</div>
                </div>
            </div>
        </div>
        
        <div class="card">
            <div class="card-title">بناء 3 مدارس بمنطقة مكة المكرمة</div>
            <div>رقم المناقصة: ED-2025-112</div>
            <div>الجهة المالكة: وزارة التعليم</div>
            <div>تاريخ الإغلاق: 5 مايو 2025</div>
            <div class="card-metrics" style="margin-top: 10px;">
                <div class="card-metric">
                    <div class="card-metric-value" style="color: #4CAF50;">38%</div>
                    <div class="card-metric-label">نسبة الإنجاز</div>
                </div>
                <div class="card-metric">
                    <div class="card-metric-value" style="color: #4CAF50;">منخفضة</div>
                    <div class="card-metric-label">المخاطر</div>
                </div>
                <div class="card-metric">
                    <div class="card-metric-value" style="color: #FFC107;">متوسطة</div>
                    <div class="card-metric-label">الأولوية</div>
                </div>
            </div>
        </div>
        """, unsafe_allow_html=True)
    
    with col2:
        st.markdown("### الوصول السريع")
        
        st.markdown("""
        <div style="display: grid; gap: 10px;">
            <button style="background-color: #1E88E5; color: white; border: none; border-radius: 5px; padding: 10px; text-align: right; cursor: pointer; font-weight: bold;">
                <i class="fas fa-file-alt" style="margin-left: 10px;"></i> تحليل مستند جديد
            </button>
            
            <button style="background-color: #43A047; color: white; border: none; border-radius: 5px; padding: 10px; text-align: right; cursor: pointer; font-weight: bold;">
                <i class="fas fa-calculator" style="margin-left: 10px;"></i> حساب تكاليف مشروع
            </button>
            
            <button style="background-color: #FB8C00; color: white; border: none; border-radius: 5px; padding: 10px; text-align: right; cursor: pointer; font-weight: bold;">
                <i class="fas fa-exclamation-triangle" style="margin-left: 10px;"></i> تقييم مخاطر العقد
            </button>
            
            <button style="background-color: #8E24AA; color: white; border: none; border-radius: 5px; padding: 10px; text-align: right; cursor: pointer; font-weight: bold;">
                <i class="fas fa-map-marker-alt" style="margin-left: 10px;"></i> استعراض خريطة المشاريع
            </button>
            
            <button style="background-color: #546E7A; color: white; border: none; border-radius: 5px; padding: 10px; text-align: right; cursor: pointer; font-weight: bold;">
                <i class="fas fa-chart-bar" style="margin-left: 10px;"></i> إنشاء تقارير تحليلية
            </button>
        </div>
        """, unsafe_allow_html=True)
        
        st.markdown("### آخر التنبيهات")
        
        st.markdown("""
        <div style="background-color: #FFEBEE; border-right: 3px solid #E53935; padding: 10px; margin-bottom: 10px; border-radius: 5px;">
            <div style="font-weight: bold; color: #B71C1C;">انتهاء موعد تقديم المناقصة</div>
            <div style="font-size: 0.9rem;">مشروع إنشاء الطريق السريع - متبقي 3 أيام</div>
        </div>
        
        <div style="background-color: #FFF8E1; border-right: 3px solid #FFA000; padding: 10px; margin-bottom: 10px; border-radius: 5px;">
            <div style="font-weight: bold; color: #FF6F00;">تغيير في شروط المناقصة</div>
            <div style="font-size: 0.9rem;">تم تحديث مستندات مشروع شبكة الصرف الصحي</div>
        </div>
        
        <div style="background-color: #E8F5E9; border-right: 3px solid #43A047; padding: 10px; margin-bottom: 10px; border-radius: 5px;">
            <div style="font-weight: bold; color: #2E7D32;">إكمال تحليل المستند</div>
            <div style="font-size: 0.9rem;">اكتمل تحليل عقد بناء المدارس بنجاح</div>
        </div>
        """, unsafe_allow_html=True)
    
    # معلومات حول النظام
    st.markdown("---")
    
    st.markdown("""
    <div class="section-card">
        <h3>حول النظام</h3>
        <p>نظام WAHBi للذكاء الاصطناعي هو نظام متكامل لتحليل العقود والمناقصات وإدارة المشاريع، مصمم خصيصاً لشركات المقاولات والبناء. يستخدم النظام تقنيات الذكاء الاصطناعي المتقدمة لتحليل المستندات واستخراج المعلومات المهمة وتقييم المخاطر ودعم اتخاذ القرار.</p>
    </div>
    """, unsafe_allow_html=True)
    
    # معلومات الشركة
    st.markdown("""
    <div style="text-align: center; margin-top: 30px; color: #666;">
        <p>هذا النظام يعمل لشركة شبه الجزيرة للمقاولات</p>
        <p>جميع الحقوق محفوظة 2025</p>
    </div>
    """, unsafe_allow_html=True)


def render_document_analysis():
    """عرض واجهة تحليل المستندات"""
    st.markdown("<h1 class='app-title'>تحليل المستندات</h1>", unsafe_allow_html=True)
    
    st.markdown("""
    <div class="section-card">
        <p>استخدم هذه الوحدة لتحليل مستندات العقود والمناقصات باستخدام تقنيات الذكاء الاصطناعي المتقدمة. 
        يمكنك تحميل المستندات بتنسيقات PDF أو Word وسيقوم النظام بتحليلها واستخراج المعلومات المهمة مثل الشروط والتكاليف والمخاطر والتزاماتك كمقاول.</p>
    </div>
    """, unsafe_allow_html=True)
    
    # أدوات التحليل
    st.markdown("### أدوات التحليل:", unsafe_allow_html=True)
    
    col1, col2, col3 = st.columns(3)
    
    with col1:
        st.markdown("""
        <div class="card">
            <div class="card-title">تحليل العقد الشامل</div>
            <p>تحليل شامل للعقد باستخدام Claude AI لاستخراج جميع البنود والشروط والالتزامات والمواعيد النهائية.</p>
        </div>
        """, unsafe_allow_html=True)
        
        if st.button("تحليل جديد", key="btn_complete_analysis"):
            # هنا سيتم استدعاء وحدة تحليل العقد الشامل
            st.session_state.analysis_type = "complete"
            st.session_state.show_document_upload = True
            st.rerun()
    
    with col2:
        st.markdown("""
        <div class="card">
            <div class="card-title">تحليل جداول الكميات</div>
            <p>تحليل متخصص لجداول الكميات (BOQ) لاستخراج قوائم المواد والكميات والأسعار والتكاليف الإجمالية.</p>
        </div>
        """, unsafe_allow_html=True)
        
        if st.button("تحليل جديد", key="btn_boq_analysis"):
            # هنا سيتم استدعاء وحدة تحليل جداول الكميات
            st.session_state.analysis_type = "boq"
            st.session_state.show_document_upload = True
            st.rerun()
    
    with col3:
        st.markdown("""
        <div class="card">
            <div class="card-title">تحليل الشروط والأحكام</div>
            <p>تحليل متخصص للشروط والأحكام في العقد لتحديد الشروط الغير عادية أو المقيدة والمخاطر القانونية.</p>
        </div>
        """, unsafe_allow_html=True)
        
        if st.button("تحليل جديد", key="btn_terms_analysis"):
            # هنا سيتم استدعاء وحدة تحليل الشروط والأحكام
            st.session_state.analysis_type = "terms"
            st.session_state.show_document_upload = True
            st.rerun()
    
    # التحليلات الأخيرة
    st.markdown("### التحليلات الأخيرة")
    
    st.markdown("""
    <table style="width: 100%; border-collapse: collapse; margin-top: 20px;">
        <thead>
            <tr style="background-color: #f5f5f5;">
                <th style="padding: 12px; text-align: right; border-bottom: 2px solid #ddd;">اسم المستند</th>
                <th style="padding: 12px; text-align: right; border-bottom: 2px solid #ddd;">نوع التحليل</th>
                <th style="padding: 12px; text-align: right; border-bottom: 2px solid #ddd;">تاريخ التحليل</th>
                <th style="padding: 12px; text-align: right; border-bottom: 2px solid #ddd;">الحالة</th>
                <th style="padding: 12px; text-align: right; border-bottom: 2px solid #ddd;">الإجراءات</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td style="padding: 12px; text-align: right; border-bottom: 1px solid #ddd;">عقد إنشاء طريق سريع.pdf</td>
                <td style="padding: 12px; text-align: right; border-bottom: 1px solid #ddd;">تحليل شامل</td>
                <td style="padding: 12px; text-align: right; border-bottom: 1px solid #ddd;">2023-03-25</td>
                <td style="padding: 12px; text-align: right; border-bottom: 1px solid #ddd;"><span style="color: #4CAF50; font-weight: bold;">مكتمل</span></td>
                <td style="padding: 12px; text-align: right; border-bottom: 1px solid #ddd;">
                    <button style="background-color: #1E88E5; color: white; border: none; border-radius: 3px; padding: 5px 10px; margin-left: 5px; cursor: pointer;">عرض</button>
                    <button style="background-color: #78909C; color: white; border: none; border-radius: 3px; padding: 5px 10px; cursor: pointer;">تنزيل التقرير</button>
                </td>
            </tr>
            <tr style="background-color: #f9f9f9;">
                <td style="padding: 12px; text-align: right; border-bottom: 1px solid #ddd;">جداول كميات مشروع صرف صحي.xlsx</td>
                <td style="padding: 12px; text-align: right; border-bottom: 1px solid #ddd;">تحليل جداول الكميات</td>
                <td style="padding: 12px; text-align: right; border-bottom: 1px solid #ddd;">2023-03-23</td>
                <td style="padding: 12px; text-align: right; border-bottom: 1px solid #ddd;"><span style="color: #4CAF50; font-weight: bold;">مكتمل</span></td>
                <td style="padding: 12px; text-align: right; border-bottom: 1px solid #ddd;">
                    <button style="background-color: #1E88E5; color: white; border: none; border-radius: 3px; padding: 5px 10px; margin-left: 5px; cursor: pointer;">عرض</button>
                    <button style="background-color: #78909C; color: white; border: none; border-radius: 3px; padding: 5px 10px; cursor: pointer;">تنزيل التقرير</button>
                </td>
            </tr>
            <tr>
                <td style="padding: 12px; text-align: right; border-bottom: 1px solid #ddd;">شروط وأحكام عقد بناء مدارس.pdf</td>
                <td style="padding: 12px; text-align: right; border-bottom: 1px solid #ddd;">تحليل الشروط والأحكام</td>
                <td style="padding: 12px; text-align: right; border-bottom: 1px solid #ddd;">2023-03-20</td>
                <td style="padding: 12px; text-align: right; border-bottom: 1px solid #ddd;"><span style="color: #4CAF50; font-weight: bold;">مكتمل</span></td>
                <td style="padding: 12px; text-align: right; border-bottom: 1px solid #ddd;">
                    <button style="background-color: #1E88E5; color: white; border: none; border-radius: 3px; padding: 5px 10px; margin-left: 5px; cursor: pointer;">عرض</button>
                    <button style="background-color: #78909C; color: white; border: none; border-radius: 3px; padding: 5px 10px; cursor: pointer;">تنزيل التقرير</button>
                </td>
            </tr>
            <tr style="background-color: #f9f9f9;">
                <td style="padding: 12px; text-align: right; border-bottom: 1px solid #ddd;">ملحق عقد مشروع كباري.pdf</td>
                <td style="padding: 12px; text-align: right; border-bottom: 1px solid #ddd;">تحليل شامل</td>
                <td style="padding: 12px; text-align: right; border-bottom: 1px solid #ddd;">2023-03-18</td>
                <td style="padding: 12px; text-align: right; border-bottom: 1px solid #ddd;"><span style="color: #FB8C00; font-weight: bold;">قيد المعالجة</span></td>
                <td style="padding: 12px; text-align: right; border-bottom: 1px solid #ddd;">
                    <button style="background-color: #9E9E9E; color: white; border: none; border-radius: 3px; padding: 5px 10px; margin-left: 5px; cursor: pointer;" disabled>عرض</button>
                    <button style="background-color: #9E9E9E; color: white; border: none; border-radius: 3px; padding: 5px 10px; cursor: pointer;" disabled>تنزيل التقرير</button>
                </td>
            </tr>
        </tbody>
    </table>
    """, unsafe_allow_html=True)
    
    # إحصائيات التحليل
    st.markdown("### إحصائيات التحليل")
    
    col1, col2 = st.columns(2)
    
    with col1:
        st.markdown("""
        <div style="padding: 20px; background-color: #f5f5f5; border-radius: 10px; height: 100%;">
            <h4 style="color: #1E88E5; margin-bottom: 15px;">توزيع أنواع المستندات</h4>
            <div style="margin-bottom: 15px;">
                <div style="display: flex; justify-content: space-between; margin-bottom: 5px;">
                    <span>عقود ومناقصات</span>
                    <span>45%</span>
                </div>
                <div style="height: 10px; background-color: #e0e0e0; border-radius: 5px;">
                    <div style="height: 100%; width: 45%; background-color: #1E88E5; border-radius: 5px;"></div>
                </div>
            </div>
            
            <div style="margin-bottom: 15px;">
                <div style="display: flex; justify-content: space-between; margin-bottom: 5px;">
                    <span>جداول كميات</span>
                    <span>30%</span>
                </div>
                <div style="height: 10px; background-color: #e0e0e0; border-radius: 5px;">
                    <div style="height: 100%; width: 30%; background-color: #43A047; border-radius: 5px;"></div>
                </div>
            </div>
            
            <div style="margin-bottom: 15px;">
                <div style="display: flex; justify-content: space-between; margin-bottom: 5px;">
                    <span>شروط وأحكام</span>
                    <span>15%</span>
                </div>
                <div style="height: 10px; background-color: #e0e0e0; border-radius: 5px;">
                    <div style="height: 100%; width: 15%; background-color: #FB8C00; border-radius: 5px;"></div>
                </div>
            </div>
            
            <div style="margin-bottom: 15px;">
                <div style="display: flex; justify-content: space-between; margin-bottom: 5px;">
                    <span>مستندات أخرى</span>
                    <span>10%</span>
                </div>
                <div style="height: 10px; background-color: #e0e0e0; border-radius: 5px;">
                    <div style="height: 100%; width: 10%; background-color: #78909C; border-radius: 5px;"></div>
                </div>
            </div>
        </div>
        """, unsafe_allow_html=True)
    
    with col2:
        st.markdown("""
        <div style="padding: 20px; background-color: #f5f5f5; border-radius: 10px; height: 100%;">
            <h4 style="color: #1E88E5; margin-bottom: 15px;">إحصائيات التحليل الشهرية</h4>
            <div style="display: flex; justify-content: space-between; text-align: center;">
                <div>
                    <div style="font-size: 2rem; font-weight: bold; color: #1E88E5;">42</div>
                    <div style="color: #666;">مستند تم تحليله</div>
                </div>
                <div>
                    <div style="font-size: 2rem; font-weight: bold; color: #43A047;">38</div>
                    <div style="color: #666;">تحليل ناجح</div>
                </div>
                <div>
                    <div style="font-size: 2rem; font-weight: bold; color: #FB8C00;">4</div>
                    <div style="color: #666;">تحليل غير مكتمل</div>
                </div>
            </div>
            
            <h4 style="color: #1E88E5; margin-top: 20px; margin-bottom: 15px;">متوسط وقت المعالجة</h4>
            <div style="display: flex; align-items: center; margin-bottom: 10px;">
                <div style="width: 150px;">تحليل شامل:</div>
                <div style="flex-grow: 1; height: 8px; background-color: #e0e0e0; border-radius: 5px;">
                    <div style="height: 100%; width: 80%; background-color: #1E88E5; border-radius: 5px;"></div>
                </div>
                <div style="width: 50px; text-align: left; padding-left: 10px;">2:30</div>
            </div>
            
            <div style="display: flex; align-items: center; margin-bottom: 10px;">
                <div style="width: 150px;">جداول الكميات:</div>
                <div style="flex-grow: 1; height: 8px; background-color: #e0e0e0; border-radius: 5px;">
                    <div style="height: 100%; width: 50%; background-color: #43A047; border-radius: 5px;"></div>
                </div>
                <div style="width: 50px; text-align: left; padding-left: 10px;">1:45</div>
            </div>
            
            <div style="display: flex; align-items: center;">
                <div style="width: 150px;">الشروط والأحكام:</div>
                <div style="flex-grow: 1; height: 8px; background-color: #e0e0e0; border-radius: 5px;">
                    <div style="height: 100%; width: 60%; background-color: #FB8C00; border-radius: 5px;"></div>
                </div>
                <div style="width: 50px; text-align: left; padding-left: 10px;">2:00</div>
            </div>
        </div>
        """, unsafe_allow_html=True)


def render_reports_and_analytics():
    """عرض واجهة التقارير والتحليلات"""
    st.markdown("<h1 class='app-title'>التقارير والتحليلات</h1>", unsafe_allow_html=True)
    
    st.markdown("""
    <div class="section-card">
        <p>استخدم هذه الوحدة لإنشاء تقارير تحليلية متقدمة عن المشاريع والمناقصات والأداء العام. 
        يوفر النظام رؤى وتحليلات متعمقة تساعدك على فهم أداء مشاريعك وتحسين عمليات صنع القرار.</p>
    </div>
    """, unsafe_allow_html=True)
    
    # أنواع التقارير
    st.markdown("### أنواع التقارير")
    
    col1, col2, col3 = st.columns(3)
    
    with col1:
        st.markdown("""
        <div class="card">
            <div class="card-title">تقارير المشاريع</div>
            <p>تقارير تفصيلية عن حالة المشاريع وتقدمها ومؤشرات الأداء الرئيسية والمشكلات المحتملة.</p>
        </div>
        """, unsafe_allow_html=True)
        
        if st.button("إنشاء تقرير", key="btn_project_report"):
            # هنا سيتم استدعاء وحدة إنشاء تقارير المشاريع
            st.session_state.report_type = "project"
            st.session_state.show_report_form = True
            st.rerun()
    
    with col2:
        st.markdown("""
        <div class="card">
            <div class="card-title">تقارير الأداء المالي</div>
            <p>تحليل مالي للمشاريع يتضمن الإيرادات والتكاليف والأرباح والتدفقات النقدية والانحرافات عن الميزانية.</p>
        </div>
        """, unsafe_allow_html=True)
        
        if st.button("إنشاء تقرير", key="btn_financial_report"):
            # هنا سيتم استدعاء وحدة إنشاء تقارير الأداء المالي
            st.session_state.report_type = "financial"
            st.session_state.show_report_form = True
            st.rerun()
    
    with col3:
        st.markdown("""
        <div class="card">
            <div class="card-title">تقارير المناقصات</div>
            <p>تحليل شامل للمناقصات النشطة والمنتهية ونسب الفوز والمنافسين ومقارنة الأسعار.</p>
        </div>
        """, unsafe_allow_html=True)
        
        if st.button("إنشاء تقرير", key="btn_tender_report"):
            # هنا سيتم استدعاء وحدة إنشاء تقارير المناقصات
            st.session_state.report_type = "tender"
            st.session_state.show_report_form = True
            st.rerun()
    
    # لوحة البيانات
    st.markdown("### لوحة البيانات التنفيذية")
    
    col1, col2 = st.columns([2, 1])
    
    with col1:
        st.markdown("#### أداء المشاريع حسب القطاع")
        
        # إنشاء بيانات تجريبية للرسم البياني
        sectors = ['البنية التحتية', 'السكني', 'التعليمي', 'الصحي', 'النقل']
        performance = [85, 72, 64, 90, 78]
        
        # إنشاء رسم بياني شريطي
        chart_data = pd.DataFrame({'القطاع': sectors, 'الأداء (%)': performance})
        st.bar_chart(chart_data.set_index('القطاع'), use_container_width=True)
        
        # عرض بيان توضيحي
        st.caption("مقارنة أداء المشاريع عبر القطاعات المختلفة (نسبة الإنجاز)")
    
    with col2:
        st.markdown("#### المؤشرات الرئيسية")
        
        # نسبة المشاريع المتأخرة
        st.markdown("##### نسبة المشاريع المتأخرة")
        delayed_projects = 15
        st.progress(delayed_projects / 100)
        st.markdown(f"<p style='text-align: center; color: #F44336; font-weight: bold; margin-top: -10px;'>{delayed_projects}%</p>", unsafe_allow_html=True)
        
        # متوسط هامش الربح
        st.markdown("##### متوسط هامش الربح")
        profit_margin = 22
        st.progress(profit_margin / 100)
        st.markdown(f"<p style='text-align: center; color: #4CAF50; font-weight: bold; margin-top: -10px;'>{profit_margin}%</p>", unsafe_allow_html=True)
        
        # معدل نجاح المناقصات
        st.markdown("##### معدل نجاح المناقصات")
        tender_success = 35
        st.progress(tender_success / 100)
        st.markdown(f"<p style='text-align: center; color: #2196F3; font-weight: bold; margin-top: -10px;'>{tender_success}%</p>", unsafe_allow_html=True)
    
    # تقارير الأداء
    st.markdown("### تقارير الأداء الأخيرة")
    
    # التقرير الأول
    with st.container():
        col1, col2 = st.columns([3, 1])
        
        with col1:
            st.markdown("#### التقرير الشهري لمشاريع الربع الأول 2025")
            st.markdown("تقرير شامل يوضح أداء جميع المشاريع النشطة خلال الربع الأول من عام 2025، بما في ذلك تحليل التكاليف والجدول الزمني والمخاطر.")
            st.markdown("**تاريخ الإنشاء:** 15 مارس 2025")
        
        with col2:
            st.markdown("<br>", unsafe_allow_html=True)  # إضافة مسافة
            col2_1, col2_2 = st.columns(2)
            with col2_1:
                if st.button("عرض", key="view_report1"):
                    st.session_state.view_report = "quarterly_q1_2025"
                    st.session_state.show_report_viewer = True
            with col2_2:
                if st.button("تنزيل", key="download_report1"):
                    st.info("جاري تحميل التقرير...")
        
        st.markdown("---")
    
    # التقرير الثاني
    with st.container():
        col1, col2 = st.columns([3, 1])
        
        with col1:
            st.markdown("#### تحليل أداء المناقصات 2024-2025")
            st.markdown("تحليل مقارن لنتائج المناقصات بين عامي 2024 و 2025، يوضح التحسن في معدلات النجاح وتحليل أسباب الخسارة وفرص التحسين.")
            st.markdown("**تاريخ الإنشاء:** 28 فبراير 2025")
        
        with col2:
            st.markdown("<br>", unsafe_allow_html=True)  # إضافة مسافة
            col2_1, col2_2 = st.columns(2)
            with col2_1:
                if st.button("عرض", key="view_report2"):
                    st.session_state.view_report = "tenders_analysis_2024_2025"
                    st.session_state.show_report_viewer = True
            with col2_2:
                if st.button("تنزيل", key="download_report2"):
                    st.info("جاري تحميل التقرير...")
        
        st.markdown("---")
    
    # التقرير الثالث
    with st.container():
        col1, col2 = st.columns([3, 1])
        
        with col1:
            st.markdown("#### تقرير المخاطر المالية للمشاريع الجارية")
            st.markdown("تقرير تفصيلي حول المخاطر المالية للمشاريع الجارية، بما في ذلك تحليل التدفقات النقدية والمستحقات المتأخرة والمطالبات المحتملة.")
            st.markdown("**تاريخ الإنشاء:** 10 فبراير 2025")
        
        with col2:
            st.markdown("<br>", unsafe_allow_html=True)  # إضافة مسافة
            col2_1, col2_2 = st.columns(2)
            with col2_1:
                if st.button("عرض", key="view_report3"):
                    st.session_state.view_report = "financial_risks_2025"
                    st.session_state.show_report_viewer = True
            with col2_2:
                if st.button("تنزيل", key="download_report3"):
                    st.info("جاري تحميل التقرير...")


def render_ai_assistant():
    """عرض واجهة المساعد الذكي باستخدام المكون الجديد"""
    try:
        from modules.ai_assistant.assistant_app import AssistantApp
        
        # عرض العنوان والوصف
        st.markdown("<h1 class='app-title'>المساعد الذكي</h1>", unsafe_allow_html=True)
        
        st.markdown("""
        <div class="section-card">
            <p>المساعد الذكي هو واجهة تفاعلية مدعومة بتقنيات الذكاء الاصطناعي لمساعدتك في جميع أنشطة إدارة المشاريع والعقود. 
            يمكنك طرح أسئلة بلغتك الطبيعية والحصول على إجابات فورية، أو طلب مساعدة في مهام محددة مثل تحليل بنود العقد أو تقدير التكاليف.</p>
        </div>
        """, unsafe_allow_html=True)
        
        # استدعاء المساعد الذكي الجديد
        ai_assistant = AssistantApp()
        ai_assistant.render()
        
    except Exception as e:
        st.error(f"حدث خطأ في تحميل المساعد الذكي: {str(e)}")
        st.markdown("""
        <div class="error-card">
            <h3>😞 عذراً، واجهنا مشكلة في تحميل المساعد الذكي</h3>
            <p>يرجى المحاولة مرة أخرى لاحقاً أو التواصل مع فريق الدعم الفني إذا استمرت المشكلة.</p>
        </div>
        """, unsafe_allow_html=True)


# تشغيل التطبيق عند تنفيذ الملف مباشرة
if __name__ == "__main__":
    main()