<?php
session_start();
require_once '../config.php';

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

// Statistik Sederhana
$balita = $pdo->query("SELECT COUNT(*) FROM balita")->fetchColumn() ?: 0;
$bumil  = $pdo->query("SELECT COUNT(*) FROM ibu_hamil")->fetchColumn() ?: 0;
$lansia = $pdo->query("SELECT COUNT(*) FROM lansia")->fetchColumn() ?: 0;
?>

<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dashboard Admin</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        .hover-shadow { transition: 0.3s; }
        .hover-shadow:hover { transform: translateY(-5px); box-shadow: 0 10px 20px rgba(0,0,0,0.1) !important; }
    </style>
</head>
<body>

<?php include 'sidebar.php'; ?>

<div class="main-content">
    <div class="container-fluid">
        <h3 class="fw-bold mb-4">Ringkasan Data Master</h3>
        
        <div class="row g-3 mb-5">
            <div class="col-12 col-sm-6 col-md-4">
                <div class="card border-0 shadow-sm p-4 bg-primary text-white rounded-4 h-100">
                    <div class="d-flex justify-content-between align-items-center">
                        <div><p class="mb-1">Total Balita</p><h2 class="fw-bold mb-0"><?=$balita?></h2></div>
                        <i class="fa fa-child fa-3x opacity-50"></i>
                    </div>
                </div>
            </div>
            <div class="col-12 col-sm-6 col-md-4">
                <div class="card border-0 shadow-sm p-4 bg-danger text-white rounded-4 h-100">
                    <div class="d-flex justify-content-between align-items-center">
                        <div><p class="mb-1">Total Bumil</p><h2 class="fw-bold mb-0"><?=$bumil?></h2></div>
                        <i class="fa fa-female fa-3x opacity-50"></i>
                    </div>
                </div>
            </div>
            <div class="col-12 col-sm-6 col-md-4">
                <div class="card border-0 shadow-sm p-4 bg-success text-white rounded-4 h-100">
                    <div class="d-flex justify-content-between align-items-center">
                        <div><p class="mb-1">Total Lansia</p><h2 class="fw-bold mb-0"><?=$lansia?></h2></div>
                        <i class="fa fa-blind fa-3x opacity-50"></i>
                    </div>
                </div>
            </div>
        </div>

        <h4 class="fw-bold mb-3">Akses Laporan Terpadu</h4>
        <div class="row g-3 text-center">
            <div class="col-12 col-md-4">
                <a href="rekap_balita.php" class="text-decoration-none text-dark">
                    <div class="card border-0 shadow-sm p-4 h-100 hover-shadow rounded-4">
                        <i class="fa fa-file-alt fa-3x text-primary mb-3"></i>
                        <h5 class="fw-bold">Laporan Balita</h5>
                    </div>
                </a>
            </div>
            <div class="col-12 col-md-4">
                <a href="rekap_bumil.php" class="text-decoration-none text-dark">
                    <div class="card border-0 shadow-sm p-4 h-100 hover-shadow rounded-4">
                        <i class="fa fa-file-medical fa-3x text-danger mb-3"></i>
                        <h5 class="fw-bold">Laporan Bumil</h5>
                    </div>
                </a>
            </div>
            <div class="col-12 col-md-4">
                <a href="rekap_lansia.php" class="text-decoration-none text-dark">
                    <div class="card border-0 shadow-sm p-4 h-100 hover-shadow rounded-4">
                        <i class="fa fa-heartbeat fa-3x text-success mb-3"></i>
                        <h5 class="fw-bold">Laporan Lansia</h5>
                    </div>
                </a>
            </div>
        </div>
    </div>
</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>