{"version":3,"sources":["file-upload-handler.js"],"names":["document","addEventListener","fileInput","getElementById","fileLabel","querySelector","fileListContainer","selectedFiles","renderFileList","innerHTML","length","forEach","file","index","fileItem","createElement","textContent","name","size","toFixed","removeButton","classList","add","splice","removeFile","appendChild","map","join","newFiles","Array","from","files","value","event","dataTransfer","DataTransfer","items"],"mappings":"AAAAA,SAAAC,iBAAA,oBAAA,WACA,MAAAC,EAAAF,SAAAG,eAAA,kCACAC,EAAAJ,SAAAK,cAAA,+CACAC,EAAAN,SAAAG,eAAA,aACA,IAAAI,EAAA,GAeA,SAAAC,IAEAF,EAAAG,UAAA,GAGAF,EAAAG,OAAA,GACAH,EAAAI,SAAA,CAAAC,EAAAC,KACA,MAAAC,EAAAd,SAAAe,cAAA,OACAD,EAAAE,YAAA,GAAAJ,EAAAK,UAAAL,EAAAM,KAAA,MAAAC,QAAA,SAGA,MAAAC,EAAApB,SAAAe,cAAA,UACAK,EAAAJ,YAAA,QACAI,EAAAC,UAAAC,IAAA,MAAA,aAAA,SAAA,OAAA,QACAF,EAAAnB,iBAAA,SAAA,IAeA,SAAAY,GACAN,EAAAgB,OAAAV,EAAA,GACAL,IAjBAgB,CAAAX,KAGAC,EAAAW,YAAAL,GACAd,EAAAmB,YAAAX,MAIAV,EAAAY,YAAAT,EAAAmB,KAAAd,GAAAA,EAAAK,OAAAU,KAAA,OAEAvB,EAAAY,YAAA,aAWAd,EAAAD,iBAAA,UA/CA,WACA,MAAA2B,EAAAC,MAAAC,KAAA5B,EAAA6B,OACAxB,EAAA,IAAAA,KAAAqB,GAGA1B,EAAA8B,MAAA,GAGAxB,OA0CAR,SAAAG,eAAA,eAAAF,iBAAA,UAAAgC,IACA,MAAAC,EAAA,IAAAC,aAGA5B,EAAAI,SAAAC,GAAAsB,EAAAE,MAAAd,IAAAV,KAGAV,EAAA6B,MAAAG,EAAAH,SAIAvB","file":"fileUploadHandler.min.js","sourcesContent":["document.addEventListener('DOMContentLoaded', function () {\r\n const fileInput = document.getElementById('PassportAndHuntingLicenseInput');\r\n const fileLabel = document.querySelector('label[for=\"PassportAndHuntingLicenseInput\"]');\r\n const fileListContainer = document.getElementById('file-list'); // Container for displaying the list of files\r\n let selectedFiles = [];\r\n\r\n // Function to handle updating the label and file list\r\n function updateFileList() {\r\n const newFiles = Array.from(fileInput.files); // Get newly selected files\r\n selectedFiles = [...selectedFiles, ...newFiles]; // Append new files to the list\r\n\r\n // Reset the file input so users can select the same file again if needed\r\n fileInput.value = '';\r\n\r\n // Render the file list and update the label\r\n renderFileList();\r\n }\r\n\r\n // Function to render the list of selected files\r\n function renderFileList() {\r\n // Clear the file list container\r\n fileListContainer.innerHTML = '';\r\n\r\n // If there are selected files, display them\r\n if (selectedFiles.length > 0) {\r\n selectedFiles.forEach((file, index) => {\r\n const fileItem = document.createElement('div');\r\n fileItem.textContent = `${file.name} (${(file.size / 1024).toFixed(2)} KB)`; // Display file name and size\r\n\r\n // Add a \"Remove\" button for each file\r\n const removeButton = document.createElement('button');\r\n removeButton.textContent = 'Fjern';\r\n removeButton.classList.add('btn', 'btn-danger', 'btn-sm', 'ml-2', 'mt-1');\r\n removeButton.addEventListener('click', () => removeFile(index)); // Remove file on click\r\n\r\n // Append the file item and the remove button\r\n fileItem.appendChild(removeButton);\r\n fileListContainer.appendChild(fileItem);\r\n });\r\n\r\n // Update the label to reflect the selected files\r\n fileLabel.textContent = selectedFiles.map(file => file.name).join(', ');\r\n } else {\r\n fileLabel.textContent = 'V\\u00E6lg filer'; // Default label text\r\n }\r\n }\r\n\r\n // Function to remove a file from the list\r\n function removeFile(index) {\r\n selectedFiles.splice(index, 1); // Remove the file from the array\r\n renderFileList(); // Re-render the file list\r\n }\r\n\r\n // Event listener for when the user selects files\r\n fileInput.addEventListener('change', updateFileList);\r\n\r\n // Before form submission, append the selected files back to the file input\r\n document.getElementById('upload-form').addEventListener('submit', (event) => {\r\n const dataTransfer = new DataTransfer();\r\n\r\n // Add all selected files to the DataTransfer object\r\n selectedFiles.forEach(file => dataTransfer.items.add(file));\r\n\r\n // Set the file input's files to the DataTransfer's files so they get submitted with the form\r\n fileInput.files = dataTransfer.files;\r\n });\r\n\r\n // Initialize the file input state on page load\r\n renderFileList();\r\n});"]}