document.addEventListener('DOMContentLoaded', () => {
  const waForm = document.getElementById('waForm');

  if (!waForm) return;

  waForm.addEventListener('submit', function(e){
    e.preventDefault();

    const nama = document.getElementById('nama')?.value.trim();
    const perusahaan = document.getElementById('perusahaan')?.value.trim();
    const phone = document.getElementById('phone')?.value.trim();
    const pesan = document.getElementById('pesan')?.value.trim();

    if (!nama || !phone || !pesan) {
      alert('Mohon lengkapi data wajib terlebih dahulu.');
      return;
    }

    const text = `Halo PT Megah International Indonesia,

Saya ingin konsultasi kebutuhan proyek.

Nama: ${nama}
Perusahaan: ${perusahaan || '-'}
No HP: ${phone}

Kebutuhan Proyek:
${pesan}`;

    const waUrl = `https://wa.me/62811906829?text=${encodeURIComponent(text)}`;

    window.open(waUrl, '_blank');

    waForm.reset();
  });
});