File size: 24,530 Bytes
8b7e8f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from streamlit_option_menu import option_menu
import os
import sys

# Add src directory to Python path
sys.path.append(os.path.join(os.path.dirname(__file__), "src"))

from src.utils.config import config
from src.utils.logger import setup_logging

# Page config
st.set_page_config(
    page_title="Lega.AI", page_icon="⚖️", layout="wide", initial_sidebar_state="expanded"
)

# Custom CSS for responsive dark/light theme
st.markdown(
    """
<style>
    /* Main header with gradient text */
    .main-header {
        font-size: 3rem;
        font-weight: bold;
        text-align: center;
        margin-bottom: 2rem;
        background: linear-gradient(90deg, #1f4e79, #2e86ab);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
    }
    
    /* Responsive feature cards that adapt to theme */
    .feature-card {
        background: var(--background-color);
        padding: 1.5rem;
        border-radius: 12px;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        margin: 1rem 0;
        border-left: 4px solid #2e86ab;
        border: 1px solid var(--border-color);
        color: var(--text-color);
        transition: all 0.3s ease;
    }
    
    .feature-card:hover {
        transform: translateY(-2px);
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
    }
    
    /* Risk color indicators */
    .risk-critical { color: #ff4444; font-weight: bold; }
    .risk-high { color: #ff6666; font-weight: bold; }
    .risk-medium { color: #ffaa00; font-weight: bold; }
    .risk-low { color: #ffcc00; font-weight: bold; }
    .risk-safe { color: #44aa44; font-weight: bold; }
    
    /* Responsive metric cards */
    .metric-card {
        background: var(--secondary-background-color);
        padding: 1.5rem;
        border-radius: 10px;
        text-align: center;
        margin: 0.5rem 0;
        border: 1px solid var(--border-color);
        color: var(--text-color);
        transition: all 0.3s ease;
    }
    
    .metric-card:hover {
        background: var(--hover-background-color);
    }
    
    /* Enhanced button styling */
    .stButton > button {
        width: 100%;
        background: linear-gradient(135deg, #2e86ab, #1f4e79);
        color: white !important;
        border: none;
        border-radius: 10px;
        padding: 0.75rem 1rem;
        font-weight: 600;
        transition: all 0.3s ease;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    }
    
    .stButton > button:hover {
        background: linear-gradient(135deg, #1f4e79, #2e86ab);
        transform: translateY(-1px);
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    }
    
    /* Enhanced sidebar styling for dark/light theme */
    .css-1d391kg {
        background: var(--background-color) !important;
    }
    
    /* Streamlit sidebar container */
    section[data-testid="stSidebar"] {
        background: var(--background-color) !important;
        border-right: 1px solid var(--border-color) !important;
    }
    
    /* Sidebar content */
    section[data-testid="stSidebar"] > div {
        background: var(--background-color) !important;
        color: var(--text-color) !important;
    }
    
    /* Sidebar header */
    section[data-testid="stSidebar"] .block-container {
        background: var(--background-color) !important;
        color: var(--text-color) !important;
    }
    
    /* Option menu in sidebar */
    section[data-testid="stSidebar"] .nav-link {
        background: var(--secondary-background-color) !important;
        color: var(--text-color) !important;
        border: 1px solid var(--border-color) !important;
    }
    
    /* Active option in sidebar */
    section[data-testid="stSidebar"] .nav-link.active {
        background: linear-gradient(135deg, #2e86ab, #1f4e79) !important;
        color: white !important;
    }
    
    /* Streamlit Option Menu specific styling - Force override */
    .nav-link {
        background: var(--secondary-background-color) !important;
        color: var(--text-color) !important;
        border: 1px solid var(--border-color) !important;
        border-radius: 8px !important;
        margin: 2px 0 !important;
    }
    
    .nav-link:hover {
        background: var(--hover-background-color) !important;
        color: var(--text-color) !important;
    }
    
    .nav-link.active {
        background: linear-gradient(135deg, #2e86ab, #1f4e79) !important;
        color: white !important;
        border: 1px solid #2e86ab !important;
    }
    
    /* Option menu container */
    .nav {
        background: transparent !important;
    }
    
    /* Fix option menu wrapper */
    div[data-testid="stVerticalBlock"] > div > div {
        background: transparent !important;
    }
    
    /* More specific selectors for option menu */
    section[data-testid="stSidebar"] .nav-link {
        background-color: var(--secondary-background-color) !important;
        color: var(--text-color) !important;
        border: 1px solid var(--border-color) !important;
    }
    
    section[data-testid="stSidebar"] .nav-link:hover {
        background-color: var(--hover-background-color) !important;
    }
    
    section[data-testid="stSidebar"] .nav-link.active {
        background-color: #2e86ab !important;
        color: white !important;
    }
    
    /* Force override any white backgrounds in sidebar */
    section[data-testid="stSidebar"] * {
        background-color: inherit !important;
    }
    
    section[data-testid="stSidebar"] .nav-link {
        background-color: var(--secondary-background-color) !important;
    }
    
    /* File uploader styling */
    .uploadedFile {
        background: var(--secondary-background-color) !important;
        border: 2px dashed var(--border-color) !important;
        border-radius: 10px !important;
        color: var(--text-color) !important;
    }
    
    /* Tab styling */
    .stTabs [data-baseweb="tab-list"] {
        gap: 8px;
    }
    
    .stTabs [data-baseweb="tab"] {
        background: var(--secondary-background-color);
        border-radius: 8px;
        color: var(--text-color);
        border: 1px solid var(--border-color);
    }
    
    .stTabs [aria-selected="true"] {
        background: linear-gradient(135deg, #2e86ab, #1f4e79) !important;
        color: white !important;
    }
    
    /* Tooltip styling for risk factors */
    .tooltip {
        position: relative;
        display: inline;
        cursor: help;
        border-radius: 4px;
        padding: 2px 4px;
        margin: 0 1px;
    }
    
    .tooltip .tooltiptext {
        visibility: hidden;
        width: 300px;
        background-color: var(--tooltip-background);
        color: var(--tooltip-text);
        text-align: left;
        border-radius: 8px;
        padding: 12px;
        position: absolute;
        z-index: 1000;
        bottom: 125%;
        left: 50%;
        margin-left: -150px;
        opacity: 0;
        transition: opacity 0.3s, visibility 0.3s;
        font-size: 13px;
        line-height: 1.4;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        border: 1px solid var(--border-color);
    }
    
    .tooltip:hover .tooltiptext {
        visibility: visible;
        opacity: 1;
    }
    
    /* Risk highlighting */
    .risk-critical { 
        background-color: rgba(255, 68, 68, 0.2); 
        border-left: 4px solid #ff4444; 
        padding: 4px 8px;
        border-radius: 4px;
    }
    .risk-high { 
        background-color: rgba(255, 136, 0, 0.2); 
        border-left: 4px solid #ff8800; 
        padding: 4px 8px;
        border-radius: 4px;
    }
    .risk-medium { 
        background-color: rgba(255, 204, 0, 0.2); 
        border-left: 4px solid #ffcc00; 
        padding: 4px 8px;
        border-radius: 4px;
    }
    .risk-low { 
        background-color: rgba(68, 170, 68, 0.2); 
        border-left: 4px solid #44aa44; 
        padding: 4px 8px;
        border-radius: 4px;
    }
    
    /* Jargon term highlighting */
    .jargon-term { 
        background-color: rgba(46, 134, 171, 0.2); 
        text-decoration: underline dotted #2e86ab;
        padding: 2px 4px;
        border-radius: 3px;
    }
    
    /* Dark theme variables */
    [data-theme="dark"] {
        --background-color: #0e1117;
        --secondary-background-color: #262730;
        --text-color: #fafafa;
        --border-color: #464a5a;
        --hover-background-color: #3d4354;
        --tooltip-background: #262730;
        --tooltip-text: #fafafa;
    }
    
    /* Light theme variables */
    [data-theme="light"], :root {
        --background-color: #ffffff;
        --secondary-background-color: #f8f9fa;
        --text-color: #262626;
        --border-color: #e0e0e0;
        --hover-background-color: #f0f0f0;
        --tooltip-background: #333333;
        --tooltip-text: #ffffff;
    }
    
    /* Auto-detect system theme */
    @media (prefers-color-scheme: dark) {
        :root {
            --background-color: #0e1117;
            --secondary-background-color: #262730;
            --text-color: #fafafa;
            --border-color: #464a5a;
            --hover-background-color: #3d4354;
            --tooltip-background: #262730;
            --tooltip-text: #fafafa;
        }
    }
    
    /* Hide Streamlit default elements */
    #MainMenu {visibility: hidden;}
    footer {visibility: hidden;}
    .stDeployButton {visibility: hidden;}
    
    /* Fix all Streamlit components for dark theme */
    .stApp {
        background: var(--background-color) !important;
        color: var(--text-color) !important;
    }
    
    /* Main content area */
    .main .block-container {
        background: var(--background-color) !important;
        color: var(--text-color) !important;
        padding-top: 2rem;
        padding-bottom: 2rem;
    }
    
    /* Text input fields */
    .stTextInput > div > div > input {
        background: var(--secondary-background-color) !important;
        color: var(--text-color) !important;
        border: 1px solid var(--border-color) !important;
    }
    
    /* Text areas */
    .stTextArea > div > div > textarea {
        background: var(--secondary-background-color) !important;
        color: var(--text-color) !important;
        border: 1px solid var(--border-color) !important;
    }
    
    /* Select boxes */
    .stSelectbox > div > div > select {
        background: var(--secondary-background-color) !important;
        color: var(--text-color) !important;
        border: 1px solid var(--border-color) !important;
    }
    
    /* Info, warning, error boxes */
    .stAlert {
        background: var(--secondary-background-color) !important;
        color: var(--text-color) !important;
        border: 1px solid var(--border-color) !important;
    }
    
    /* Expander */
    .streamlit-expanderHeader {
        background: var(--secondary-background-color) !important;
        color: var(--text-color) !important;
        border: 1px solid var(--border-color) !important;
    }
    
    /* Columns */
    .element-container {
        background: transparent !important;
    }
    
    /* Status indicators */
    .status-success {
        background: rgba(68, 170, 68, 0.1);
        border: 1px solid #44aa44;
        border-radius: 6px;
        padding: 8px 12px;
        color: #44aa44;
    }
    
    .status-warning {
        background: rgba(255, 136, 0, 0.1);
        border: 1px solid #ff8800;
        border-radius: 6px;
        padding: 8px 12px;
        color: #ff8800;
    }
    
    .status-error {
        background: rgba(255, 68, 68, 0.1);
        border: 1px solid #ff4444;
        border-radius: 6px;
        padding: 8px 12px;
        color: #ff4444;
    }
</style>
""",
    unsafe_allow_html=True,
)


