document.getElementById('csvForm').addEventListener('submit', (event) => {
    event.preventDefault();
    var fileInput = document.querySelector('input[name="csvfile"]');
    var message = document.getElementById('message');
    message.textContent = ''; // Clear any previous messages

    if (fileInput.files.length === 0) {
        message.textContent = 'Please select a CSV file.';
        return;
    }

    var file = fileInput.files[0];
    if (file.type !== 'text/csv') {
        message.textContent = 'Please upload a valid CSV file.';
        return;
    }

    var formData = new FormData();
    formData.append('csvfile', file);

    fetch('verify_license.php', { // Adjust the URL to your PHP script
        method: 'POST',
        body: formData
    })
    .then(response => response.json())
    .then(result => {
        if (result.status === 'success') {
            message.textContent = 'CSV file uploaded and processed successfully!';
            localStorage.setItem('csvUploaded', 'true'); // Set local storage flag
            closePopup();
        } else {
            message.textContent = result.message; // Show error message from the server
        }
    })
    .catch(error => {
        message.textContent = 'An error occurred during upload.';
    });
});

function closePopup() {
    document.getElementById('popup_token').classList.remove('show');
    document.querySelector('.blur-background').style.display = 'none';
}






