// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0

/*
 *        interstellar_development website
 *        Copyright (C) 2024 interstellar_development
 *
 *        This program is free software: you can redistribute it and/or modify
 *        it under the terms of the GNU Affero General Public License as
 *        published by the Free Software Foundation, either version 3 of the
 *        License, or (at your option) any later version.
 *
 *        This program is distributed in the hope that it will be useful,
 *        but WITHOUT ANY WARRANTY; without even the implied warranty of
 *        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *        GNU Affero General Public License for more details.
 *
 *        You should have received a copy of the GNU Affero General Public License
 *        along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

// contact-form.js

document.addEventListener('DOMContentLoaded', function() {
  const contactForm = document.getElementById('contactForm');

  if (contactForm) {
    contactForm.addEventListener('submit', function(event) {
      event.preventDefault(); // Prevent the form from submitting the traditional way

      // Generate a random ticket number
      const ticketNumber = Math.floor(Math.random() * 1000000); // Generates a random number between 0 and 999999

      // Retrieve form values
      const name = encodeURIComponent(document.getElementById('name').value);
      const email = encodeURIComponent(document.getElementById('email').value);
      const message = encodeURIComponent(document.getElementById('message').value);

      // Construct the mailto link
      const subject = `Support Ticket #${ticketNumber}`;
      const body = `Name: ${name}%0AEmail: ${email}%0AMessage:%0A${message}`;
      const mailtoLink = `mailto:example@example.com?subject=${subject}&body=${body}`;

      // Open the default mail client
      window.location.href = mailtoLink;
    });
  }
});

// @license-end