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
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
import streamlit as st
import pandas as pd
from datetime import date, datetime
import os
import altair as alt
import smtplib
from email.mime.text import MIMEText
import base64

# import streamlit as st
# import pandas as pd
from docx import Document
# import smtplib
# from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
# from email.mime.base import MIMEBase
from email import encoders
import os

# import smtplib
# from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

# File to store project data
PROJECT_DATA_FILE = 'projects.csv'
TASK_DATA_FILE = 'tasks.csv'
TEAM_DATA_FILE = 'team_members.csv'

st.title("Projects Management Tool")
# st.title("Developed By Mansoor Sarookh, CS Student at GPGC Swabi")

# Load project data
def load_projects():
    try:
        return pd.read_csv(PROJECT_DATA_FILE)
    except FileNotFoundError:
        return pd.DataFrame(columns=["Project Name", "Description", "Start Date", "End Date", "Priority", "Status", "Progress", "Budget", "Tags"])

# Save project data
def save_projects(df):
    df.to_csv(PROJECT_DATA_FILE, index=False)

# Load tasks
def load_tasks():
    try:
        return pd.read_csv(TASK_DATA_FILE)
    except FileNotFoundError:
        return pd.DataFrame(columns=["Project Name", "Task Name", "Deadline", "Status", "Assigned To"])

# Save tasks
def save_tasks(df):
    df.to_csv(TASK_DATA_FILE, index=False)

# Load team members
def load_team():
    try:
        return pd.read_csv(TEAM_DATA_FILE)
    except FileNotFoundError:
        return pd.DataFrame(columns=["Project Name", "Member Name", "Role"])

# Save team members
def save_team(df):
    df.to_csv(TEAM_DATA_FILE, index=False)






import streamlit as st

def home():
    st.title("Welcome to the Project Management Tool")
    st.markdown("""
    ## About the Tool
    The **Project Management Tool** is a comprehensive solution built specifically for **Admins** and **Project Managers** in small software houses.
                - It **streamlines workflows, enhances productivity, and ensures smooth project execution.**

    ### Key Features:
    - **Add, Edit, and Delete Projects:** Easily create, modify, or remove projects.
    - **Task Management:** Assign and organize tasks efficiently.
    - **High Priority & Deadlines:** Focus on critical tasks to meet deadlines.
    - **Project Progress Tracking:** Monitor project progress in real-time.
    - **Team Collaboration:** Facilitate communication and teamwork.
    - **Analytics & Reports:** Generate performance and resource utilization reports.
    - **Calendar View:** Plan schedules with an intuitive calendar format.
    - **Search and Filter Projects:** Quickly find projects using advanced search tools.
    - **Budget Tracking:** Manage budgets effectively to avoid overspending.
    - **Comments and Notes:** Document critical details and discussions.
    - **Prioritization Metrics:** Focus on the most impactful tasks.
    - **Gantt Chart Visualization:** Gain a clear view of timelines with Gantt charts.
    - **Resource Management:** Allocate resources optimally across projects.
    - **Risk Management:** Identify and mitigate potential risks proactively.

    ### Why Choose This Tool?
    - Specifically designed for **Admins** and **Project Managers**.
    - Tailored for small software houses.
    - Focused on streamlining project workflows and improving efficiency.
    """)



# Add new project with suggestions and technology selection
def add_project():
    st.header("Add New Project")

    # Project name input with suggestions
    project_suggestions = [
        "Machine Learning Model",
        "Web Development App",
        "Mobile App Development",
        "Data Science Pipeline",
        "API Development",
        "Game Development",
    ]
    project_name = st.selectbox("Select or type a project name:", project_suggestions)

    # Description based on project name
    description_placeholder = {
        "Machine Learning Model": "Enter a brief description of your machine learning model project.",
        "Web Development App": "Enter a brief description of your web development app project.",
        "Mobile App Development": "Enter a brief description of your mobile app development project.",
        "Data Science Pipeline": "Enter a brief description of your data science pipeline project.",
        "API Development": "Enter a brief description of your API development project.",
        "Game Development": "Enter a brief description of your game development project."
    }
    description = st.text_area("Project Description", placeholder=description_placeholder.get(project_name, ""))

    # Technology selection dynamically based on project name
    technologies = {
        "Machine Learning Model": ["Python", "TensorFlow", "PyTorch", "Scikit-learn"],
        "Web Development App": ["HTML", "CSS", "JavaScript", "Django", "Flask"],
        "Mobile App Development": ["Flutter", "React Native", "Swift", "Kotlin"],
        "Data Science Pipeline": ["Python", "Pandas", "NumPy", "Matplotlib"],
        "API Development": ["FastAPI", "Flask", "Express.js", "Django Rest Framework"],
        "Game Development": ["Unity", "Unreal Engine", "C#", "Godot"],
    }

    if project_name in technologies:
        tech_options = technologies[project_name]
    else:
        tech_options = []
    
    technology_used = st.multiselect("Select technologies used in the project:", tech_options)

    # Additional project details
    start_date = st.date_input("Start Date", date.today())
    end_date = st.date_input("End Date")
    priority = st.selectbox("Priority", ["Low", "Medium", "High"])
    budget = st.number_input("Budget", min_value=0.0)

    # Submit button
    if st.button("Create Project"):
        if project_name and description:
            new_project = pd.DataFrame({
                "Project Name": [project_name],
                "Description": [description],
                "Start Date": [start_date],
                "End Date": [end_date],
                "Priority": [priority],
                "Status": ["Uncompleted"],
                "Progress": [0],
                "Budget": [budget],
                "Technologies": [", ".join(technology_used)]  # Store selected technologies as a comma-separated string
            })
            df = load_projects()
            df = pd.concat([df, new_project], ignore_index=True)
            save_projects(df)
            st.success(f"Project '{project_name}' has been added!")
        else:
            st.error("Please fill in all fields")

