import { q as query } from '../../../chunks/db_Du3AmLCY.mjs';
import { f as findOrCreateUser, g as generateToken } from '../../../chunks/user-auth_D4NBmYxs.mjs';
import { a as sendVerificationEmail } from '../../../chunks/email_DspzjvY3.mjs';
export { renderers } from '../../../renderers.mjs';

const POST = async ({ request }) => {
  try {
    const { email } = await request.json();
    if (!email || !email.includes("@")) {
      return new Response(JSON.stringify({ error: "Ongeldig emailadres" }), { status: 400 });
    }
    const user = await findOrCreateUser(email);
    if (user.email_verified) {
      return new Response(JSON.stringify({ error: "Email is al geregistreerd. Gebruik inloggen." }), { status: 400 });
    }
    const token = generateToken();
    await query("UPDATE users SET verification_token = $1 WHERE id = $2", [token, user.id]);
    await sendVerificationEmail(email, token);
    return new Response(JSON.stringify({ ok: true, message: "Check je email voor de bevestigingslink!" }));
  } catch (err) {
    console.error("Register error:", err);
    return new Response(JSON.stringify({ error: "Er ging iets mis" }), { status: 500 });
  }
};

const _page = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.defineProperty({
  __proto__: null,
  POST
}, Symbol.toStringTag, { value: 'Module' }));

const page = () => _page;

export { page };
