document.getElementById('uploadForm').addEventListener('submit', function(event) {
    event.preventDefault();

    const fileUrl = document.getElementById('fileUrl').value;
    const progressBar = document.getElementById('progress');
    const progressText = document.getElementById('progressText');
    const progressContainer = document.getElementById('progressBar');

    // Show progress bar
    progressContainer.classList.remove('hidden');

    // Send file URL to the backend
    fetch('/upload', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({ fileUrl }),
    })
    .then(response => response.text())
    .then(data => {
        alert(data); // Show success message
        progressContainer.classList.add('hidden');
        progressBar.style.width = '0%';
        progressText.textContent = '0%';
    })
    .catch(error => {
        console.error('Error:', error);
        alert('File upload failed.');
    });

    // Simulate progress (optional)
    let progress = 0;
    const interval = setInterval(() => {
        progress += 10;
        progressBar.style.width = `${progress}%`;
        progressText.textContent = `${progress}%`;

        if (progress >= 100) {
            clearInterval(interval);
        }
    }, 500);
});