<?php
$db = getDB();
$sliderCount = $db->query("SELECT COUNT(*) FROM sliders")->fetchColumn();
$sectionCount = $db->query("SELECT COUNT(*) FROM sections")->fetchColumn();
$announcementCount = $db->query("SELECT COUNT(*) FROM announcements")->fetchColumn();
$resourceCount = $db->query("SELECT COUNT(*) FROM resources")->fetchColumn();
$facilityCount = $db->query("SELECT COUNT(*) FROM facilities")->fetchColumn();
$serviceCount = $db->query("SELECT COUNT(*) FROM services")->fetchColumn();
$workshopCount = $db->query("SELECT COUNT(*) FROM workshops")->fetchColumn();
$articleCount = $db->query("SELECT COUNT(*) FROM articles")->fetchColumn();
$teamCount = $db->query("SELECT COUNT(*) FROM team_members")->fetchColumn();
$alumniCount = $db->query("SELECT COUNT(*) FROM alumni_team")->fetchColumn();
$galleryCount = $db->query("SELECT COUNT(*) FROM gallery_images")->fetchColumn();
$messageCount = $db->query("SELECT COUNT(*) FROM contact_messages")->fetchColumn();
$registrationCount = $db->query("SELECT COUNT(*) FROM workshop_registrations")->fetchColumn();
$subscriberCount = $db->query("SELECT COUNT(*) FROM newsletter_subscribers WHERE active = TRUE")->fetchColumn();

include __DIR__ . '/admin_header.php';
?>

<div class="admin-topbar">
    <h2><i class="fas fa-tachometer-alt" style="color:var(--accent);margin-right:8px;font-size:22px;"></i> Dashboard</h2>
    <span style="display:flex;align-items:center;gap:8px;">
        <i class="fas fa-user-circle" style="color:var(--accent);"></i>
        Welcome, <strong><?= htmlspecialchars($_SESSION['admin_user'] ?? 'Admin') ?></strong>
    </span>
</div>

<div class="stat-grid">
    <div class="stat-card">
        <div class="number"><?= $serviceCount ?></div>
        <div class="label"><i class="fas fa-flask"></i> Services</div>
    </div>
    <div class="stat-card">
        <div class="number"><?= $workshopCount ?></div>
        <div class="label"><i class="fas fa-chalkboard-teacher"></i> Workshops</div>
    </div>
    <div class="stat-card">
        <div class="number"><?= $articleCount ?></div>
        <div class="label"><i class="fas fa-newspaper"></i> Articles</div>
    </div>
    <div class="stat-card">
        <div class="number"><?= $sectionCount ?></div>
        <div class="label"><i class="fas fa-th-large"></i> Sections</div>
    </div>
    <div class="stat-card">
        <div class="number"><?= $teamCount ?></div>
        <div class="label"><i class="fas fa-users"></i> Team Members</div>
    </div>
    <div class="stat-card">
        <div class="number"><?= $alumniCount ?></div>
        <div class="label"><i class="fas fa-user-graduate"></i> Alumni</div>
    </div>
    <div class="stat-card">
        <div class="number"><?= $galleryCount ?></div>
        <div class="label"><i class="fas fa-camera"></i> Gallery Photos</div>
    </div>
    <div class="stat-card">
        <div class="number"><?= $sliderCount ?></div>
        <div class="label"><i class="fas fa-photo-video"></i> Sliders</div>
    </div>
    <div class="stat-card">
        <div class="number"><?= $messageCount ?></div>
        <div class="label"><i class="fas fa-envelope"></i> Messages</div>
    </div>
    <div class="stat-card">
        <div class="number"><?= $registrationCount ?></div>
        <div class="label"><i class="fas fa-clipboard-list"></i> Registrations</div>
    </div>
    <div class="stat-card">
        <div class="number"><?= $subscriberCount ?></div>
        <div class="label"><i class="fas fa-envelope-open-text"></i> Subscribers</div>
    </div>
</div>

<div class="admin-card">
    <h3><i class="fas fa-bolt"></i> Quick Actions</h3>
    <div class="quick-actions">
        <a href="/admin/services" class="btn-sm btn-sm-primary"><i class="fas fa-flask"></i> Services</a>
        <a href="/admin/workshops" class="btn-sm btn-sm-primary"><i class="fas fa-chalkboard-teacher"></i> Workshops</a>
        <a href="/admin/articles" class="btn-sm btn-sm-primary"><i class="fas fa-newspaper"></i> Articles</a>
        <a href="/admin/team" class="btn-sm btn-sm-primary"><i class="fas fa-users"></i> Team</a>
        <a href="/admin/gallery" class="btn-sm btn-sm-primary"><i class="fas fa-camera"></i> Gallery</a>
        <a href="/admin/sliders" class="btn-sm btn-sm-warning"><i class="fas fa-images"></i> Sliders</a>
        <a href="/admin/menu" class="btn-sm btn-sm-warning"><i class="fas fa-bars"></i> Menu Builder</a>
        <a href="/admin/users" class="btn-sm btn-sm-outline"><i class="fas fa-user-shield"></i> Users & Roles</a>
        <a href="/admin/settings" class="btn-sm btn-sm-outline"><i class="fas fa-cog"></i> Settings</a>
        <a href="/admin/seo" class="btn-sm btn-sm-outline"><i class="fas fa-search"></i> SEO</a>
        <a href="/" target="_blank" class="btn-sm btn-sm-success"><i class="fas fa-external-link-alt"></i> View Website</a>
    </div>
</div>

<?php include __DIR__ . '/admin_footer.php'; ?>
