
// WHEN THE USER CHOOSE A FILE THE NAME OF THE FILE WILL APPEAR IN THE SPAN

document.addEventListener('DOMContentLoaded', function() {
    const fileInputs = document.querySelectorAll('.file-input');

    fileInputs.forEach(fileInput => {
        const fileNameSpan = fileInput.parentElement.querySelector('.file-name');
        const fileLabel = fileInput.parentElement.querySelector('.file-label');

        // Event listener to the label "file-label", which triggers a click on the hidden file input "file-input"
        fileLabel.addEventListener('click', () => {
            fileInput.click();
        });

        fileInput.addEventListener('change', (event) => {
            const selectedFiles = event.target.files;
            if (selectedFiles.length > 0) {
                const fileNames = Array.from(selectedFiles).map(file => file.name).join(', ');
                fileNameSpan.textContent = fileNames;
            } else {
                fileNameSpan.textContent = 'Upload Documents (PDF, docx)';
            }
        });
    });
});
