
function register(event)
{
    event
    

    var input = event;
    var obj = {};

    var data = new FormData(event);
    data.forEach((i, x) => {
        obj[x] = i;
    })


    document.querySelector("#sbtn").innerHTML = "<b>Processing...</b>";
    document.querySelector("#sbtn").disabled = true;

    //check for password 
    if (input.elements.password.value != input.elements.password2.value) {
        Swal.fire({
            icon: 'error',
            title: "Password did not match",
            text: "password provided did not match check and re submit again "
        });
        document.querySelector("#sbtn").innerHTML = "<b>Register</b>";
        document.querySelector("#sbtn").disabled = false;
        return 0;
    }

    let i = fetch("/register", {
        method: "POST",
        body: JSON.stringify({ "form": obj }),
        headers: { "Content-type": "application/json; charset=utf-8" },

    }).then(x => {

        if (x.status == 200) {
            x.json().then(data => {
                Swal.fire({
                    icon: 'success',
                    title: "success",
                    text: "Account Registered Successful You Can now Login"
                });
                console.log(data);
                location = "/login";

                document.querySelector("#sbtn").disabled = false;
            })
        } else {
            x.json().then(data => {
                Swal.fire({
                    icon: 'error',
                    title: "Registration error ",
                    text: data.error??data.message
                });
                console.log(data.error??data.message);
                document.querySelector("#sbtn").innerHTML = "<b>Register</b>";
                document.querySelector("#sbtn").disabled = false;
            })

        }
    });




    console.log(input);
}