File size: 4,405 Bytes
9b92573
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

// API Endpoints
const API = {
  upload: '/api/upload',
  analyze: '/api/analyze',
  outlines: '/api/outlines',
  search: '/api/search',
  tags: '/api/tags'
};

document.addEventListener('DOMContentLoaded', function() {
    // Initialize components
    initFileUpload();
    initAnalysisDashboard();
    initOutlineEditor();
    initSermonFilter();
    loadSermonLibrary();
});

function initFileUpload() {
const dropzone = document.getElementById('upload-dropzone');
    const fileInput = document.getElementById('file-input');
    
    if (dropzone) {
        dropzone.addEventListener('click', () => fileInput.click());
        
        ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
            dropzone.addEventListener(eventName, preventDefaults, false);
        });

        function preventDefaults(e) {
            e.preventDefault();
            e.stopPropagation();
        }

        ['dragenter', 'dragover'].forEach(eventName => {
            dropzone.addEventListener(eventName, highlight, false);
        });

        ['dragleave', 'drop'].forEach(eventName => {
            dropzone.addEventListener(eventName, unhighlight, false);
        });

        function highlight() {
            dropzone.classList.add('upload-dropzone', 'active');
        }

        function unhighlight() {
            dropzone.classList.remove('active');
        }

        dropzone.addEventListener('drop', handleDrop, false);

        function handleDrop(e) {
            const dt = e.dataTransfer;
            const files = dt.files;
            handleFiles(files);
        }
    }

    if (fileInput) {
        fileInput.addEventListener('change', function() {
            handleFiles(this.files);
        });
    }

    function handleFiles(files) {
        if (files.length > 0) {
            const file = files[0];
            if (file.type === 'text/plain' || file.name.endsWith('.docx')) {
                // Simulate upload and processing
                simulateProcessing(file);
            } else {
                alert('Please upload a .txt or .docx file');
            }
        }
    }

    function simulateProcessing(file) {
        const progressBar = document.getElementById('progress-bar');
        const statusText = document.getElementById('status-text');
        const uploadCard = document.getElementById('upload-card');
        
        if (progressBar && statusText && uploadCard) {
            // Show processing state
            uploadCard.classList.add('processing');
            statusText.textContent = 'Processing...';
            progressBar.style.width = '0%';
            
            // Simulate progress
            let progress = 0;
            const interval = setInterval(() => {
                progress += 5;
                progressBar.style.width = `${progress}%`;
                
                if (progress >= 100) {
                    clearInterval(interval);
                    statusText.textContent = 'Analysis Complete!';
                    uploadCard.classList.remove('processing');
                    uploadCard.classList.add('processed');
                    
                    // In a real app, we would redirect to the analysis page
                    setTimeout(() => {
                        alert('Sermon analysis complete! Redirecting to results...');
                        // window.location.href = '/analysis.html?id=123';
                    }, 1000);
                }
            }, 300);
        }
    }

    // Load sample sermons for the library
    loadSampleSermons();
    
    function loadSampleSermons() {
        const sermons = [
            {
                title: "The Good Shepherd",
                date: "2023-10-22",
                scripture: "John 10:1-18",
                status: "processed",
                wordCount: 2450
            },
            {
                title: "Walking in Faith",
                date: "2023-10-15",
                scripture: "2 Corinthians 5:7",
                status: "processed",
                wordCount: 1875
            },
            {
                title: "The Lord's Prayer",
                date: "2023-10-08",
                scripture: "Matthew 6:9-13",
                status: "processed",
                wordCount: 3200
            }
        ];

        const libraryContainer = document.querySelector('.grid.md\\:grid-cols-2.lg\\: