// marketplace.el -- Marketplace developer interest form submission.
// Compiled with: elc --target=js --bundle --minify --obfuscate

fn main() -> Void {
    native_js("(function() {
  var form = document.getElementById('dev-form');
  if (!form) return;
  form.addEventListener('submit', async function(e) {
    e.preventDefault();
    var msg = document.getElementById('dev-msg');
    var btn = form.querySelector('button[type=submit]');
    btn.disabled = true;
    btn.textContent = 'Sending...';
    try {
      var r = await fetch('/api/developer-interest', {
        method: 'POST',
        headers: {'Content-Type': 'application/json'},
        body: JSON.stringify({
          name:  document.getElementById('dev-name').value,
          email: document.getElementById('dev-email').value,
          idea:  document.getElementById('dev-idea').value
        })
      });
      msg.style.display = 'block';
      if (r.ok) {
        msg.textContent = 'Got it. Will review it personally and reach out.';
        msg.style.color = 'var(--navy)';
        form.reset();
      } else {
        msg.textContent = 'Something went wrong. Email developers@neurontechnologies.ai directly.';
        msg.style.color = '#c44';
      }
    } catch(err) {
      msg.style.display = 'block';
      msg.textContent = 'Connection error. Email developers@neurontechnologies.ai directly.';
      msg.style.color = '#c44';
    }
    btn.disabled = false;
    btn.textContent = 'Send interest →';
  });
})()")
}
