export function initWaitlistForm() {
  const form = document.getElementById('waitlist-form') as HTMLFormElement;
  const successMessage = document.getElementById('form-success');
  
  if (!form || !successMessage) return;
  
  form.addEventListener('submit', async (e) => {
    e.preventDefault();
    
    const submitButton = form.querySelector('button[type="submit"]') as HTMLButtonElement;
    const formText = submitButton.querySelector('.form-text');
    const formLoading = submitButton.querySelector('.form-loading');
    
    formText?.classList.add('hidden');
    formLoading?.classList.remove('hidden');
    submitButton.disabled = true;
    
    const formData = new FormData(form);
    const email = formData.get('email') as string;
    const company = formData.get('company') as string;
    
    const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
    if (!emailRegex.test(email)) {
      alert('Please enter a valid email address');
      formText?.classList.remove('hidden');
      formLoading?.classList.add('hidden');
      submitButton.disabled = false;
      return;
    }
    
    await new Promise(resolve => setTimeout(resolve, 1500));
    
    form.style.display = 'none';
    successMessage.classList.remove('hidden');
    
    console.log('Waitlist submission:', { email, company, timestamp: new Date().toISOString() });
  });
}