def main():
    # Initialize logging
    setup_logging()

    # Initialize session state
    if "current_document" not in st.session_state:
        st.session_state.current_document = None
    if "documents_library" not in st.session_state:
        st.session_state.documents_library = []

    # Sidebar navigation
    with st.sidebar:
        st.markdown("### ⚖️ Lega.AI")
        st.markdown("*Making legal documents accessible*")

        selected = option_menu(
            menu_title=None,
            options=[
                "🏠 Home",
                "📄 Upload",
                "📊 Analysis",
                "💬 Q&A",
                "📚 Library",
                "⚙️ Settings",
            ],
            icons=["house", "upload", "graph-up", "chat-dots", "folder", "gear"],
            menu_icon="list",
            default_index=0,
            styles={
                "container": {
                    "padding": "0!important",
                    "background-color": "transparent",
                },
                "icon": {"color": "#2e86ab", "font-size": "18px"},
                "nav-link": {
                    "font-size": "16px",
                    "text-align": "left",
                    "margin": "2px 0px",
                    "padding": "8px 12px",
                    "border-radius": "8px",
                    "background-color": "transparent",
                    "color": "inherit",
                    "border": "1px solid transparent",
                    "--hover-color": "transparent",
                },
                "nav-link-selected": {
                    "background-color": "#2e86ab",
                    "color": "white",
                    "border": "1px solid #2e86ab",
                },
            },
        )

    # Handle page redirections from session state
    if "page" in st.session_state and st.session_state.page:
        # Map the session state page to the selected value
        page_mapping = {
            "📄 Upload": "📄 Upload",
            "📊 Analysis": "📊 Analysis",
            "💬 Q&A": "💬 Q&A",
            "📚 Library": "📚 Library",
            "⚙️ Settings": "⚙️ Settings",
        }

        if st.session_state.page in page_mapping:
            selected = st.session_state.page
            # Clear the page state to prevent continuous redirections
            del st.session_state.page

    # Main content area
    if selected == "🏠 Home":
        show_home_page()
    elif selected == "📄 Upload":
        show_upload_page()
    elif selected == "📊 Analysis":
        show_analysis_page()
    elif selected == "💬 Q&A":
        show_qa_page()
    elif selected == "📚 Library":
        show_library_page()
    elif selected == "⚙️ Settings":
        show_settings_page()


