<?php
session_start();
include '../config/koneksi.php';

if(!isset($_SESSION['admin'])){
    header("Location: ../login.php");
    exit;
}

$total_pendaftar = mysqli_num_rows(mysqli_query($conn,"SELECT * FROM pendaftar"));

$total_atph = mysqli_num_rows(mysqli_query($conn,
"SELECT * FROM pendaftar WHERE jurusan='ATPH'"));

$total_atu = mysqli_num_rows(mysqli_query($conn,
"SELECT * FROM pendaftar WHERE jurusan='ATU'"));

$total_pplg = mysqli_num_rows(mysqli_query($conn,
"SELECT * FROM pendaftar WHERE jurusan='PPLG'"));

$total_dkv = mysqli_num_rows(mysqli_query($conn,
"SELECT * FROM pendaftar WHERE jurusan='DKV'"));

$total_tsm = mysqli_num_rows(mysqli_query($conn,
"SELECT * FROM pendaftar WHERE jurusan='TSM'"));

$total_tptup = mysqli_num_rows(mysqli_query($conn,
"SELECT * FROM pendaftar WHERE jurusan='TPTUP'"));

$data = mysqli_query($conn,
"SELECT * FROM pendaftar ORDER BY id DESC LIMIT 5");
?>

<!DOCTYPE html>
<html lang="id">
<head>

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Admin SPMB</title>

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">

<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css">

<style>

body{
    background:#f4f6f9;
    font-family:'Segoe UI',sans-serif;
}