# Edit project with suggestions and technology update
def edit_project():
    st.header("Edit Project")
    df = load_projects()
    if df.empty:
        st.info("No projects to edit.")
        return
    
    project_names = df["Project Name"].tolist()
    project = st.selectbox("Select Project", project_names)
    
    if project:
        row = df[df["Project Name"] == project].iloc[0]

        # Project name input with suggestions
        project_suggestions = [
            "Machine Learning Model",
            "Web Development App",
            "Mobile App Development",
            "Data Science Pipeline",
            "API Development",
            "Game Development",
        ]
        new_name = st.selectbox("Select or type a project name:", project_suggestions, index=project_suggestions.index(row["Project Name"]) if row["Project Name"] in project_suggestions else 0)

        # Description based on project name
        description_placeholder = {
            "Machine Learning Model": "Enter a brief description of your machine learning model project.",
            "Web Development App": "Enter a brief description of your web development app project.",
            "Mobile App Development": "Enter a brief description of your mobile app development project.",
            "Data Science Pipeline": "Enter a brief description of your data science pipeline project.",
            "API Development": "Enter a brief description of your API development project.",
            "Game Development": "Enter a brief description of your game development project."
        }
        description = st.text_area("Project Description", placeholder=description_placeholder.get(new_name, ""), value=row["Description"])

        # Technology selection dynamically based on project name
        technologies = {
            "Machine Learning Model": ["Python", "TensorFlow", "PyTorch", "Scikit-learn"],
            "Web Development App": ["HTML", "CSS", "JavaScript", "Django", "Flask"],
            "Mobile App Development": ["Flutter", "React Native", "Swift", "Kotlin"],
            "Data Science Pipeline": ["Python", "Pandas", "NumPy", "Matplotlib"],
            "API Development": ["FastAPI", "Flask", "Express.js", "Django Rest Framework"],
            "Game Development": ["Unity", "Unreal Engine", "C#", "Godot"],
        }

        tech_options = technologies.get(new_name, [])
        technology_used = st.multiselect("Select technologies used in the project:", tech_options, default=row["Technologies"].split(", "))

        # Additional project details
        start_date = st.date_input("Start Date", row["Start Date"])
        end_date = st.date_input("End Date", row["End Date"])
        priority = st.selectbox("Priority", ["Low", "Medium", "High"], index=["Low", "Medium", "High"].index(row["Priority"]))
        budget = st.number_input("Budget", min_value=0.0, value=row["Budget"])

        # Submit button
        if st.button("Update Project"):
            # Update the project data
            df.loc[df["Project Name"] == project, ["Project Name", "Description", "Start Date", "End Date", "Priority", "Budget", "Technologies"]] = new_name, description, start_date, end_date, priority, budget, ", ".join(technology_used)
            save_projects(df)
            st.success(f"Project '{new_name}' has been updated.")

# Delete project
def delete_project():
    st.header("Delete Project")
    df = load_projects()
    if df.empty:
        st.info("No projects to delete.")
        return
    
    project = st.selectbox("Select Project to Delete", df["Project Name"])
    if st.button("Delete Project"):
        df = df[df["Project Name"] != project]
        save_projects(df)
        st.success(f"Project '{project}' has been deleted.")

# THIS IS THE EXACT DESIRE ONE EXCEPT OF THE EMAIL FIELD ALTHOGUH WE CAN SEDN EMAIL SMOOTHLY

# Function to send email
def send_email(to_email, subject, body, attachment=None):
    from_email = "your_email@gmail.com"  # Replace with your email
    password = "your_password"          # Replace with your email app password
    try:
        server = smtplib.SMTP('smtp.gmail.com', 587)
        server.starttls()
        server.login(from_email, password)
        msg = MIMEMultipart()
        msg['Subject'] = subject
        msg['From'] = from_email
        msg['To'] = to_email
        msg.attach(MIMEText(body, 'plain'))

        # Attach a file if provided
        if attachment:
            with open(attachment, "rb") as file:
                part = MIMEBase("application", "octet-stream")
                part.set_payload(file.read())
            encoders.encode_base64(part)
            part.add_header("Content-Disposition", f"attachment; filename={attachment}")
            msg.attach(part)

        server.sendmail(from_email, to_email, msg.as_string())
        server.quit()
    except Exception as e:
        print(f"Failed to send email: {e}")

# Task management within each project
def manage_tasks():
    st.header("Task Management")

    # Load projects and tasks
    projects = load_projects()
    tasks_df = load_tasks()

    if projects.empty:
        st.info("No projects available.")
        return

    # Select a project
    project = st.selectbox("Select Project", projects["Project Name"])
    
    # Define team members
    team_members = {
        "Machine Learning Model": ["Ahmed", "Omar", "Faisal"],
        "Web Development App": ["Zaid", "Salman", "Yusuf"],
        "Mobile App Development": ["Hassan", "Bilal", "Ibrahim"],
        "Data Science Pipeline": ["Suleiman", "Imran", "Farhan"],
        "API Development": ["Adeel", "Hamza", "Mustafa"],
        "Game Development": ["Ali", "Khalid", "Tariq"]
    }

    # Task details
    st.subheader("Add a New Task")
    title = st.text_input("Task Title")
    description = st.text_area("Task Description")
    priority = st.selectbox("Priority", ["Low", "Medium", "High", "Custom"])
    custom_priority = None
    if priority == "Custom":
        custom_priority = st.text_input("Enter Custom Priority")

    tags = st.multiselect("Tags/Labels", ["Design", "Development", "Testing", "Research", "Bug Fixing"])
    team_leader = st.selectbox("Team Leader", team_members.get(project, []))
    assigned_to = st.multiselect("Assigned Team Members", team_members.get(project, []))
    start_date = st.date_input("Start Date")  # Start Date feature
    deadline = st.date_input("Deadline")

    # Prepare new task as a DataFrame (temporary)
    new_task = pd.DataFrame({
        "Project Name": [project],
        "Task Title": [title],
        "Description": [description],
        "Priority": [priority if priority != "Custom" else custom_priority],
        "Tags": [", ".join(tags)],
        "Team Leader": [team_leader],
        "Assigned To": [", ".join(assigned_to)],
        "Start Date": [start_date],  # Include Start Date
        "Deadline": [deadline],
        "Status": ["Uncompleted"]
    })

    # Show options before adding the task
    if title and team_leader and assigned_to:
        st.subheader("Preview Current Task")
        st.write(new_task)

        # Download Current Task
        st.subheader("Download Current Task")
        current_task_file = "current_task.csv"
        new_task.to_csv(current_task_file, index=False)
        st.download_button(
            label="Download Current Task as CSV",
            data=open(current_task_file, "rb").read(),
            file_name="current_task.csv",
            mime="text/csv"
        )

        # Send Current Task File via Email
        st.subheader("Send Email to Team Member")
        email_recipient = st.text_input("Email Recipient for Current Task File")
        if st.button("Send Current Task File"):
            if email_recipient:
                send_email(
                    to_email=email_recipient,
                    subject=f"Task Assigned: {title}",
                    body=f"Task '{title}' has been assigned to you. Please find the details attached.",
                    attachment=current_task_file
                )
                st.success(f"Current task file sent to {email_recipient}!")
            else:
                st.error("Please provide an email recipient.")

    # Add task button
    if st.button("Add Task"):
        if project and title and team_leader and assigned_to and start_date:
            tasks_df = pd.concat([tasks_df, new_task], ignore_index=True)
            save_tasks(tasks_df)
            st.success(f"Task '{title}' has been added to project '{project}'.")
        else:
            st.error("Please fill in all required fields.")




