import { api } from '/static/js/api.js';

const form = document.getElementById('register-form');
const errorBox = document.getElementById('error');

form.addEventListener('submit', async (e) => {
  e.preventDefault();
  errorBox.textContent = '';
  try {
    await api('POST', '/api/v1/auth/register', {
      name: document.getElementById('name').value.trim(),
      email: document.getElementById('email').value.trim(),
      password: document.getElementById('password').value,
    });
    window.location.href = '/';
  } catch (err) {
    errorBox.textContent = err.message;
  }
});
