<?php 
if (!defined('IN_SITE')) {
    die('The Request Not Found');
}
$title = 'Trang Quản Trị | ' . $DVR->site('title');
$body = [
    'title' => 'Danh sách Tool'
];
$body['header'] = '
<style>
    .dashboard-wrap{
        padding-bottom: 24px;
    }

    .page-header-breadcrumb{
        background: linear-gradient(135deg, #0f172a 0%, #1e293b 45%, #334155 100%);
        border-radius: 20px;
        padding: 20px;
        margin-bottom: 24px !important;
        box-shadow: 0 12px 35px rgba(15, 23, 42, 0.12);
        position: relative;
        overflow: hidden;
    }

    .page-header-breadcrumb::before{
        content: "";
        position: absolute;
        right: -60px;
        top: -60px;
        width: 180px;
        height: 180px;
        border-radius: 50%;
        background: rgba(255,255,255,0.06);
    }

    .page-header-breadcrumb::after{
        content: "";
        position: absolute;
        left: -50px;
        bottom: -50px;
        width: 140px;
        height: 140px;
        border-radius: 50%;
        background: rgba(255,255,255,0.04);
    }

    .dashboard-title{
        color: #fff;
        margin: 0;
        position: relative;
        z-index: 2;
    }

    .dashboard-subtitle{
        color: rgba(255,255,255,0.75);
        margin-top: 6px;
        font-size: 13px;
        position: relative;
        z-index: 2;
    }

    .btn-license-check{
        border-radius: 12px;
        padding: 10px 16px;
        font-weight: 600;
        position: relative;
        z-index: 2;
        box-shadow: 0 10px 20px rgba(13, 110, 253, .25);
    }

    .license-alert{
        border: 0;
        border-radius: 18px;
        background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
        box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
        padding: 22px;
        position: relative;
        overflow: hidden;
    }

    .license-alert::before{
        content: "";
        position: absolute;
        right: -30px;
        top: -30px;
        width: 120px;
        height: 120px;
        background: rgba(13, 110, 253, 0.08);
        border-radius: 50%;
    }

    .license-alert h5,
    .license-alert h6,
    .license-alert small,
    .license-alert hr,
    .license-alert .btn,
    .license-alert .btn-close{
        position: relative;
        z-index: 2;
    }

    .license-key{
        display: inline-flex;
        align-items: center;
        gap: 8px;
        padding: 8px 14px;
        background: rgba(220, 38, 38, 0.08);
        color: #dc2626;
        border: 1px dashed rgba(220, 38, 38, 0.25);
        border-radius: 12px;
        font-weight: 700;
        letter-spacing: .4px;
    }

    .copy{
        border-radius: 10px;
        font-weight: 600;
        padding: 6px 12px;
    }

    .live-box{
        display: inline-flex;
        align-items: center;
        justify-content: flex-end;
        width: 100%;
    }

    .live-box img{
        max-width: 70px;
        filter: drop-shadow(0 6px 14px rgba(0,0,0,.16));
    }

    .stats-section-title{
        font-size: 14px;
        font-weight: 700;
        color: #64748b;
        text-transform: uppercase;
        letter-spacing: .8px;
        margin: 10px 0 14px;
        padding-left: 2px;
    }

    .custom-card.hrm-main-card{
        border: 0;
        border-radius: 20px;
        overflow: hidden;
        position: relative;
        transition: all .25s ease;
        box-shadow: 0 10px 25px rgba(15, 23, 42, 0.06);
        height: 100%;
    }

    .custom-card.hrm-main-card:hover{
        transform: translateY(-4px);
        box-shadow: 0 18px 38px rgba(15, 23, 42, 0.12);
    }

    .custom-card.hrm-main-card .card-body{
        padding: 20px;
        position: relative;
        z-index: 2;
    }

    .custom-card.hrm-main-card::before{
        content: "";
        position: absolute;
        top: 0;
        right: 0;
        width: 110px;
        height: 110px;
        border-radius: 0 0 0 100%;
        opacity: .08;
        z-index: 1;
    }

    .custom-card.hrm-main-card.primary::before{ background: #0d6efd; }
    .custom-card.hrm-main-card.secondary::before{ background: #0dcaf0; }
    .custom-card.hrm-main-card.warning::before{ background: #f59e0b; }
    .custom-card.hrm-main-card.danger::before{ background: #dc3545; }

    .stat-card-icon{
        width: 54px;
        height: 54px;
        min-width: 54px;
        border-radius: 16px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        box-shadow: inset 0 1px 0 rgba(255,255,255,.15), 0 8px 18px rgba(0,0,0,.08);
    }

    .stat-card-icon i{
        font-size: 18px;
        color: #fff;
    }

    .stat-card-title{
        font-size: 13px;
        color: #64748b;
        font-weight: 600;
        margin-bottom: 8px;
        display: block;
    }

    .stat-card-value{
        font-size: 26px;
        line-height: 1.2;
        font-weight: 800;
        color: #0f172a;
        margin-bottom: 10px;
        word-break: break-word;
    }

    .stat-card-footer{
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        flex-wrap: wrap;
    }

    .stat-badge{
        border-radius: 999px;
        padding: 6px 12px;
        font-size: 12px;
        font-weight: 700;
    }

    .stat-card-note{
        font-size: 12px;
        color: #94a3b8;
        font-weight: 600;
    }

    .spinner{
        display: none;
    }

    .dashboard-block{
        margin-bottom: 26px;
    }

    @media (max-width: 991.98px){
        .page-header-breadcrumb{
            padding: 18px;
            border-radius: 18px;
        }

        .dashboard-title{
            font-size: 22px !important;
        }
    }

    @media (max-width: 767.98px){
        .page-header-breadcrumb{
            padding: 16px;
        }

        .btn-license-check{
            width: 100%;
            margin-top: 12px;
            justify-content: center;
        }

        .license-alert{
            padding: 18px;
        }

        .stat-card-value{
            font-size: 22px;
        }

        .live-box{
            justify-content: center;
            margin-bottom: 6px;
        }
    }

    @media (max-width: 575.98px){
        .dashboard-title{
            font-size: 20px !important;
        }

        .dashboard-subtitle{
            font-size: 12px;
        }

        .stat-card-icon{
            width: 48px;
            height: 48px;
            min-width: 48px;
            border-radius: 14px;
        }

        .custom-card.hrm-main-card .card-body{
            padding: 16px;
        }

        .license-key{
            display: inline-block;
            word-break: break-all;
        }
    }
</style>
';
$body['footer'] = '';
require_once(__DIR__.'/Header.php');
require_once(__DIR__.'/Sidebar.php');
require_once(__DIR__ . '/../../../core/is_user.php');
CheckLogin();
CheckAdmin();
$month = date('m');
$year = date('Y');
$day = date('d');
?>

<div class="main-content app-content">
    <div class="container-fluid dashboard-wrap">

        <div class="d-md-flex d-block align-items-center justify-content-between my-4 page-header-breadcrumb">
            <div>
                <h1 class="page-title fw-semibold fs-18 mb-0 dashboard-title">Dashboard Quản Trị</h1>
                <div class="dashboard-subtitle">
                    Theo dõi nhanh thống kê hệ thống, giao dịch viên và đơn tố cáo theo thời gian thực
                </div>
            </div>
            <div class="mt-3 mt-md-0">
                <a class="btn btn-primary btn-wave btn-sm btn-license-check"
                   href="https://www.facebook.com/haomilknn"
                   target="_blank">
                    <i class="fa-solid fa-magnifying-glass me-1"></i> KIỂM TRA BẢN QUYỀN
                </a>
            </div>
        </div>

        <div class="alert alert-secondary alert-dismissible fade show custom-alert-icon license-alert mb-4" role="alert">
            <h5 class="mb-2">
                CheckScam Version: <strong style="color:blue;">6.5</strong>
            </h5>

            <h6 class="mb-2">
                Giấy phép kích hoạt website của bạn là:
                <span class="license-key" id="copyKey">VNDEVCODE.COM</span>
                <button class="btn btn-info btn-sm btn-wave copy ms-2"
                        data-clipboard-target="#copyKey"
                        onclick="copy()">
                    Copy
                </button>
            </h6>

            <small>
                Vui lòng bảo mật giấy phép của bạn, chỉ cung cấp cho <strong>TRẦN HÀO DEV</strong> khi cần hỗ trợ.
            </small>

            <hr class="my-3">

            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close">
                <i class="bi bi-x"></i>
            </button>
        </div>

        <div class="row">
            <div class="col-12">
                <div class="live-box mb-2">
                    <img src="https://zshopclone7.cmsnt.net/mod/img/gif-live.gif" width="60" alt="live">
                </div>
            </div>
        </div>

        <div class="dashboard-block">
            <div class="stats-section-title">Thống kê toàn thời gian</div>
            <div class="row g-4">
                <!-- Thành viên đăng ký toàn thời gian -->
                <div class="col-xxl-3 col-xl-3 col-lg-6 col-md-6 col-sm-6">
                    <div class="card custom-card hrm-main-card primary">
                        <div class="card-body">
                            <div class="d-flex align-items-start">
                                <div class="me-3">
                                    <span class="stat-card-icon bg-primary">
                                        <i class="fa-solid fa-users"></i>
                                    </span>
                                </div>
                                <div class="flex-fill">
                                    <span class="stat-card-title">Thành viên đăng ký</span>
                                    <div class="stat-card-value">
                                        <?= format_cash($DVR->num_rows("SELECT * FROM `users`")) ?>
                                        <div class="spinner"><i class="fas fa-spinner fa-spin"></i></div>
                                    </div>
                                    <div class="stat-card-footer">
                                        <span class="badge bg-primary-transparent stat-badge">Toàn thời gian</span>
                                        <span class="stat-card-note">Tổng user hệ thống</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Số giao dịch viên toàn thời gian -->
                <div class="col-xxl-3 col-xl-3 col-lg-6 col-md-6 col-sm-6">
                    <div class="card custom-card hrm-main-card secondary">
                        <div class="card-body">
                            <div class="d-flex align-items-start">
                                <div class="me-3">
                                    <span class="stat-card-icon bg-info">
                                        <i class="fa-solid fa-circle-check"></i>
                                    </span>
                                </div>
                                <div class="flex-fill">
                                    <span class="stat-card-title">Số giao dịch viên</span>
                                    <div class="stat-card-value">
                                        <?= format_cash($DVR->num_rows("SELECT * FROM `gdv`")) ?>
                                        <div class="spinner"><i class="fas fa-spinner fa-spin"></i></div>
                                    </div>
                                    <div class="stat-card-footer">
                                        <span class="badge bg-info-transparent stat-badge">Toàn thời gian</span>
                                        <span class="stat-card-note">Tổng số GDV</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Số đơn tố cáo toàn thời gian -->
                <div class="col-xxl-3 col-xl-3 col-lg-6 col-md-6 col-sm-6">
                    <div class="card custom-card hrm-main-card warning">
                        <div class="card-body">
                            <div class="d-flex align-items-start">
                                <div class="me-3">
                                    <span class="stat-card-icon bg-warning">
                                        <i class="fa-solid fa-triangle-exclamation"></i>
                                    </span>
                                </div>
                                <div class="flex-fill">
                                    <span class="stat-card-title">Số Đơn Tố Cáo</span>
                                    <div class="stat-card-value">
                                        <?= format_cash($DVR->num_rows("SELECT * FROM `tocaoscam`")) ?>
                                        <div class="spinner"><i class="fas fa-spinner fa-spin"></i></div>
                                    </div>
                                    <div class="stat-card-footer">
                                        <span class="badge bg-warning-transparent stat-badge">Toàn thời gian</span>
                                        <span class="stat-card-note">Tổng đơn tố cáo</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Số tiền GDV toàn thời gian -->
                <div class="col-xxl-3 col-xl-3 col-lg-6 col-md-6 col-sm-6">
                    <div class="card custom-card hrm-main-card danger">
                        <div class="card-body">
                            <div class="d-flex align-items-start">
                                <div class="me-3">
                                    <span class="stat-card-icon bg-danger">
                                        <i class="fa-solid fa-circle-dollar-to-slot"></i>
                                    </span>
                                </div>
                                <div class="flex-fill">
                                    <span class="stat-card-title">Số Tiền GDV</span>
                                    <div class="stat-card-value">
                                        <?= format_cash($DVR->get_row("SELECT SUM(`money`) FROM `gdv` ")['SUM(`money`)']); ?>đ
                                        <div class="spinner"><i class="fas fa-spinner fa-spin"></i></div>
                                    </div>
                                    <div class="stat-card-footer">
                                        <span class="badge bg-danger-transparent stat-badge">Toàn thời gian</span>
                                        <span class="stat-card-note">Tổng tiền giao dịch</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="dashboard-block">
            <div class="stats-section-title">Thống kê tháng <?= $month; ?>/<?= $year; ?></div>
            <div class="row g-4">
                <!-- Thành viên đăng ký tháng này -->
                <div class="col-xxl-3 col-xl-3 col-lg-6 col-md-6 col-sm-6">
                    <div class="card custom-card hrm-main-card primary">
                        <div class="card-body">
                            <div class="d-flex align-items-start">
                                <div class="me-3">
                                    <span class="stat-card-icon bg-primary">
                                        <i class="fa-solid fa-users"></i>
                                    </span>
                                </div>
                                <div class="flex-fill">
                                    <span class="stat-card-title">Thành viên đăng ký</span>
                                    <div class="stat-card-value">
                                        <?= format_cash($DVR->num_rows("SELECT * FROM `users` WHERE MONTH(create_date) = $month ")) ?>
                                        <div class="spinner"><i class="fas fa-spinner fa-spin"></i></div>
                                    </div>
                                    <div class="stat-card-footer">
                                        <span class="badge bg-primary-transparent stat-badge">Tháng <?= $month; ?></span>
                                        <span class="stat-card-note">User trong tháng</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Số giao dịch viên tháng này -->
                <div class="col-xxl-3 col-xl-3 col-lg-6 col-md-6 col-sm-6">
                    <div class="card custom-card hrm-main-card secondary">
                        <div class="card-body">
                            <div class="d-flex align-items-start">
                                <div class="me-3">
                                    <span class="stat-card-icon bg-info">
                                        <i class="fa-solid fa-circle-check"></i>
                                    </span>
                                </div>
                                <div class="flex-fill">
                                    <span class="stat-card-title">Số giao dịch viên</span>
                                    <div class="stat-card-value">
                                        <?= format_cash($DVR->num_rows("SELECT * FROM `gdv` WHERE MONTH(ngay) = $month ")) ?>
                                        <div class="spinner"><i class="fas fa-spinner fa-spin"></i></div>
                                    </div>
                                    <div class="stat-card-footer">
                                        <span class="badge bg-info-transparent stat-badge">Tháng <?= $month; ?></span>
                                        <span class="stat-card-note">GDV trong tháng</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Số đơn tố cáo tháng này -->
                <div class="col-xxl-3 col-xl-3 col-lg-6 col-md-6 col-sm-6">
                    <div class="card custom-card hrm-main-card warning">
                        <div class="card-body">
                            <div class="d-flex align-items-start">
                                <div class="me-3">
                                    <span class="stat-card-icon bg-warning">
                                        <i class="fa-solid fa-triangle-exclamation"></i>
                                    </span>
                                </div>
                                <div class="flex-fill">
                                    <span class="stat-card-title">Số Đơn Tố Cáo</span>
                                    <div class="stat-card-value">
                                        <?= format_cash($DVR->num_rows("SELECT * FROM `tocaoscam` WHERE MONTH(ngay) = $month ")) ?>
                                        <div class="spinner"><i class="fas fa-spinner fa-spin"></i></div>
                                    </div>
                                    <div class="stat-card-footer">
                                        <span class="badge bg-warning-transparent stat-badge">Tháng <?= $month; ?></span>
                                        <span class="stat-card-note">Tố cáo tháng này</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Số tiền Scamer -->
                <div class="col-xxl-3 col-xl-3 col-lg-6 col-md-6 col-sm-6">
                    <div class="card custom-card hrm-main-card danger">
                        <div class="card-body">
                            <div class="d-flex align-items-start">
                                <div class="me-3">
                                    <span class="stat-card-icon bg-danger">
                                        <i class="fa-solid fa-triangle-exclamation"></i>
                                    </span>
                                </div>
                                <div class="flex-fill">
                                    <span class="stat-card-title">Số Tiền Scamer</span>
                                    <div class="stat-card-value">
                                        <?= format_cash($DVR->get_row("SELECT SUM(`money`) FROM `tocaoscam` WHERE `status` = 'scam' ")['SUM(`money`)']); ?>đ
                                        <div class="spinner"><i class="fas fa-spinner fa-spin"></i></div>
                                    </div>
                                    <div class="stat-card-footer">
                                        <span class="badge bg-danger-transparent stat-badge">Toàn thời gian</span>
                                        <span class="stat-card-note">Tổng tiền scam</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="dashboard-block">
            <div class="stats-section-title">Thống kê hôm nay</div>
            <div class="row g-4">
                <!-- Thành viên đăng ký hôm nay -->
                <div class="col-xxl-3 col-xl-3 col-lg-6 col-md-6 col-sm-6">
                    <div class="card custom-card hrm-main-card primary">
                        <div class="card-body">
                            <div class="d-flex align-items-start">
                                <div class="me-3">
                                    <span class="stat-card-icon bg-primary">
                                        <i class="fa-solid fa-users"></i>
                                    </span>
                                </div>
                                <div class="flex-fill">
                                    <span class="stat-card-title">Thành viên đăng ký</span>
                                    <div class="stat-card-value">
                                        <?= format_cash($DVR->num_rows("SELECT * FROM `users` WHERE DAY(create_date) = $day")) ?>
                                        <div class="spinner"><i class="fas fa-spinner fa-spin"></i></div>
                                    </div>
                                    <div class="stat-card-footer">
                                        <span class="badge bg-primary-transparent stat-badge">Hôm nay</span>
                                        <span class="stat-card-note">User mới trong ngày</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Giao dịch viên hôm nay -->
                <div class="col-xxl-3 col-xl-3 col-lg-6 col-md-6 col-sm-6">
                    <div class="card custom-card hrm-main-card secondary">
                        <div class="card-body">
                            <div class="d-flex align-items-start">
                                <div class="me-3">
                                    <span class="stat-card-icon bg-info">
                                        <i class="fa-solid fa-circle-check"></i>
                                    </span>
                                </div>
                                <div class="flex-fill">
                                    <span class="stat-card-title">Số giao dịch viên</span>
                                    <div class="stat-card-value">
                                        <?= format_cash($DVR->num_rows("SELECT * FROM `gdv` WHERE DAY(ngay) = $day")) ?>
                                        <div class="spinner"><i class="fas fa-spinner fa-spin"></i></div>
                                    </div>
                                    <div class="stat-card-footer">
                                        <span class="badge bg-info-transparent stat-badge">Hôm nay</span>
                                        <span class="stat-card-note">GDV phát sinh hôm nay</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Đơn tố cáo hôm nay -->
                <div class="col-xxl-3 col-xl-3 col-lg-6 col-md-6 col-sm-6">
                    <div class="card custom-card hrm-main-card warning">
                        <div class="card-body">
                            <div class="d-flex align-items-start">
                                <div class="me-3">
                                    <span class="stat-card-icon bg-warning">
                                        <i class="fa-solid fa-triangle-exclamation"></i>
                                    </span>
                                </div>
                                <div class="flex-fill">
                                    <span class="stat-card-title">Số Đơn Tố Cáo</span>
                                    <div class="stat-card-value">
                                        <?= format_cash($DVR->num_rows("SELECT * FROM `tocaoscam` WHERE DAY(ngay) = $day")) ?>
                                        <div class="spinner"><i class="fas fa-spinner fa-spin"></i></div>
                                    </div>
                                    <div class="stat-card-footer">
                                        <span class="badge bg-warning-transparent stat-badge">Hôm nay</span>
                                        <span class="stat-card-note">Tố cáo phát sinh hôm nay</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Ô trống giữ layout đẹp -->
                <div class="col-xxl-3 col-xl-3 col-lg-6 col-md-6 col-sm-6">
                    <div class="card custom-card hrm-main-card danger">
                        <div class="card-body">
                            <div class="d-flex align-items-start">
                                <div class="me-3">
                                    <span class="stat-card-icon bg-danger">
                                        <i class="fa-solid fa-chart-line"></i>
                                    </span>
                                </div>
                                <div class="flex-fill">
                                    <span class="stat-card-title">Trạng thái hệ thống</span>
                                    <div class="stat-card-value">Online</div>
                                    <div class="stat-card-footer">
                                        <span class="badge bg-danger-transparent stat-badge">Realtime</span>
                                        <span class="stat-card-note">Giao diện nâng cấp</span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>

<?php
require_once(__DIR__.'/Footer.php');
?>