# View project deadlines and high-priority projects
def view_high_priority():
    st.header("Upcoming Deadlines & High Priority Projects")
    df = load_projects()
    if df.empty:
        st.info("No projects available.")
        return
    
    today = date.today()
    upcoming_deadlines = df[df["End Date"] >= str(today)].sort_values("End Date")
    high_priority = upcoming_deadlines[upcoming_deadlines["Priority"] == "High"]

    if not high_priority.empty:
        st.subheader("High Priority Projects")
        for i, row in high_priority.iterrows():
            st.text(f"{row['Project Name']} - Deadline: {row['End Date']}")

    st.subheader("Upcoming Deadlines")
    for i, row in upcoming_deadlines.iterrows():
        st.text(f"{row['Project Name']} - Deadline: {row['End Date']}")

# Team collaboration and management
def manage_team():
    st.header("Team Management")
    df = load_team()
    project = st.selectbox("Assign Team Member to Project", load_projects()["Project Name"])
    member_name = st.text_input("Team Member Name")
    role = st.selectbox("Role", ["Project Manager", "Developer", "Designer", "Quality Assurance Specialist QA"])

    if st.button("Add Member"):
        if project and member_name:
            new_member = pd.DataFrame({
                "Project Name": [project],
                "Member Name": [member_name],
                "Role": [role]
            })
            df = pd.concat([df, new_member], ignore_index=True)
            save_team(df)
            st.success(f"Team member '{member_name}' assigned to project '{project}'.")

    if not df.empty:
        st.subheader("Team Members")
        for i, member in df.iterrows():
            st.text(f"Member: {member['Member Name']} | Role: {member['Role']} | Project: {member['Project Name']}")





# Predefined Data
project_suggestions = [
    "Machine Learning Model",
    "Web Development App",
    "Mobile App Development",
    "Data Science Pipeline",
    "API Development",
    "Game Development",
]

technologies = {
    "Machine Learning Model": ["Python", "TensorFlow", "PyTorch", "Scikit-learn"],
    "Web Development App": ["HTML", "CSS", "JavaScript", "Django", "Flask"],
    "Mobile App Development": ["Flutter", "React Native", "Swift", "Kotlin"],
    "Data Science Pipeline": ["Python", "Pandas", "NumPy", "Matplotlib"],
    "API Development": ["FastAPI", "Flask", "Express.js", "Django Rest Framework"],
    "Game Development": ["Unity", "Unreal Engine", "C#", "Godot"],
}

# Function to generate project report
def generate_report(project_name, deadline, progress_data, overall_progress):
    doc = Document()
    doc.add_heading("Project Report", level=1)
    
    # Project Details
    doc.add_heading("Project Details", level=2)
    doc.add_paragraph(f"Project Name: {project_name}")
    doc.add_paragraph(f"Deadline: {deadline}")
    doc.add_paragraph(f"Overall Progress: {overall_progress:.2f}%")
    
    # Team Progress
    doc.add_heading("Team Progress", level=2)
    table = doc.add_table(rows=1, cols=2)
    table.style = "Table Grid"
    hdr_cells = table.rows[0].cells
    hdr_cells[0].text = "Team Member"
    hdr_cells[1].text = "Progress (%)"
    for progress in progress_data:
        row_cells = table.add_row().cells
        row_cells[0].text = progress["Member"]
        row_cells[1].text = f"{progress['Progress (%)']}%"
    
    # Save Report
    file_name = f"{project_name.replace(' ', '_')}_Report.docx"
    doc.save(file_name)
    return file_name

# Function to allow downloading the file
def create_download_link(file_path):
    with open(file_path, "rb") as file:
        file_bytes = file.read()
    b64 = base64.b64encode(file_bytes).decode()
    href = f'<a href="data:application/octet-stream;base64,{b64}" download="{os.path.basename(file_path)}">Download Report</a>'
    return href

# Function to send email with the report
def send_email_with_report(receiver_email, subject, body, file_path):
    sender_email = "your_email@example.com"  # Replace with your email
    msg = MIMEMultipart()
    msg["From"] = sender_email
    msg["To"] = receiver_email
    msg["Subject"] = subject

    # Email body
    msg.attach(MIMEText(body, "plain"))

    # Attach the document
    with open(file_path, "rb") as attachment:
        part = MIMEBase("application", "octet-stream")
        part.set_payload(attachment.read())
        encoders.encode_base64(part)
        part.add_header(
            "Content-Disposition",
            f"attachment; filename= {os.path.basename(file_path)}",
        )
        msg.attach(part)
    
    # Send email
    try:
        with smtplib.SMTP("smtp.gmail.com", 587) as server:
            server.starttls()
            server.sendmail(sender_email, receiver_email, msg.as_string())
        return f"Email sent successfully to {receiver_email}!"
    except Exception as e:
        return f"Failed to send email: {e}"

