// 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\\: