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

document.getElementById('forgot-form').addEventListener('submit', async (e) => {
  e.preventDefault();
  const errorBox = document.getElementById('error');
  const okBox = document.getElementById('ok');
  errorBox.textContent = '';
  okBox.textContent = '';
  try {
    await api('POST', '/api/v1/auth/forgot', {
      email: document.getElementById('email').value.trim(),
    });
    okBox.textContent = 'If an account with that email exists, a reset link is on its way.';
  } catch (err) {
    errorBox.textContent = err.code === 'smtp_disabled'
      ? 'Email is not configured on this server — ask an administrator to reset your password.'
      : err.message;
  }
});