# Function to track project progress
def project_progress():
    st.title("Project Progress Tracking")
    
    # Select a project
    project = st.selectbox("Select a Project", project_suggestions)
    technologies_used = ", ".join(technologies[project])
    st.write(f"Technologies: {technologies_used}")
    
    # Input for deadline and progress
    deadline = st.date_input(f"Set a deadline for {project}")
    progress_data = []
    team_size = st.number_input(f"Enter number of team members for {project}", min_value=1, step=1)
    for i in range(team_size):
        member = st.text_input(f"Enter team member {i+1} name")
        progress = st.slider(f"Progress by {member} (%)", 0, 100, 0)
        email = st.text_input(f"Email for {member}")
        progress_data.append({"Member": member, "Progress (%)": progress, "Email": email})
    
    # Calculate overall progress
    progress_df = pd.DataFrame(progress_data)
    overall_progress = progress_df["Progress (%)"].mean()
    st.progress(overall_progress / 100)
    st.write(f"Overall Progress: {overall_progress:.2f}%")
    
    # Generate and download project report
    if st.button("Generate Report"):
        report_file = generate_report(project, deadline, progress_data, overall_progress)
        st.success(f"Report saved as {report_file}")
        st.markdown(create_download_link(report_file), unsafe_allow_html=True)
    
    # # Send the report via email
    # st.subheader("Send Report via Email")
    # recipient_emails = st.text_area("Enter recipient emails (comma-separated)")
    # if st.button("Send Report"):
    #     if report_file:
    #         for email in recipient_emails.split(","):
    #             email_status = send_email_with_report(
    #                 email.strip(),
    #                 f"Project Report: {project}",
    #                 f"Dear Team,\n\nPlease find attached the latest project report for {project}.\n\nBest regards,\nProject Management Team",
    #                 report_file,
    #             )
    #             st.write(email_status)
    #     else:
    #         st.error("Please generate the report first!")


# Call the function to display in menu
# project_progress()



# Set milestones for each project
def set_milestones():
    st.header("Set Milestones")
    df = load_projects()
    if df.empty:
        st.info("No projects available.")
        return

    project = st.selectbox("Select Project for Milestone", df["Project Name"])
    milestone = st.text_input("Milestone Name")
    milestone_date = st.date_input("Milestone Date")

    if st.button("Add Milestone"):
        if project and milestone:
            st.success(f"Milestone '{milestone}' added to project '{project}' for {milestone_date}.")
        else:
            st.error("Please complete the milestone details.")

# Time tracking for projects
def time_tracking():
    st.header("Time Tracking")
    project = st.selectbox("Select Project", load_projects()["Project Name"])
    hours_logged = st.number_input("Hours Worked", min_value=0)
    
    if st.button("Log Time"):
        if project:
            st.success(f"{hours_logged} hours logged for project '{project}'.")

# Document uploads
def document_upload():
    st.header("Document Upload")
    project = st.selectbox("Select Project for Document Upload", load_projects()["Project Name"])
    uploaded_file = st.file_uploader("Upload Document", type=["pdf", "docx", "txt"])

    if uploaded_file is not None:
        st.success(f"Document uploaded to project '{project}'.")

# Project tags and categorization
def project_tags():
    st.header("Project Tags & Categories")
    df = load_projects()
    if df.empty:
        st.info("No projects available.")
        return

    project = st.selectbox("Select Project for Tagging", df["Project Name"])
    tags = st.text_input("Tags (comma-separated)")

    if st.button("Add Tags"):
        if tags:
            df.loc[df["Project Name"] == project, "Tags"] = tags
            save_projects(df)
            st.success(f"Tags updated for project '{project}'.")

# Analytics and reports
def analytics():
    st.header("Project Analytics and Reports")
    df = load_projects()
    if df.empty:
        st.info("No data available.")
        return

    st.subheader("Projects by Priority")
    priority_counts = df["Priority"].value_counts()
    st.bar_chart(priority_counts)

    st.subheader("Project Progress Overview")
    st.line_chart(df["Progress"])

# Calendar view
def calendar_view():
    st.header("Project Calendar View")
    df = load_projects()
    if df.empty:
        st.info("No projects to display on the calendar.")
        return

    st.subheader("Upcoming Deadlines")
    for i, row in df.iterrows():
        st.text(f"{row['Project Name']} - End Date: {row['End Date']}")
# Automated notifications for approaching deadlines or high-priority tasks
def automated_notifications():
    st.header("Automated Notifications")
    df = load_projects()
    if df.empty:
        st.info("No projects available.")
        return

    today = date.today()
    notification_list = []

    # Identify upcoming deadlines and high-priority projects
    for _, row in df.iterrows():
        days_left = (pd.to_datetime(row['End Date']) - pd.to_datetime(today)).days
        if days_left <= 7 or row['Priority'] == 'High':
            notification_list.append(f"{row['Project Name']} - {days_left} days remaining")

    if notification_list:
        st.subheader("Notifications")
        for notification in notification_list:
            st.warning(notification)
    else:
        st.info("No upcoming deadlines or high-priority tasks.")


# Project search and advanced filtering
def search_and_filter_projects():
    st.header("Search and Filter Projects")
    df = load_projects()
    if df.empty:
        st.info("No projects available.")
        return

    # Search bar
    search_query = st.text_input("Search by Project Name or Description")

    # Advanced filters
    filter_priority = st.selectbox("Filter by Priority", ["All", "Low", "Medium", "High"])
    filter_status = st.selectbox("Filter by Status", ["All", "Completed", "Uncompleted"])

    # Apply filters and search
    if search_query:
        df = df[df["Project Name"].str.contains(search_query, case=False) | df["Description"].str.contains(search_query, case=False)]
    if filter_priority != "All":
        df = df[df["Priority"] == filter_priority]
    if filter_status != "All":
        df = df[df["Status"] == filter_status]

    if df.empty:
        st.info("No projects matched the search criteria.")
    else:
        st.write(df)

