import { postData } from "./client.js";

const registerForm = document.getElementById("registerForm");

if (registerForm) registerForm.onsubmit = async e => {
    e.preventDefault();
    if (registerForm.regPass.value !== registerForm.regVerify.value) {
        alert("Passwords must match");
        return;
    }

    let resultObject = await postData("/register", {
        username: registerForm.regUser.value,
        password: registerForm.regPass.value,
        role: registerForm.regRole.value
    });
    alert(resultObject.message);
    if (resultObject.success === true) {
        window.location.href = "/login";
    }
};
