File size: 4,138 Bytes
0e916e6
f5cfb50
 
 
 
0e916e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b5866be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f5cfb50
 
b5866be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
000d745
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f5cfb50
 
 
 
 
 
 
 
 
 
 
 
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

// Main application script
document.addEventListener('DOMContentLoaded', function() {
    console.log('LegalEagle CaseSync Portal initialized');
    
    // Initialize bottom sheet behavior
    const contextPanel = document.querySelector('.context-panel');
    if (contextPanel) {
        const handle = contextPanel.querySelector('.bottom-sheet-handle');
        if (handle) {
            handle.addEventListener('click', () => {
                contextPanel.classList.toggle('expanded');
            });
        }
    }

    // Initialize bottom nav active state
    const navItems = document.querySelectorAll('custom-bottom-nav .nav-item');
    navItems.forEach(item => {
        item.addEventListener('click', function() {
            navItems.forEach(i => i.classList.remove('active'));
            this.classList.add('active');
        });
    });
// Mobile panel toggles
    document.querySelectorAll('.panel-toggle').forEach(toggle => {
        toggle.addEventListener('click', () => {
            const panel = toggle.nextElementSibling;
            panel.style.display = panel.style.display === 'none' ? 'block' : 'none';
            toggle.querySelector('i').setAttribute('data-feather', 
                panel.style.display === 'none' ? 'chevron-down' : 'chevron-up');
            feather.replace();
        });
    });

    // Document preview handler
    document.querySelectorAll('[data-preview]').forEach(el => {
        el.addEventListener('click', async (e) => {
            const fileUrl = e.target.dataset.preview;
            if(fileUrl.endsWith('.pdf')) {
                // Use PDF.js for PDF preview
                window.open(`/pdf-viewer.html?file=${encodeURIComponent(fileUrl)}`, '_blank');
            } else {
                // Fetch and display text-based files
                const res = await fetch(fileUrl);
                const content = await res.text();
                // Show in modal
                showPreviewModal(content);
            }
        });
    });
});

function showPreviewModal(content) {
    // Implementation for preview modal
    const modal = document.createElement('div');
    modal.className = 'fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center p-4';
    modal.innerHTML = `
        <div class="bg-white rounded-lg max-w-full max-h-full w-full md:w-3/4 h-3/4 overflow-auto p-4">
            <div class="flex justify-between items-center mb-4">
                <h3 class="text-lg font-bold">Document Preview</h3>
                <button class="text-gray-500" onclick="this.parentElement.parentElement.parentElement.remove()">
                    <i data-feather="x"></i>
                </button>
            </div>
            <pre class="whitespace-pre-wrap font-sans">${content}</pre>
        </div>
    `;
    document.body.appendChild(modal);
    feather.replace();
}
// Document preview handlers
function setupDocumentPreview() {
  document.querySelectorAll('[data-preview]').forEach(el => {
    el.addEventListener('click', async (e) => {
      const fileUrl = e.target.dataset.preview;
      if(fileUrl.endsWith('.pdf')) {
        // Use PDF.js for PDF preview
        window.open(`/pdf-viewer.html?file=${encodeURIComponent(fileUrl)}`, '_blank');
      } else if(fileUrl.endsWith('.docx')) {
        // Use Mammoth.js for DOCX preview
        const res = await fetch(fileUrl);
        const arrayBuffer = await res.arrayBuffer();
        const result = await mammoth.extractRawText({arrayBuffer});
        showPreviewModal(result.value);
      } else {
        // Plain text files
        const res = await fetch(fileUrl);
        const content = await res.text();
        showPreviewModal(content);
      }
    });
  });
}

// Helper functions
function formatDate(dateString) {
    const options = { year: 'numeric', month: 'short', day: 'numeric' };
    return new Date(dateString).toLocaleDateString('en-US', options);
}

function calculateDaysUntil(dateString) {
    const today = new Date();
    const targetDate = new Date(dateString);
    const diffTime = targetDate - today;
    return Math.ceil(diffTime / (1000 * 60 * 60 * 24)); 
}