# Backup and restore project data
def backup_and_restore():
    st.header("Backup and Restore")

    # Backup functionality
    if st.button("Backup Data"):
        df = load_projects()
        if not df.empty:
            df.to_csv('project_backup.csv', index=False)
            st.success("Project data backed up successfully.")
        else:
            st.info("No data to back up.")

    # Restore functionality
    uploaded_file = st.file_uploader("Upload Backup File", type=["csv"])
    if uploaded_file is not None:
        restored_df = pd.read_csv(uploaded_file)
        save_projects(restored_df)
        st.success("Project data restored successfully.")

# Customizable status options
def customize_status():
    st.header("Customizable Project Status Options")
    df = load_projects()
    if df.empty:
        st.info("No projects available.")
        return

    project = st.selectbox("Select Project to Change Status", df["Project Name"])
    new_status = st.text_input("Enter New Status (e.g., In Progress, Pending, On Hold)")

    if st.button("Update Status"):
        if project and new_status:
            df.loc[df["Project Name"] == project, "Status"] = new_status
            save_projects(df)
            st.success(f"Status updated for project '{project}' to '{new_status}'.")

# Project templates
def project_templates():
    st.header("Project Templates")
    templates = {
        "Software Development": {
            "Description": "Developing a software application.",
            "Start Date": date.today(),
            "End Date": date.today(),
            "Priority": "High",
            "Status": "Uncompleted"
        },
        "Marketing Campaign": {
            "Description": "Executing a marketing strategy.",
            "Start Date": date.today(),
            "End Date": date.today(),
            "Priority": "Medium",
            "Status": "Uncompleted"
        }
    }

    selected_template = st.selectbox("Choose a Template", list(templates.keys()))
    template_data = templates[selected_template]

    if st.button("Create Project from Template"):
        df = load_projects()
        new_project = pd.DataFrame(template_data, index=[0])
        df = pd.concat([df, new_project], ignore_index=True)
        save_projects(df)
        st.success(f"Project created from template: {selected_template}")

#Budget Tracking
def budget_tracking():
    st.header("Budget Tracking")
    df = load_projects()  # Assume this fetches your existing projects data.

    if df.empty:
        st.info("No projects available.")
        return

    project = st.selectbox("Select Project for Budget Tracking", df["Project Name"])
    budget = st.number_input("Set Budget (in PKR)", min_value=0)
    expenses = st.number_input("Enter Expenses (in PKR)", min_value=0)

    if st.button("Update Budget"):
        # Update the budget and expenses for the selected project.
        df.loc[df["Project Name"] == project, "Budget"] = budget
        df.loc[df["Project Name"] == project, "Expenses"] = expenses
        save_projects(df)
        st.success(f"Budget and expenses updated for project '{project}'.")

    # Display budget status with Profit or Loss Calculation
    st.subheader("Project Budgets")
    for _, row in df.iterrows():
        budget = row.get("Budget", 0)
        expenses = row.get("Expenses", 0)
        remaining_budget = budget - expenses
        # Calculate profit or loss
        if remaining_budget > 0:
            status = "Profit"
            amount = remaining_budget
        else:
            status = "Loss"
            amount = -remaining_budget  # Convert to positive value for loss

        st.write(
            f"{row['Project Name']} - Budget: {budget}, Expenses: {expenses}, "
            f"Remaining: {remaining_budget} ({status}: {amount})"
        )

    # Download options
    st.subheader("Download Budget Reports")

    # Current project budget
    current_project_data = df[df["Project Name"] == project]
    if not current_project_data.empty:
        current_csv = current_project_data.to_csv(index=False)
        st.download_button(
            label=f"Download Current Budget ({project})",
            data=current_csv,
            file_name=f"{project}_budget.csv",
            mime="text/csv",
        )

    # Overall budgets of the selected project
    overall_project_data = df[df["Project Name"] == project][["Project Name", "Budget", "Expenses"]]
    if not overall_project_data.empty:
        overall_csv = overall_project_data.to_csv(index=False)
        st.download_button(
            label=f"Download Overall Budget for {project}",
            data=overall_csv,
            file_name=f"{project}_overall_budget.csv",
            mime="text/csv",
        )

    # All projects' budgets
    all_csv = df.to_csv(index=False)
    st.download_button(
        label="Download All Projects Budget",
        data=all_csv,
        file_name="all_projects_budget.csv",
        mime="text/csv",
    )




# Comments and Notes
def comments_and_notes():
    st.header("Comments and Notes")
    df = load_projects()
    if df.empty:
        st.info("No projects available.")
        return

    project = st.selectbox("Select Project to Comment On", df["Project Name"])
    comment = st.text_area("Add Comment/Note")

    if st.button("Add Comment"):
        df.loc[df["Project Name"] == project, "Comments"] = df.loc[df["Project Name"] == project, "Comments"].fillna("") + comment + "\n"
        save_projects(df)
        st.success(f"Comment added to project '{project}'.")

    # Display comments for each project
    st.subheader("Project Comments")
    for _, row in df.iterrows():
        comments = row.get("Comments", "No comments yet.")
        st.write(f"{row['Project Name']} - Comments:\n{comments}")

# Prioritization Metrics
def prioritization_metrics():
    st.header("Prioritization Metrics")
    df = load_projects()
    if df.empty:
        st.info("No projects available.")
        return

    project = st.selectbox("Select Project for Prioritization", df["Project Name"])
    impact = st.slider("Impact", min_value=1, max_value=10)
    cost = st.slider("Cost", min_value=1, max_value=10)
    urgency = st.slider("Urgency", min_value=1, max_value=10)
    overall_priority = (impact * 0.5) + (urgency * 0.3) + (10 - cost) * 0.2

    if st.button("Set Prioritization Metrics"):
        df.loc[df["Project Name"] == project, "Impact"] = impact
        df.loc[df["Project Name"] == project, "Cost"] = cost
        df.loc[df["Project Name"] == project, "Urgency"] = urgency
        df.loc[df["Project Name"] == project, "Priority Score"] = overall_priority
        save_projects(df)
        st.success(f"Prioritization metrics set for project '{project}'.")

    # Display prioritization summary
    st.subheader("Project Prioritization Scores")
    for _, row in df.iterrows():
        priority_score = row.get("Priority Score", "Not set")
        st.write(f"{row['Project Name']} - Priority Score: {priority_score}")