def show_home_page():
    """Display the home page with overview and features."""
    st.markdown('<h1 class="main-header">⚖️ Lega.AI</h1>', unsafe_allow_html=True)
    st.markdown(
        '<p style="text-align: center; font-size: 1.2rem; color: #666;">AI-powered legal document analysis and simplification</p>',
        unsafe_allow_html=True,
    )

    # Key benefits
    col1, col2, col3 = st.columns(3)

    with col1:
        st.markdown(
            """
        <div class="feature-card">
            <h3>🚀 Instant Analysis</h3>
            <p>Upload any legal document and get comprehensive analysis in under 60 seconds using Google's Gemini AI.</p>
        </div>
        """,
            unsafe_allow_html=True,
        )

    with col2:
        st.markdown(
            """
        <div class="feature-card">
            <h3>🎯 Risk Assessment</h3>
            <p>Color-coded risk scoring helps you identify problematic clauses at a glance with detailed explanations.</p>
        </div>
        """,
            unsafe_allow_html=True,
        )

    with col3:
        st.markdown(
            """
        <div class="feature-card">
            <h3>💬 Plain Language</h3>
            <p>Convert complex legal jargon into clear, understandable language that anyone can comprehend.</p>
        </div>
        """,
            unsafe_allow_html=True,
        )

    # Quick stats
    st.markdown("---")
    st.subheader("📊 Platform Statistics")

    col1, col2, col3, col4 = st.columns(4)

    with col1:
        st.markdown(
            """
        <div class="metric-card">
            <h2>1,247</h2>
            <p>Documents Analyzed</p>
        </div>
        """,
            unsafe_allow_html=True,
        )

    with col2:
        st.markdown(
            """
        <div class="metric-card">
            <h2>95%</h2>
            <p>Accuracy Rate</p>
        </div>
        """,
            unsafe_allow_html=True,
        )

    with col3:
        st.markdown(
            """
        <div class="metric-card">
            <h2>₹2,000</h2>
            <p>Avg. Saved per User</p>
        </div>
        """,
            unsafe_allow_html=True,
        )

    with col4:
        st.markdown(
            """
        <div class="metric-card">
            <h2>45 sec</h2>
            <p>Avg. Processing Time</p>
        </div>
        """,
            unsafe_allow_html=True,
        )

    # Getting started
    st.markdown("---")
    st.subheader("🎯 Getting Started")

    col1, col2 = st.columns([2, 1])

    with col1:
        st.markdown(
            """
        **How to use Lega.AI:**
        
        1. **Upload** your legal document (PDF, DOCX, or TXT)
        2. **Wait** for AI analysis (typically 30-60 seconds)
        3. **Review** risk assessment and simplified explanations  
        4. **Ask questions** about specific clauses or terms
        5. **Export** summary for your records
        """
        )

    with col2:
        st.markdown("### 📄 Try Real Sample Documents")
        st.markdown("Get started with actual legal documents:")
        
        # Get available sample documents
        sample_dir = "./sample"
        sample_files = []
        if os.path.exists(sample_dir):
            sample_files = [f for f in os.listdir(sample_dir) if f.endswith(('.pdf', '.docx', '.txt'))]
        
        if sample_files:
            for i, filename in enumerate(sample_files[:4]):  # Show first 4
                display_name = filename.replace('_', ' ').replace('.pdf', '').replace('.docx', '').replace('.txt', '')
                display_name = display_name.title()
                
                if st.button(f"📄 {display_name}", key=f"home_sample_{i}"):
                    st.session_state.load_sample = filename
                    st.session_state.page = "📄 Upload"
                    st.rerun()
        else:
            st.info("Sample documents loading...")

    # CTA button
    st.markdown("---")
    if st.button("📄 Analyze Your First Document", type="primary"):
        st.session_state.page = "📄 Upload"
        st.rerun()


