<!DOCTYPE html>
<html lang="vi">

<head>
    <?php require_once('head.php');?>
    <title>AdminLTE 3 | Dashboard</title>
    <?php require_once('nav.php');?>
</head>
<?php
if (isset($_GET['del'])) {
    $del = $_GET['del'];
    echo '<script> if (confirm("Bạn có chắc muốn xoá thành viên này")) {
        window.location="?delete='.$del.'";
    } else {
        alert("Đã huỷ");
        window.location="?ok";
    }
    </script>';
}
?>

<?php
if (isset($_GET['delete'])) 
{
    $delete = $_GET['delete'];

    $create = mysqli_query($ketnoi,"DELETE FROM `users` WHERE `id` = '".$delete."' ");

    if ($create)
    {
      echo '<script type="text/javascript">swal("Thành Công","Xóa thành công","success");setTimeout(function(){ location.href = "chuyen-muc.php" },500);</script>'; 
    }
    else
    {
      echo '<script type="text/javascript">swal("Lỗi","Lỗi máy chủ","error");setTimeout(function(){ location.href = "chuyen-muc.php" },1000);</script>'; 
    }
}
?>
<body class="hold-transition sidebar-mini layout-fixed" style="font-family: 'Plus Jakarta Sans', 'Inter', sans-serif;">
    <div class="wrapper">
        <div class="content-wrapper">
            <div class="content-header">
                <div class="container-fluid">
                    <div class="row mb-3 align-items-center">
                        <div class="col-sm-6">
                            <h1 class="m-0 fw-boldest text-gray-800">
                                <i class="bi bi-people-fill text-primary me-2"></i>Quản Lý Thành Viên
                            </h1>
                        </div><div class="col-sm-6">
                            <ol class="breadcrumb float-sm-right bg-transparent p-0 m-0">
                                <li class="breadcrumb-item"><a href="#">Home</a></li>
                                <li class="breadcrumb-item active">Thành viên</li>
                            </ol>
                        </div></div></div></div>
            <section class="content">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-md-12">
                            <div class="card card-default shadow-sm rounded-3 overflow-hidden">
                                <div class="card-header border-bottom border-gray-100 py-4 bg-white">
                                    <h3 class="card-title fw-bold text-uppercase tracking-wider text-secondary fs-7 m-0">
                                        <i class="bi bi-list-stars text-primary me-1"></i>Danh sách tài khoản hệ thống
                                    </h3>
                                </div>
                                
                                <div class="card-body p-0">
                                    <div class="table-responsive">
                                        <table id="datatable1" class="table table-row-bordered table-row-gray-200 align-middle gs-6 gy-4 mb-0">
                                            <thead>
                                                <tr class="fw-boldest text-muted text-uppercase fs-8 tracking-widest bg-light bg-opacity-60 border-bottom border-gray-200">
                                                    <th class="text-center" style="width: 60px">ID</th>
                                                    <th class="min-w-150px">Tài khoản</th>
                                                    <th class="min-w-200px">Email</th>
                                                    <th class="min-w-120px">Số dư (VND)</th>
                                                    <th class="min-w-160px text-center">Cấp bậc / Rank</th>
                                                    <th class="min-w-100px text-center">Trạng thái</th>
                                                    <th class="min-w-160px text-end pe-6">Thao tác</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php
                                                $result = mysqli_query($ketnoi, "SELECT * FROM `users` ORDER BY id DESC");
                                                while($row = mysqli_fetch_assoc($result)) {
                                                ?>
                                                <tr class="text-gray-800 fs-7 border-bottom border-gray-100 text-hover-bg-light">
                                                    <td class="text-center font-monospace fw-bold text-muted"><?=htmlspecialchars($row['id']);?></td>
                                                    
                                                    <td>
                                                        <span class="fw-boldest text-gray-900" style="font-family: 'JetBrains Mono', monospace;">
                                                            <?=htmlspecialchars($row['username']);?>
                                                        </span>
                                                    </td>

                                                    <td class="text-gray-600"><?=htmlspecialchars($row['email']);?></td>
                                                    
                                                    <td class="fw-bold text-success font-monospace fs-6">
                                                        <?=number_format($row['money']);?>đ
                                                    </td>
                                                    
                                                    <td class="text-center">
                                                        <?php 
                                                            $lvl = (int)$row['level'];
                                                            if ($lvl == 0) {
                                                                echo '<span class="badge badge-light-secondary text-gray-600 fw-boldest px-3 py-2 shadow-xs border"><i class="bi bi-shield me-1"></i>Thạch Anh</span>';
                                                            } elseif ($lvl == 1) {
                                                                echo '<span class="badge fw-boldest px-3 py-2 shadow-xs" style="color: #ffffff; background-color: #B87333;"><i class="bi bi-gem me-1 text-white"></i>Đồng (Bronze)</span>';
                                                            } elseif ($lvl == 2) {
                                                                echo '<span class="badge badge-secondary text-white fw-boldest px-3 py-2 shadow-xs" style="background-color: #a0a0a0;"><i class="bi bi-gem me-1"></i>Bạc (Silver)</span>';
                                                            } elseif ($lvl == 3) {
                                                                echo '<span class="badge badge-warning text-white fw-boldest px-3 py-2 shadow-xs" style="background-color: #ff9800;"><i class="bi bi-gem me-1"></i>Vàng (Gold)</span>';
                                                            } elseif ($lvl == 4) {
                                                                echo '<span class="badge badge-primary text-white fw-boldest px-3 py-2 shadow-xs"><i class="bi bi-shield-shaded me-1"></i>Bạch Kim</span>';
                                                            } elseif ($lvl == 5) {
                                                                echo '<span class="badge badge-success text-white fw-boldest px-3 py-2 shadow-xs"><i class="bi bi-gem me-1"></i>Lục Bảo</span>';
                                                            } elseif ($lvl == 6) {
                                                                echo '<span class="badge badge-info text-white fw-boldest px-3 py-2 shadow-xs"><i class="bi bi-gem me-1"></i>Kim Cương</span>';
                                                            } elseif ($lvl == 9) {
                                                                echo '<span class="badge badge-danger text-white fw-boldest px-3 py-2 shadow-xs"><i class="bi bi-person-fill-lock me-1"></i>Admin</span>';
                                                            } else {
                                                                echo '<span class="badge badge-light text-muted fw-boldest px-3 py-2">Không rõ</span>';
                                                            }
                                                        ?>
                                                    </td>
                                                    
                                                    <td class="text-center">
                                                        <?php if((int)$row['bannd'] == 0): ?>
                                                            <span class="badge bg-light-success text-success fw-bold px-2.5 py-1.5 border border-success border-opacity-25 rounded-2">Active</span>
                                                        <?php else: ?>
                                                            <span class="badge bg-light-danger text-danger fw-bold px-2.5 py-1.5 border border-danger border-opacity-25 rounded-2">Banned</span>
                                                        <?php endif; ?>
                                                    </td>
                                                    
                                                    <td class="text-end pe-6">
                                                        <a href="edit-user.php?id=<?=htmlspecialchars($row['id']);?>" class="btn btn-sm btn-primary fw-bold px-3 py-1.5 me-1 rounded-2 shadow-sm">
                                                            <i class="bi bi-pencil-square me-1"></i> Sửa
                                                        </a>
                                                        <a href="?del=<?=htmlspecialchars($row['id']);?>" class="btn btn-sm btn-danger fw-bold px-3 py-1.5 rounded-2 shadow-sm" onclick="return confirm('Bạn có chắc chắn muốn xóa thành viên này không?')">
                                                            <i class="bi bi-trash3 me-1"></i> Xóa
                                                        </a>
                                                    </td>
                                                </tr>
                                                <?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                            </div>
                    </div>
                    </div></section>
            </div>
        <aside class="control-sidebar control-sidebar-dark">
            </aside>
        </div>
    <!-- ./wrapper -->

    <?php require_once('foot.php');?>
</body>

</html>