// contact-form.js
document.addEventListener('DOMContentLoaded', function () {
    var contactForm = document.getElementById('contact-form');
   
    contactForm.addEventListener('submit', function (event) {
       event.preventDefault();
   
       var name = document.getElementById('name').value;
       var email = document.getElementById('email').value;
       var message = document.getElementById('message').value;
   
       sendMessageToDiscord(name, email, message);
    });
   });
   
   function sendMessageToDiscord(name, email, message) {
    var payload = {
        content: '',
        embeds: [
          {
            title: 'Contact Form Submission',
            color: 5763719, // Green color in decimal RGB format
            fields: [
              { name: 'Name', value: name, inline: true },
              { name: 'Email', value: email, inline: true },
              { name: 'Message', value: message },
            ],
          },
        ],
     };
   
     fetch('https://discord.com/api/webhooks/1164594368137678962/cafbIkGsmkoBob1Rmi3nm0wqxh9TuFgfCtPpOCJp9YBk1_coaYm63edXDX2jBbdGwUtx', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json',
        },
        body: JSON.stringify(payload),
     })
        .then(function (response) {
          console.log('Response:', response);
          return response.json();
        })
        .then(function (data) {
          console.log('Data:', data);
          alert('Your message has been sent successfully!');
        })
        .catch(function (error) {
          console.error('Error:', error);
          alert('Your message has been send! SamVolvo will contact you soon!');
        });
   }