File size: 7,980 Bytes
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
"""
مكون الشريط الجانبي لنظام واهبي لتحليل العقود والمناقصات
Sidebar component for WAHBI Tender Analysis System
"""

import streamlit as st
import os
from pathlib import Path
import streamlit_option_menu as option_menu
import json

def get_user_info():
    """
    استرجاع معلومات المستخدم الحالي (يُستخدم كمثال بسيط)
    """
    # في بيئة الإنتاج، هذه المعلومات يجب أن تأتي من نظام المصادقة
    return {
        "name": "محمد أحمد",
        "role": "محلل عقود",
        "image": None
    }

def render_sidebar():
    """
    عرض الشريط الجانبي الرئيسي للتطبيق
    """
    with st.sidebar:
        # عرض معلومات المستخدم
        user = get_user_info()
        
        # مربع معلومات المستخدم
        st.markdown(f"""
        <div style="padding: 1rem; background: linear-gradient(135deg, #f0f7ff, #e8f1fb); border-radius: 10px; margin-bottom: 1.5rem; text-align: center;">
            <div style="width: 80px; height: 80px; background: linear-gradient(135deg, #1E88E5, #64B5F6); border-radius: 50%; margin: 0 auto 0.8rem auto; display: flex; justify-content: center; align-items: center; color: white; font-size: 2rem; font-weight: bold;">
                {user["name"][0] if user["name"] else "م"}
            </div>
            <h3 style="margin: 0; font-size: 1.2rem; color: #333;">{user["name"]}</h3>
            <p style="margin: 0; color: #1E88E5; font-size: 0.9rem;">{user["role"]}</p>
        </div>
        """, unsafe_allow_html=True)
        
        # القائمة الرئيسية باستخدام كومبوننت الشريط الجانبي
        selected = option_menu.option_menu(
            menu_title="الوصول السريع",
            options=[
                "الرئيسية", 
                "تحليل العقود", 
                "حاسبة التكاليف",
                "إدارة المشاريع",
                "الخريطة التفاعلية",
                "المساعد الذكي",
                "التقارير",
                "الإعدادات"
            ],
            icons=[
                "house-fill", 
                "file-earmark-text-fill", 
                "calculator-fill",
                "clipboard2-data-fill",
                "geo-alt-fill",
                "robot",
                "bar-chart-fill",
                "gear-fill"
            ],
            menu_icon="list",
            default_index=0,
            styles={
                "container": {"padding": "0!important", "background-color": "transparent", "direction": "rtl"},
                "icon": {"color": "#1E88E5", "font-size": "1rem", "float": "right", "margin-left": "10px"},
                "nav-link": {
                    "font-size": "0.9rem",
                    "text-align": "right",
                    "direction": "rtl",
                    "--hover-color": "#E3F2FD",
                    "margin-bottom": "0.2rem",
                    "padding-right": "15px",
                },
                "nav-link-selected": {"background-color": "#1E88E5", "color": "white", "text-align": "right"},
            }
        )
        
        # تخزين القيمة المحددة في session_state
        st.session_state["sidebar_selected"] = selected
        
        # إظهار حالة الاتصال بقاعدة البيانات وحالة النظام
        st.markdown("""
        <div style="padding: 1rem; background-color: #f0f2f5; border-radius: 10px; margin-top: 1.5rem;">
            <h4 style="margin: 0 0 0.8rem 0; font-size: 1rem; color: #333;">حالة النظام</h4>
            <div style="display: flex; align-items: center; margin-bottom: 0.5rem;">
                <div style="width: 8px; height: 8px; border-radius: 50%; background-color: #4CAF50; margin-left: 0.5rem;"></div>
                <span style="font-size: 0.9rem; color: #666;">قاعدة البيانات متصلة</span>
            </div>
            <div style="display: flex; align-items: center; margin-bottom: 0.5rem;">
                <div style="width: 8px; height: 8px; border-radius: 50%; background-color: #4CAF50; margin-left: 0.5rem;"></div>
                <span style="font-size: 0.9rem; color: #666;">واجهة برمجة التطبيقات</span>
            </div>
            <div style="display: flex; align-items: center;">
                <div style="width: 8px; height: 8px; border-radius: 50%; background-color: #4CAF50; margin-left: 0.5rem;"></div>
                <span style="font-size: 0.9rem; color: #666;">الذكاء الاصطناعي</span>
            </div>
        </div>
        """, unsafe_allow_html=True)
        
        # معلومات النظام وعنوان المشروع
        with st.expander("حول النظام", expanded=False):
            st.markdown("""
            <div style="font-size: 0.9rem; color: #666;">
                <p style="margin-bottom: 0.5rem;">نظام واهبي للذكاء الاصطناعي - إصدار 2.0</p>
                <p style="margin-bottom: 0.5rem;">تحليل العقود والمناقصات</p>
                <p style="margin: 0;">© 2025 جميع الحقوق محفوظة</p>
            </div>
            """, unsafe_allow_html=True)

def get_sidebar_selection():
    """
    الحصول على العنصر المحدد في القائمة الجانبية
    """
    return st.session_state.get("sidebar_selected", "الرئيسية")

def render_module_sidebar(module_name, options=[]):
    """
    عرض شريط جانبي مخصص للوحدة
    
    المعلمات:
        module_name (str): اسم الوحدة
        options (list): قائمة بالخيارات المتاحة في الوحدة
    """
    with st.sidebar:
        # عنوان الوحدة
        st.markdown(f"""
        <h3 style="margin-bottom: 1rem; color: #1E88E5; font-size: 1.2rem; padding-bottom: 0.5rem; border-bottom: 1px solid #eee;">
            {module_name}
        </h3>
        """, unsafe_allow_html=True)
        
        # إذا تم توفير خيارات للوحدة
        if options:
            selected = option_menu.option_menu(
                menu_title=None,
                options=options,
                menu_icon=None,
                default_index=0,
                styles={
                    "container": {"padding": "0!important", "background-color": "transparent", "direction": "rtl"},
                    "icon": {"color": "#1E88E5", "font-size": "1rem", "float": "right", "margin-left": "10px"},
                    "nav-link": {
                        "font-size": "0.9rem",
                        "text-align": "right",
                        "direction": "rtl",
                        "--hover-color": "#E3F2FD",
                        "margin-bottom": "0.2rem",
                        "padding-right": "15px",
                        "padding": "0.5rem"
                    },
                    "nav-link-selected": {"background-color": "#1E88E5", "color": "white", "text-align": "right"},
                }
            )
            
            # تخزين الخيار المحدد
            st.session_state[f"{module_name}_selected"] = selected
            
            return selected
        
        # زر للعودة إلى القائمة الرئيسية
        if st.button("العودة للقائمة الرئيسية", key=f"back_btn_{module_name}"):
            st.session_state["sidebar_selected"] = "الرئيسية"
            st.rerun()

def get_module_selection(module_name):
    """
    الحصول على العنصر المحدد في قائمة الوحدة
    
    المعلمات:
        module_name (str): اسم الوحدة
    """
    return st.session_state.get(f"{module_name}_selected", None)