def load_sample_document(doc_type: str):
    """Load a sample document for demonstration."""
    sample_docs = {
        "rental": {
            "filename": "sample_rental_agreement.pdf",
            "type": "rental",
            "text": """
            RESIDENTIAL LEASE AGREEMENT
            
            This Lease Agreement is entered into between John Smith (Landlord) and Jane Doe (Tenant) 
            for the property located at 123 Main Street, Mumbai, Maharashtra.
            
            RENT: Tenant agrees to pay Rs. 25,000 per month, due on the 1st of each month. 
            Late payments will incur a penalty of Rs. 1,000 per day.
            
            SECURITY DEPOSIT: Tenant shall pay a security deposit of Rs. 75,000, which is 
            non-refundable except for damage assessment.
            
            TERMINATION: Either party may terminate this lease with 30 days written notice. 
            Early termination by Tenant results in forfeiture of security deposit.
            
            MAINTENANCE: Tenant is responsible for all repairs and maintenance, including 
            structural repairs, regardless of cause.
            
            The property is leased "as-is" with no warranties. Landlord is not liable for 
            any damages or injuries occurring on the premises.
            """,
        },
        "loan": {
            "filename": "sample_loan_agreement.pdf",
            "type": "loan",
            "text": """
            PERSONAL LOAN AGREEMENT
            
            Borrower: Rajesh Kumar
            Lender: QuickCash Financial Services Pvt Ltd
            Principal Amount: Rs. 2,00,000
            
            INTEREST RATE: 24% per annum (APR 28.5% including processing fees)
            
            REPAYMENT: 24 monthly installments of Rs. 12,500 each
            Total repayment amount: Rs. 3,00,000
            
            LATE PAYMENT PENALTY: Rs. 500 per day for any late payment
            
            DEFAULT: If payment is late by more than 7 days, the entire remaining 
            balance becomes immediately due and payable.
            
            COLLATERAL: Borrower pledges gold ornaments worth Rs. 2,50,000 as security.
            Lender may seize collateral immediately upon default.
            
            ARBITRATION: All disputes shall be resolved through binding arbitration. 
            Borrower waives right to jury trial.
            
            Processing fee: Rs. 10,000 (non-refundable)
            Documentation charges: Rs. 5,000
            """,
        },
        "employment": {
            "filename": "sample_employment_contract.pdf",
            "type": "employment",
            "text": """
            EMPLOYMENT CONTRACT
            
            Employee: Priya Sharma
            Company: TechCorp India Private Limited
            Position: Software Developer
            Start Date: January 1, 2024
            
            SALARY: Rs. 8,00,000 per annum, payable monthly
            
            WORKING HOURS: 45 hours per week, including mandatory weekend work when required
            
            NON-COMPETE: Employee shall not work for any competing company for 2 years 
            after termination, within India or globally.
            
            CONFIDENTIALITY: Employee agrees to maintain strict confidentiality of all 
            company information indefinitely, even after termination.
            
            TERMINATION: Company may terminate employment at any time without cause or notice. 
            Employee must provide 90 days notice to resign.
            
            NO MOONLIGHTING: Employee shall not engage in any other work or business 
            activities during employment.
            
            INTELLECTUAL PROPERTY: All work created by employee belongs entirely to company, 
            including personal projects done outside work hours.
            """,
        },
    }

    if doc_type in sample_docs:
        sample = sample_docs[doc_type]
        from src.utils.helpers import generate_document_id

        # Store in session state
        st.session_state.current_document = {
            "id": generate_document_id(),
            "filename": sample["filename"],
            "document_type": sample["type"],
            "original_text": sample["text"],
            "is_sample": True,
        }

        st.success(f"📄 Loaded sample {doc_type} document!")
        st.session_state.page = "📊 Analysis"
        st.rerun()


def show_upload_page():
    """Import and show the upload page."""
    try:
        from src.pages.upload import show_upload_interface

        show_upload_interface()
    except ImportError as e:
        st.error(f"Upload page not found: {e}")


def show_analysis_page():
    """Import and show the analysis page."""
    try:
        from src.pages.analysis import show_analysis_interface

        show_analysis_interface()
    except ImportError as e:
        st.error(f"Analysis page not found: {e}")


def show_qa_page():
    """Import and show the Q&A page."""
    try:
        from src.pages.qa_assistant import show_qa_interface

        show_qa_interface()
    except ImportError as e:
        st.error(f"Q&A page not found: {e}")


def show_library_page():
    """Import and show the library page."""
    try:
        from src.pages.library import show_library_interface

        show_library_interface()
    except ImportError as e:
        st.error(f"Library page not found: {e}")


def show_settings_page():
    """Import and show the settings page."""
    try:
        from src.pages.settings import show_settings_interface

        show_settings_interface()
    except ImportError as e:
        st.error(f"Settings page not found: {e}")


if __name__ == "__main__":
    main()