document.addEventListener('DOMContentLoaded', function () {
  document.getElementById('initialPhoto').addEventListener('change', function (event) {
    const fileName = event.target.files[0] ? event.target.files[0].name : 'Upload Foto'
    const label = document.querySelector('label[for="initialPhoto"]')
    label.textContent = fileName
  })

  document.getElementById('reportForm').reset();

  async function populateDropdown() {
    try {
        const response = await fetch('data/damageType.json');
        if (!response.ok) {
            throw new Error('Network response was not ok');
        }
        const dropdownData = await response.json();

        const dropdownMenu = document.getElementById('damageType');

        for (const [key, value] of Object.entries(dropdownData)) {
            const option = document.createElement('option');
            option.value = key;
            option.textContent = value;
            dropdownMenu.appendChild(option);
        }
    } catch (error) {
        console.error('There was a problem with the fetch operation:', error);
    }
  }

  populateDropdown();
})