# Calendar View (visualization of deadlines using a calendar layout)
def calendar_view():
    st.header("Calendar View")
    import plotly.express as px
    df = load_projects()
    if df.empty:
        st.info("No projects available.")
        return

    # Convert date columns to datetime
    df["Start Date"] = pd.to_datetime(df["Start Date"])
    df["End Date"] = pd.to_datetime(df["End Date"])

    # Create a Gantt chart to visualize project timelines
    fig = px.timeline(df, x_start="Start Date", x_end="End Date", y="Project Name", color="Priority",
                      title="Project Calendar View", labels={"Priority": "Priority Level"})
    fig.update_yaxes(categoryorder="total ascending")
    st.plotly_chart(fig)
# Automated Notifications for approaching deadlines and task assignments
def automated_notifications():
    st.header("Automated Notifications")
    df = load_projects()
    if df.empty:
        st.info("No projects available.")
        return

    today = date.today()
    notifications = []

    # Check for projects with approaching deadlines
    for _, row in df.iterrows():
        end_date = pd.to_datetime(row["End Date"])
        days_to_deadline = (end_date - today).days
        if days_to_deadline == 7:
            notifications.append(f"Project '{row['Project Name']}' is due in 7 days!")
        elif days_to_deadline == 1:
            notifications.append(f"Project '{row['Project Name']}' is due tomorrow!")
        elif days_to_deadline == 0:
            notifications.append(f"Project '{row['Project Name']}' is due today!")

    # Display notifications
    if notifications:
        st.subheader("Notifications")
        for notification in notifications:
            st.warning(notification)
    else:
        st.info("No notifications for upcoming deadlines.")

# Project Search and Filter by various criteria
def search_and_filter_projects():
    st.header("Search and Filter Projects")
    df = load_projects()
    if df.empty:
        st.info("No projects available.")
        return

    search_term = st.text_input("Search by Project Name or Description")
    priority_filter = st.selectbox("Filter by Priority", ["All", "Low", "Medium", "High"])
    status_filter = st.selectbox("Filter by Status", ["All", "Completed", "Uncompleted"])

    if search_term:
        df = df[df["Project Name"].str.contains(search_term, case=False) | df["Description"].str.contains(search_term, case=False)]
    
    if priority_filter != "All":
        df = df[df["Priority"] == priority_filter]
    
    if status_filter != "All":
        df = df[df["Status"] == status_filter]

    if df.empty:
        st.info("No projects match the search criteria.")
    else:
        st.subheader("Search Results")
        for _, row in df.iterrows():
            st.write(f"**{row['Project Name']}** - Priority: {row['Priority']}, Status: {row['Status']}")

# Backup and Restore project data
def backup_and_restore():
    st.header("Backup and Restore")
    df = load_projects()

    if st.button("Backup Project Data"):
        backup_file = PROJECT_DATA_FILE.replace(".csv", "_backup.csv")
        df.to_csv(backup_file, index=False)
        st.success(f"Backup created as {backup_file}")

    uploaded_file = st.file_uploader("Restore from Backup", type=["csv"])
    if uploaded_file:
        df_backup = pd.read_csv(uploaded_file)
        save_projects(df_backup)
        st.success("Project data restored from backup.")

# Customizable Status Options
def customize_status():
    st.header("Customize Project Status Options")
    df = load_projects()
    if df.empty:
        st.info("No projects available.")
        return

    project = st.selectbox("Select Project to Update Status", df["Project Name"])
    status_options = ["In Progress", "Pending", "On Hold", "Completed", "Uncompleted"]
    custom_status = st.selectbox("Set Custom Status", status_options)

    if st.button("Update Status"):
        df.loc[df["Project Name"] == project, "Status"] = custom_status
        save_projects(df)
        st.success(f"Status of '{project}' updated to '{custom_status}'")

# Project Templates for frequently used project types
def project_templates():
    st.header("Project Templates")
    template_name = st.selectbox("Select Template", ["Software Development", "Marketing Campaign", "Research Project", "Event Planning", "Custom"])
    
    if template_name != "Custom":
        template_description = {
            "Software Development": "Developing a software application with multiple phases, from requirements gathering to deployment.",
            "Marketing Campaign": "Organizing and launching a marketing campaign, including content creation and social media promotion.",
            "Research Project": "Conducting research, including literature review, data collection, analysis, and reporting.",
            "Event Planning": "Planning and organizing an event, including venue booking, logistics, and promotions."
        }.get(template_name, "A general project template.")
    else:
        template_description = st.text_area("Custom Project Description")

    if st.button("Create Project from Template"):
        new_project = pd.DataFrame({
            "Project Name": [template_name + " Project"],
            "Description": [template_description],
            "Start Date": [date.today()],
            "End Date": [date.today()],
            "Priority": ["Medium"],
            "Status": ["Uncompleted"]
        })
        
        df = load_projects()
        df = pd.concat([df, new_project], ignore_index=True)
        save_projects(df)
        st.success(f"Project '{template_name} Project' created from template.")





# Comments and Notes for team collaboration
def comments_and_notes():
    st.header("Project Comments & Notes")
    df = load_projects()
    if df.empty:
        st.info("No projects available.")
        return

    project = st.selectbox("Select Project", df["Project Name"])
    note = st.text_area("Add a Comment or Note")

    if st.button("Add Note"):
        df.loc[df["Project Name"] == project, "Notes"] = df.loc[df["Project Name"] == project].get("Notes", "") + "\n" + note
        save_projects(df)
        st.success(f"Note added to '{project}'")

    st.subheader("Project Notes")
    for i, row in df.iterrows():
        if "Notes" in row and row["Notes"]:
            st.write(f"**{row['Project Name']}** Notes:\n{row['Notes']}")

