<?php
$page_title = "Dashboard";
include 'layout/header.php';
include 'layout/sidebar.php';
require_once '../config.php';

// Stats
$stmt_all = $pdo->query("SELECT COUNT(*) as ttl FROM tbl_pengajuan");
$tot_all = $stmt_all->fetch()->ttl;

$stmt_diterima = $pdo->query("SELECT COUNT(*) as ttl FROM tbl_pengajuan WHERE status='diterima'");
$tot_diterima = $stmt_diterima->fetch()->ttl;

$stmt_diverifikasi = $pdo->query("SELECT COUNT(*) as ttl FROM tbl_pengajuan WHERE status='diverifikasi'");
$tot_diverifikasi = $stmt_diverifikasi->fetch()->ttl;

$stmt_diproses = $pdo->query("SELECT COUNT(*) as ttl FROM tbl_pengajuan WHERE status='diproses'");
$tot_diproses = $stmt_diproses->fetch()->ttl;

$stmt_ditolak = $pdo->query("SELECT COUNT(*) as ttl FROM tbl_pengajuan WHERE status='ditolak'");
$tot_ditolak = $stmt_ditolak->fetch()->ttl;

$stmt_selesai = $pdo->query("SELECT COUNT(*) as ttl FROM tbl_pengajuan WHERE status='selesai'");
$tot_selesai = $stmt_selesai->fetch()->ttl;
?>

<div class="content-wrapper">
    <div class="content-header">
        <div class="container-fluid">
            <h1 class="m-0">Dashboard Utama</h1>
        </div>
    </div>

    <section class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-4 col-6">
                    <div class="small-box bg-info">
                        <div class="inner">
                            <h3><?= $tot_all ?></h3>
                            <p>Total Pengajuan</p>
                        </div>
                        <div class="icon">
                            <i class="fas fa-envelope"></i>
                        </div>
                    </div>
                </div>
                <div class="col-lg-4 col-6">
                    <div class="small-box bg-secondary">
                        <div class="inner">
                            <h3><?= $tot_diterima ?></h3>
                            <p>Pengajuan Diterima</p>
                        </div>
                        <div class="icon">
                            <i class="fas fa-inbox"></i>
                        </div>
                    </div>
                </div>
                <div class="col-lg-4 col-6">
                    <div class="small-box bg-primary">
                        <div class="inner">
                            <h3><?= $tot_diverifikasi ?></h3>
                            <p>Telah Diverifikasi</p>
                        </div>
                        <div class="icon">
                            <i class="fas fa-user-check"></i>
                        </div>
                    </div>
                </div>
                <div class="col-lg-4 col-6">
                    <div class="small-box bg-warning">
                        <div class="inner">
                            <h3><?= $tot_diproses ?></h3>
                            <p>Sedang Diproses</p>
                        </div>
                        <div class="icon">
                            <i class="fas fa-spinner"></i>
                        </div>
                    </div>
                </div>
                <div class="col-lg-4 col-6">
                    <div class="small-box bg-danger">
                        <div class="inner">
                            <h3><?= $tot_ditolak ?></h3>
                            <p>Pengajuan Ditolak</p>
                        </div>
                        <div class="icon">
                            <i class="fas fa-times-circle"></i>
                        </div>
                    </div>
                </div>
                <div class="col-lg-4 col-6">
                    <div class="small-box bg-success">
                        <div class="inner">
                            <h3><?= $tot_selesai ?></h3>
                            <p>Pengajuan Selesai</p>
                        </div>
                        <div class="icon">
                            <i class="fas fa-check-circle"></i>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="row mt-4">
                <div class="col-12">
                    <div class="card">
                        <div class="card-header border-0">
                            <h3 class="card-title">Selamat Datang di Dashboard Aplikasi LENTERA</h3>
                        </div>
                        <div class="card-body">
                            <p>Anda login sebagai <strong><?= htmlspecialchars($_SESSION['nama_lengkap']) ?></strong> (<?= ucfirst($_SESSION['level']) ?>).</p>
                            <p>Silakan gunakan menu di sebelah kiri untuk mengelola data pengajuan dari masyarakat.</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</div>

<?php include 'layout/footer.php'; ?>
