<?php
$title = 'Đăng Nhập - ' . $DVR->site('site_ten');
$body['header'] = '';
$body['footer'] = '';
require_once __DIR__ . '/header.php';
require_once __DIR__ . '/nav.php';
//CheckLogin();
?>

<div id="main" class="main">
    <div class="section-gap section-report">
        <form method="post" class="form-theme" id="reportForm" enctype="multipart/form-data">
            <div class="container">
                <div class="row justify-content-center">
                    <div class="col-12">
                        <div class="section-heading">
                            <div class="title">
                                Đăng Nhập
                            </div>
                            <div class="line"></div>
                        </div>
                    </div>
                    <div class="col-md-10 col-lg-8">
                        <div class="row row-col-10">
                                    <div class="col-md-6 col-12 py-md-0">
                                <div class="form-theme_item">
                                    <input type="text" class="form-theme_item__input"
                                           id="username" name="username" value="<?=$DVR->site('status_demo') == 1 ? 'admin' : '';?>">
                                    <label class="form-theme_item__label" for="">
                                        Tài Khoản <span class="font-weight-bold text-danger">*</span>
                                    </label>
                                </div>
                            </div>
                            <div class="col-md-6 col-12 py-md-0">
                                <div class="form-theme_item">
                                    <input type="text" class="form-theme_item__input" id="password" value="<?=$DVR->site('status_demo') == 1 ? 'admin' : '';?>" name="password">
                                    <label class="form-theme_item__label" for="">
                                        Mật Khẩu <span class="font-weight-bold text-danger">*</span>
                                    </label>
                                </div>
                            </div>

                            <div class="col-12 mt-4">
                                <div class="form-theme_item text-center">
                                    <button id="btnLogin" type="submit" name="submit" class="btn-theme btn-theme_primary">
                                       Đăng Nhập
                                        <span></span>
                                    </button>
                                    <div class="form-theme_item__desc p-1 pb-0 text-muted"> Nếu bạn không có tài khoản, thì bạn hãy bấm <a href="/dang-ky" target="_blank">Đăng Ký</a></div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.js"></script>

<script type="text/javascript">
    $("#btnLogin").on("click", function() {
        $('#btnLogin').html('<i class="fa fa-spinner fa-spin"></i> Đang xử lý...').prop(
            'disabled',
            true);
        $.ajax({
            url: "<?=base_url('ajaxs/client/login.php');?>",
            method: "POST",
            dataType: "JSON",
            data: {
                username: $("#username").val(),
                password: $("#password").val(),
            },
            success: function(respone) {
                if (respone.status == 'success') {
                    Swal.fire("Thành Công",
                    respone.msg,
                    "success"
                    );
                    setTimeout("location.href = '<?=BASE_URL('');?>';", 500);
                } else {
                    Swal.fire("Thất Bại",
                    respone.msg,
                    "error"
                    );
                }
                $('#btnLogin').html('<i class="fas fa-sign-in-alt"></i> Đăng Nhập').prop('disabled',
                    false);
            },
            error: function() {
                cuteToast({
                    type: "error",
                    message: 'Không thể xử lý',
                    timer: 5000
                });
                $('#btnLogin').html('<i class="fas fa-sign-in-alt"></i> Đăng Nhập').prop('disabled',
                    false);
            }

        });
    });
    </script>

<?php require_once __DIR__ . '/footer.php'; ?>
