<?php
if(session_status() === PHP_SESSION_NONE){
    session_start();
}

require_once __DIR__ . '/../config.php';

/* ===== CEK LOGIN ===== */
if(!isset($_SESSION['role'])){
    header("Location: ../login.php");
    exit;
}

/* ===== HITUNG DATA ===== */
$jml_masuk = $conn->query("SELECT COUNT(*) as jml FROM pengajuan WHERE status='Menunggu'")->fetch_assoc()['jml'];

$jml_diterima = $conn->query("SELECT COUNT(*) as jml FROM pengajuan WHERE status='Diterima'")->fetch_assoc()['jml'];

$jml_ditolak = $conn->query("SELECT COUNT(*) as jml FROM pengajuan WHERE status='Ditolak'")->fetch_assoc()['jml'];

$jml_selesai = $conn->query("SELECT COUNT(*) as jml FROM pengajuan WHERE no_surat IS NOT NULL")->fetch_assoc()['jml'];
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Admin Panel</title>

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

<style>
body {
    margin:0;
    background:#f1f3f6;
}

/* ===== SIDEBAR ===== */
.sidebar {
    width:220px;
    position:fixed;
    top:0;
    left:0;
    bottom:0;
    background:#1e293b;
    color:white;
    overflow-y:auto;
}

.sidebar a {
    display:block;
    padding:12px;
    color:#cbd5e1;
    text-decoration:none;
}

.sidebar a:hover {
    background:#334155;
    color:white;
}

/* ===== CONTENT ===== */
.content {
    margin-left:220px;
    padding:20px;
}
</style>

</head>

<body>

<!-- SIDEBAR -->
<div class="sidebar">
<h4>📁 Admin Layanan SDA</h4>

<?php if($_SESSION['role'] == 'admin1'){ ?>

<a href="surat_masuk">
📥 Surat Masuk 
<span class="badge bg-danger"><?= $jml_masuk ?></span>
</a>

<a href="surat_diterima">
✅ Surat Diterima 
<span class="badge bg-success"><?= $jml_diterima ?></span>
</a>

<a href="surat_ditolak">
❌ Surat Ditolak 
<span class="badge bg-secondary"><?= $jml_ditolak ?></span>
</a>

<a href="surat_selesai">
📦 Surat Selesai 
<span class="badge bg-primary"><?= $jml_selesai ?></span>
</a>

<a href="survei">📊 Survei</a>

<a href="../login"> 
   🚪 <i class="fa-solid fa-right-from-bracket"></i>
    Logout
</a>

<?php } elseif($_SESSION['role'] == 'admin2'){ ?>

<a href="../admin2/surat_diterima">
📄 Surat Diterima
</a>

<a href="../admin2/surat_selesai">
📦 Surat Selesai
</a>

<a href="../login"> 
   🚪 <i class="fa-solid fa-right-from-bracket"></i>
    Logout
</a>

<?php } ?>

</div>

<!-- CONTENT -->
<div class="content">