# Calendar View for visual project timelines and deadlines
def calendar_view():
    st.header("Project Calendar View")
    df = load_projects()
    if df.empty:
        st.info("No projects available.")
        return

    st.write("**Project Deadlines and Timelines**")
    for i, row in df.iterrows():
        st.write(f"{row['Project Name']} - **Start:** {row['Start Date']} **End:** {row['End Date']}")


# Prioritization Metrics for automated prioritization
def prioritization_metrics():
    st.header("Prioritization Metrics")
    df = load_projects()
    if df.empty:
        st.info("No projects available.")
        return

    priority_metric = st.selectbox("Set Prioritization Criteria", ["Impact", "Cost", "Deadline"])
    st.write(f"Projects prioritized by {priority_metric}")

    # Example: prioritize by impact or cost (placeholder logic)
    if priority_metric == "Impact":
        df = df.sort_values("Priority", ascending=False)  # Assuming high = more impact
    elif priority_metric == "Cost":
        df = df.sort_values("Budget", ascending=True)
    elif priority_metric == "Deadline":
        df = df.sort_values("End Date")

    for i, row in df.iterrows():
        st.write(f"{row['Project Name']} - Priority: {row['Priority']} - Deadline: {row['End Date']}")
# Customizable Status Options: Allows users to create custom project statuses
def customizable_status_options():
    st.header("Customizable Status Options")
    df = load_projects()
    
    if df.empty:
        st.info("No projects available.")
        return
    
    # Allow users to select a project and choose a custom status
    project = st.selectbox("Select Project", df["Project Name"].unique())
    custom_status = st.text_input("Enter New Status (e.g., In Progress, On Hold)")
    
    if st.button("Update Status"):
        if custom_status:
            df.loc[df["Project Name"] == project, "Status"] = custom_status
            save_projects(df)
            st.success(f"Status for '{project}' updated to '{custom_status}'.")
        else:
            st.warning("Please enter a valid status.")

# Comments and Notes: Add a comment section to each project
def comments_and_notes():
    st.header("Comments and Notes")
    df = load_projects()
    
    if df.empty:
        st.info("No projects available.")
        return
    
    project = st.selectbox("Select Project for Comments", df["Project Name"].unique())
    comment = st.text_area("Add Comment or Note")
    
    if st.button("Submit Comment"):
        if comment:
            comments_file = f"{project}_comments.txt"
            with open(comments_file, "a") as file:
                file.write(f"{comment}\n")
            st.success("Comment added successfully!")
        else:
            st.warning("Please enter a comment.")
    
    # Display existing comments
    if os.path.exists(f"{project}_comments.txt"):
        st.subheader("Existing Comments")
        with open(f"{project}_comments.txt", "r") as file:
            comments = file.readlines()
            for c in comments:
                st.text(c.strip())

# Automated Notifications for project deadlines and updates
def automated_notifications():
    st.header("Automated Notifications")
    df = load_projects()
    
    if df.empty:
        st.info("No projects available.")
        return

    today = date.today()
    upcoming_deadlines = df[(pd.to_datetime(df['End Date']) >= today) & (pd.to_datetime(df['End Date']) <= today + pd.Timedelta(days=7))]
    
    if not upcoming_deadlines.empty:
        st.warning("Upcoming Deadlines:")
        for i, row in upcoming_deadlines.iterrows():
            st.text(f"{row['Project Name']} - Due on {row['End Date']}")
    
    st.success("Notifications are enabled for approaching deadlines and updates.")

# Team Collaboration: Add team members and assign roles to projects
def team_collaboration():
    st.header("Team Collaboration")
    df = load_projects()
    
    if df.empty:
        st.info("No projects available.")
        return
    
    project = st.selectbox("Select Project for Team Collaboration", df["Project Name"].unique())
    member_name = st.text_input("Team Member Name")
    role = st.selectbox("Role", ["Team Member", "Project Manager", "Viewer"])
    
    if st.button("Add Team Member"):
        if member_name:
            team_file = f"{project}_team.csv"
            if os.path.exists(team_file):
                team_df = pd.read_csv(team_file)
            else:
                team_df = pd.DataFrame(columns=["Member Name", "Role"])
                
            new_member = pd.DataFrame({"Member Name": [member_name], "Role": [role]})
            team_df = pd.concat([team_df, new_member], ignore_index=True)
            team_df.to_csv(team_file, index=False)
            st.success(f"{member_name} added to the project as {role}!")
        else:
            st.warning("Please enter a team member's name.")

    # Display current team members
    if os.path.exists(f"{project}_team.csv"):
        st.subheader("Current Team Members")
        team_df = pd.read_csv(f"{project}_team.csv")
        st.dataframe(team_df)
# Gantt Chart Visualization
def gantt_chart_visualization():
    st.header("Gantt Chart Visualization")
    df = load_projects()
    
    if df.empty:
        st.info("No projects available to display in Gantt chart.")
        return
    
    # Prepare data for Gantt chart
    df['Start Date'] = pd.to_datetime(df['Start Date'])
    df['End Date'] = pd.to_datetime(df['End Date'])
    df['Duration'] = (df['End Date'] - df['Start Date']).dt.days

    chart = alt.Chart(df).mark_bar().encode(
        x='Start Date:T',
        x2='End Date:T',
        y=alt.Y('Project Name', sort=alt.SortField("Start Date", order="ascending")),
        color='Priority'
    ).properties(width=600, height=400)

    st.altair_chart(chart)

# Task Dependencies and Sequencing
def manage_task_dependencies():
    st.header("Manage Task Dependencies")
    project_name = st.selectbox("Select Project", load_projects()["Project Name"].unique())
    task_name = st.text_input("Task Name")
    dependency_task = st.selectbox("Select Prerequisite Task", load_projects()["Project Name"].unique())
    
    if st.button("Set Dependency"):
        if task_name and dependency_task:
            dependencies_file = f"{project_name}_dependencies.csv"
            if os.path.exists(dependencies_file):
                dependencies_df = pd.read_csv(dependencies_file)
            else:
                dependencies_df = pd.DataFrame(columns=["Task", "Dependency"])
            
            new_dependency = pd.DataFrame({"Task": [task_name], "Dependency": [dependency_task]})
            dependencies_df = pd.concat([dependencies_df, new_dependency], ignore_index=True)
            dependencies_df.to_csv(dependencies_file, index=False)
            st.success("Dependency added successfully!")
        else:
            st.warning("Please enter both the task name and prerequisite task.")

    if os.path.exists(f"{project_name}_dependencies.csv"):
        st.subheader("Existing Dependencies")
        dependencies_df = pd.read_csv(f"{project_name}_dependencies.csv")
        st.dataframe(dependencies_df)

