function pesan() {
    const Toast = Swal.mixin({
        toast: true,
        position: "top-end",
        showConfirmButton: false,
        timer: 3000,
        timerProgressBar: true,
        didOpen: (toast) => {
            toast.onmouseenter = Swal.stopTimer;
            toast.onmouseleave = Swal.resumeTimer;
        }
    });
    Toast.fire({
        icon: "success",
        title: "Please check youre email and follow the instructions"
    });
}

function gagal(txt) {
    const Toast = Swal.mixin({
        toast: true,
        position: "top-end",
        showConfirmButton: false,
        timer: 2000,
        timerProgressBar: false,
        didOpen: (toast) => {
            toast.onmouseenter = Swal.stopTimer;
            toast.onmouseleave = Swal.resumeTimer;
        }
    });
    Toast.fire({
        icon: "error",
        title: txt
    });
}


$("#loginpage").on("submit", function (e) {
    var base_url = $("#base_url").val();
    e.preventDefault();
    $.ajax({
        url: base_url + "Auth/masuk",
        type: "POST",
        data: new FormData(this),
        contentType: false,
        cache: false,
        processData: false,
        success: function (data) {
            //alert(data);

            if (data == 0) {
                gagal('Login gagal');
                document.getElementById('strUsername').value = "";
                document.getElementById('strPassword').value = "";
            }

            if (data == 100) {
                gagal('IP Anda belum terdaftar');
                document.getElementById('strUsername').value = "";
                document.getElementById('strPassword').value = "";
            }

            if (data == 1) {
                let timerInterval;
                Swal.fire({
                    title: "Loading...",
                    timer: 1000,
                    timerProgressBar: false,
                    didOpen: () => {
                        Swal.showLoading();
                        const timer = Swal.getPopup().querySelector("b");
                        timerInterval = setInterval(() => {
                            timer.textContent = `${Swal.getTimerLeft()}`;
                        }, 100);
                    },
                    willClose: () => {
                        clearInterval(timerInterval);
                        window.open(base_url + "Home", "_self");
                    }
                });
            }

        }
    });
});