<?php include($_SERVER['DOCUMENT_ROOT'] . "/COMPONENTS/root/path.php"); ?>
<div class="p-3">
    <div class="text-center">
        <a href="<?php echo $website_name; ?>"> <img src="<?php echo $website_name; ?>/assets/images/<?php echo $image; ?>" width="350px" alt="wrapkit"></a>
    </div>
    <h2 class="mt-3 text-center">Sign In</h2>
    <p class="text-center">Enter your email address and password to access your dashboard.</p>
    <form method='POST' action='' id='form_signin' autocomplete='off' validate>
        <div class="row">
            <div class="col-lg-12">
                <div class="form-group">
                    <label class="text-dark" for="username">USERNAME</label>
                    <input class="form-control" name="username" id="username" type="text" placeholder="Enter your email" required>
                </div>
            </div>
            <div class="col-lg-12">
                <div class="form-group">
                    <label class="text-dark" for="password">PASSWORD</label>
                    <input class="form-control" name="password" id="password" type="password" placeholder="Enter your password" required>
                </div>
            </div>
            <div class="col-lg-12 text-center" style="margin-bottom:30px;">
                <button type="submit" class="btn btn-block btn-dark" id="signin"><span class='submitLoader'>Sign In</span></button>
            </div>
            <div class="col-lg-12 text-center mt-5">
                Don't have an account? <a href="#" class="text-danger get-inn" data-url="signup/register-form-super-admin.php">Sign Up</a>
            </div>
        </div>
    </form>
</div>


<script>
    $("#signin").on("click", function() {
        $("#form_signin").submit(function(e) {
            $.ajax({
                url: domain_api + "/signin/signin.php",
                // url: domain_api + "/auth/signin",
                type: "POST",
                data: $(this).serialize(),
                beforeSend: function() {
                    $("#signin").attr("disabled", "disabled");
                    $(".submitLoader").html("<i class='fa fa-spinner fa-spin'></i>");
                },
                success: function(data) {

                    if (data.code == 200) {
                        sessionStorage.removeItem("SigninPage");
                        sessionStorage.setItem("authCode", data.token);
                        sessionStorage.setItem("user", data.user);
                        sessionStorage.setItem("userId", data.data[0].unique_user_id);
                        var token = sessionStorage.getItem("authCode");
                        var role = sessionStorage.getItem("user");
                        var userId = sessionStorage.getItem("userId");
                        $.getJSON(domain_api + "/signin/session.php?token=" + encodeURIComponent(token), function(data) {
                            sessionStorage.setItem("role", data.data[0].role);
                            sessionStorage.setItem("user_nationality", data.data[0].nationality);
                            sessionStorage.setItem("living_town", data.data[0].living_town);
                            sessionStorage.setItem("fullname", data.data[0].fullname);
                            sessionStorage.setItem("dob", data.data[0].dob);
                            sessionStorage.setItem("email", data.data[0].email);
                            sessionStorage.setItem("phone", data.data[0].phone);
                            sessionStorage.setItem("whatsapp_no", data.data[0].whatsapp_no);
                            sessionStorage.setItem("date_added", data.data[0].date_added);
                            var role = sessionStorage.getItem("role");
                            var nationality = sessionStorage.getItem("user_nationality");
                            var path = "/COMPONENTS/super-admin/index.php?userId=" + encodeURIComponent(userId) + "&role=" + encodeURIComponent(role) + "";
                            sessionStorage.setItem("indexURL", path);
                            var path1 = "/COMPONENTS/super-admin/dashboard.php";
                            sessionStorage.setItem('UserType', domain + path);
                            sessionStorage.setItem('ActivePage', domain + path1);
                            $(".preloader1").show();
                            $(".body").load(domain + path, function(data) {
                                $(".submitLoader").html("Sign In");
                                $(".preloader1").fadeOut();
                                $(".sidebar-link:eq(0)").addClass("active");
                                $(".container-fluid").load(domain + path1, function(data) {});
                            });
                        });


                    } else {
                        $(".submitLoader").html("Sign In");
                        swal("Oops!", data.message, "error");
                    }


                    $("#signin").attr("disabled", false);
                },
                error: function(request, error) {
                    swal("Oops!", error, "error");
                    $("#signin").attr("disabled", false);
                },
            });
            e.preventDefault();
        });
        $(this).off();
    });


    $(".get-inn").off().on("click", function() {
        var url = $(this).attr("data-url");
        // alert(url);
        $(".signin-signup-form").load(domain + "/COMPONENTS/" + url, function() {})
    });
</script>