# Resource Management
def resource_management():
    st.header("Resource Management")
    df = load_projects()
    if df.empty:
        st.info("No projects available.")
        return
    
    project = st.selectbox("Select Project for Resource Allocation", df["Project Name"].unique())
    resource_name = st.text_input("Resource Name")
    allocation_percentage = st.slider("Resource Allocation Percentage", 0, 100, 50)
    
    if st.button("Allocate Resource"):
        if resource_name:
            resource_file = f"{project}_resources.csv"
            if os.path.exists(resource_file):
                resource_df = pd.read_csv(resource_file)
            else:
                resource_df = pd.DataFrame(columns=["Resource Name", "Allocation (%)"])
            
            new_resource = pd.DataFrame({"Resource Name": [resource_name], "Allocation (%)": [allocation_percentage]})
            resource_df = pd.concat([resource_df, new_resource], ignore_index=True)
            resource_df.to_csv(resource_file, index=False)
            st.success(f"{resource_name} allocated to '{project}'!")
        else:
            st.warning("Please enter the resource name.")

    if os.path.exists(f"{project}_resources.csv"):
        st.subheader("Allocated Resources")
        resource_df = pd.read_csv(f"{project}_resources.csv")
        st.dataframe(resource_df)

# Risk Management and Mitigation Tracking
def risk_management():
    st.header("Risk Management and Mitigation Tracking")
    df = load_projects()
    
    if df.empty:
        st.info("No projects available.")
        return

    project = st.selectbox("Select Project for Risk Management", df["Project Name"].unique())
    risk_description = st.text_input("Risk Description")
    risk_level = st.selectbox("Risk Level", ["Low", "Medium", "High"])
    mitigation_strategy = st.text_area("Mitigation Strategy")
    
    if st.button("Log Risk"):
        if risk_description and mitigation_strategy:
            risk_file = f"{project}_risks.csv"
            if os.path.exists(risk_file):
                risk_df = pd.read_csv(risk_file)
            else:
                risk_df = pd.DataFrame(columns=["Risk Description", "Risk Level", "Mitigation Strategy"])
            
            new_risk = pd.DataFrame({
                "Risk Description": [risk_description],
                "Risk Level": [risk_level],
                "Mitigation Strategy": [mitigation_strategy]
            })
            risk_df = pd.concat([risk_df, new_risk], ignore_index=True)
            risk_df.to_csv(risk_file, index=False)
            st.success(f"Risk added to '{project}'!")
        else:
            st.warning("Please complete all fields to log a risk.")

    if os.path.exists(f"{project}_risks.csv"):
        st.subheader("Logged Risks")
        risk_df = pd.read_csv(f"{project}_risks.csv")
        st.dataframe(risk_df)

# Integration with Third-Party Tools (Simulated example)
def integration_with_third_party_tools():
    st.header("Integration with Third-Party Tools")
    st.info("Here, you can integrate with various third-party tools like Slack, Trello, or Google Workspace.")

    tool = st.selectbox("Select Tool to Integrate", ["Slack", "GitHub", "Trello", "Google Workspace"])
    if st.button("Integrate"):
        st.success(f"{tool} has been integrated successfully! (Simulated)")



  
# #project tags and categories , "Third-Party Integrations",  "Automated Notifications", "Backup & Restore", 


# for notifications:

import streamlit as st

# Add your other function definitions here, like add_project(), edit_project(), etc.

# Sidebar menu using radio buttons
menu = st.sidebar.radio(
    "Menu", [
        "Home", "Add Project", "Edit Project", "Delete Project", 
        "Task Management", "High Priority & Deadlines", 
         "Project Progress Tracking", 
          
        "Analytics & Reports", "Calendar View", 
        "Search and Filter", "Budget Tracking", 
        "Comments and Notes", "Prioritization Metrics", 
        "Gantt Chart Visualization", 
        "Resource Management", "Risk Management"
    ]
)

# Linking each radio button option to the corresponding function
if menu == "Home":
    home()
elif menu == "Add Project":
    add_project()
elif menu == "Edit Project":
    edit_project()
elif menu == "Delete Project":
    delete_project()
elif menu == "Task Management":
    manage_tasks()  # Calling your manage_tasks function here
elif menu == "High Priority & Deadlines":
    view_high_priority()
# elif menu == "Team Collaboration":
#     manage_team()
elif menu == "Project Progress Tracking":
    project_progress()
# elif menu == "Set Milestones":
#     set_milestones()
# elif menu == "Time Tracking":
#     time_tracking()
# elif menu == "Document Upload":
#     document_upload()
elif menu == "Analytics & Reports":
    analytics()
elif menu == "Calendar View":
    calendar_view()
elif menu == "Search and Filter":
    search_and_filter_projects()
# elif menu == "Customizable Status":
#     customizable_status_options()
# elif menu == "Project Templates":
#     project_templates()
elif menu == "Budget Tracking":
    budget_tracking()
elif menu == "Comments and Notes":
    comments_and_notes()
elif menu == "Prioritization Metrics":
    prioritization_metrics()
elif menu == "Gantt Chart Visualization":
    gantt_chart_visualization()
# elif menu == "Task Dependencies and Sequencing":
#     manage_task_dependencies()
elif menu == "Resource Management":
    resource_management()
elif menu == "Risk Management":
    risk_management()



# "Team Collaboration", "Set Milestones", "Time Tracking", "Document Upload", "Customizable Status", 
        # "Project Templates", "Task Dependencies and Sequencing",