/* Navbar */
.navbar{
    background:linear-gradient(45deg,#0d6efd,#0b5ed7);
}

/* Sidebar */
.sidebar{
    width:260px;
    min-height:100vh;
    background:#0d1b2a;
    position:fixed;
    left:0;
    top:0;
    color:white;
    padding-top:20px;
}

.sidebar .logo{
    text-align:center;
    margin-bottom:30px;
}

.sidebar .logo h4{
    font-weight:700;
}

.sidebar a{
    display:block;
    color:white;
    padding:15px 25px;
    text-decoration:none;
    transition:0.3s;
    font-size:15px;
}

.sidebar a:hover{
    background:#1b263b;
    padding-left:35px;
}

.sidebar a i{
    width:25px;
}

/* Main Content */
.main-content{
    margin-left:260px;
    padding:20px;
}

/* Hero */
.hero-card{
    background:linear-gradient(135deg,#0d6efd,#0b5ed7);
    border-radius:25px;
    color:white;
    overflow:hidden;
    padding:40px;
    position:relative;
}

.hero-card img{
    max-width:250px;
}

.hero-title{
    font-size:40px;
    font-weight:700;
}

/* Card Statistik */
.stat-card{
    border:none;
    border-radius:20px;
    color:white;
    padding:25px;
    box-shadow:0 10px 25px rgba(0,0,0,0.08);
    transition:0.3s;
}

.stat-card:hover{
    transform:translateY(-5px);
}

.stat-card i{
    font-size:40px;
    opacity:0.8;
}

.stat-card h2{
    font-weight:700;
}

/* Table */
.card-table{
    border:none;
    border-radius:20px;
    overflow:hidden;
    box-shadow:0 5px 20px rgba(0,0,0,0.08);
}

.table thead{
    background:#0d6efd;
    color:white;
}

/* Responsive */
@media(max-width:992px){

    .sidebar{
        position:relative;
        width:100%;
        min-height:auto;
    }

    .main-content{
        margin-left:0;
    }

}

</style>

</head>
<body>

<!-- Sidebar -->
<div class="sidebar">

<div class="logo">
<h4>SPMB ADMIN</h4>
<p>SMKN 1 CIKAUM</p>
</div>

<a href="dashboard.php">
<i class="fa fa-home"></i> Dashboard
</a>

<a href="data_pendaftar.php">
<i class="fa fa-users"></i> Data Pendaftar
</a>



<a href="statistik.php">
<i class="fa fa-chart-bar"></i> Statistik
</a>


<a href="logout.php">
<i class="fa fa-sign-out-alt"></i> Logout
</a>

</div>

<!-- Main -->
<div class="main-content">

<!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-dark rounded-4 shadow-sm px-4 mb-4">

<div class="container-fluid">

<span class="navbar-brand fw-bold">
Admin SPMB
</span>

<div class="text-white">
<i class="fa fa-user-circle"></i>
Administrator
</div>

</div>

</nav>

<!-- Hero -->
<div class="hero-card mb-4">

<div class="row align-items-center">

<div class="col-lg-8">

<h5>🎓 Selamat Datang Admin</h5>

<h1 class="hero-title">
Dashboard SPMB<br>
SMKN 1 CIKAUM
</h1>

<p class="mt-3">
Kelola seluruh data pendaftaran peserta didik baru
dengan mudah dan modern.
</p>

<a href="data_pendaftar.php"
class="btn btn-light rounded-pill px-4 fw-bold">

<i class="fa fa-users"></i>
Lihat Data Pendaftar
</a>

</div>
<div class="col-lg-4 text-center">
<img src="../assets/img/hero.png"
class="img-fluid">
</div>
</div>
</div>

<!-- Statistik -->
<div class="row g-4 mb-4">
<div class="col-md-3">
<div class="stat-card bg-info">
<div class="d-flex justify-content-between align-items-center">
<div>
<h6>Total Pendaftar</h6>
<h2><?= $total_pendaftar ?></h2>
</div>
<i class="fa fa-user-graduate"></i>
</div>
</div>
</div>

<div class="col-md-3">
<div class="stat-card bg-success">
<div class="d-flex justify-content-between align-items-center">
<div>
<h6>Jurusan ATPH</h6>
<h2><?= $total_atph ?></h2>
</div>
<i class="fa fa-seedling"></i>
</div>
</div>
</div>

<div class="col-md-3">
<div class="stat-card bg-success">
<div class="d-flex justify-content-between align-items-center">
<div>
<h6>Jurusan ATU</h6>
<h2><?= $total_atu ?></h2>
</div>
<i class="fa fa-dove"></i>
</div>
</div>
</div>

<div class="col-md-3">
<div class="stat-card bg-danger">
<div class="d-flex justify-content-between align-items-center">
<div>
<h6>Jurusan PPLG</h6>
<h2><?= $total_pplg ?></h2>
</div>
<i class="fa fa-computer"></i>
</div>
</div>
</div>

<div class="col-md-3">
<div class="stat-card bg-danger">
<div class="d-flex justify-content-between align-items-center">
<div>
<h6>Jurusan DKV</h6>
<h2><?= $total_dkv ?></h2>
</div>

<i class="fa fa-palette"></i>
</div>
</div>
</div>

<div class="col-md-3">
<div class="stat-card bg-primary">
<div class="d-flex justify-content-between align-items-center">
<div>
<h6>Jurusan TSM</h6>
<h2><?= $total_tsm ?></h2>
</div>
<i class="fa fa-car"></i>
</div>
</div>
</div>

<div class="col-md-3">
<div class="stat-card bg-primary">
<div class="d-flex justify-content-between align-items-center">
<div>
<h6>Jurusan TPTUP</h6>
<h2><?= $total_tptup ?></h2>
</div>
<i class="fa fa-snowflake"></i>
</div>
</div>
</div>

<div class="col-md-3">
<div class="stat-card bg-info">
<div class="d-flex justify-content-between align-items-center">
<div>
<h6>Total Pendaftar</h6>
<h2><?= $total_pendaftar ?></h2>
</div>
<i class="fa fa-user"></i>
</div>
</div>
</div>


</div>
<!-- Table -->
<div class="card card-table">

<div class="card-header bg-white p-4 border-0">

<h5 class="fw-bold mb-0">
<i class="fa fa-users"></i>
Pendaftar Terbaru
</h5>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover align-middle">

<thead>
<tr>
<th>No</th>
<th>Nama</th>
<th>NISN</th>
<th>Jurusan</th>
<th>No HP</th>
<th>Tanggal</th>
</tr>
</thead>

<tbody>

<?php
$no=1;
while($d=mysqli_fetch_array($data)){
?>

<tr>
<td><?= $no++ ?></td>
<td>
<b><?= $d['nama'] ?></b>
</td>
<td><?= $d['nisn'] ?></td>
<td>
<span class="badge bg-primary">
<?= $d['jurusan'] ?>
</span>
</td>
<td><?= $d['no_hp'] ?></td>
<td><?= date('d M Y',strtotime($d['tanggal_daftar'])) ?></td>
</tr>

<?php } ?>
</tbody>
</table>
</div>
</div>
</div>

<!-- Footer -->
<div class="text-center mt-4 text-muted">
© 2026 SPMB SMKN 1 CIKAUM
</div>

</div>

</body>
</html>