<?php
/**
 * Admin Dashboard
 * PHP User Registration - https://rskworld.in
 * Developer: Molla Samser | RSK World
 * Contact: help@rskworld.in | +91 93305 39277
 * Year: 2026
 */

require_once __DIR__ . '/../includes/init.php';

requireAdmin();
$baseHref = '..';

$pdo = getDbConnection();
$userCount = (int) $pdo->query('SELECT COUNT(*) FROM users')->fetchColumn();
$unverifiedCount = 0;
try {
    $unverifiedCount = (int) $pdo->query('SELECT COUNT(*) FROM users WHERE email_verified = 0')->fetchColumn();
} catch (PDOException $e) { /* column may not exist */ }
$msgCount = 0;
try {
    $msgCount = (int) $pdo->query('SELECT COUNT(*) FROM contact_messages')->fetchColumn();
} catch (PDOException $e) {
    // table may not exist yet
}

$pageTitle = 'Admin Dashboard';
require_once __DIR__ . '/../includes/header.php';
?>

<div class="page-content admin-content">
    <h1><i class="fas fa-cog"></i> Admin Dashboard</h1>
    <p class="subtitle">PHP User Registration — <a href="https://rskworld.in" target="_blank">rskworld.in</a></p>

    <div class="admin-cards">
        <a href="users.php" class="admin-card">
            <span class="admin-card-number"><?= $userCount ?></span>
            <span class="admin-card-label">Users</span>
        </a>
        <a href="users.php" class="admin-card <?= $unverifiedCount > 0 ? 'admin-card-warning' : '' ?>">
            <span class="admin-card-number"><?= $unverifiedCount ?></span>
            <span class="admin-card-label">Unverified</span>
        </a>
        <a href="messages.php" class="admin-card">
            <span class="admin-card-number"><?= $msgCount ?></span>
            <span class="admin-card-label">Contact Messages</span>
        </a>
        <a href="failed-logins.php" class="admin-card">
            <span class="admin-card-number"><?php try { echo (int) $pdo->query('SELECT COUNT(*) FROM failed_login_attempts')->fetchColumn(); } catch (PDOException $e) { echo '0'; } ?></span>
            <span class="admin-card-label">Failed Logins</span>
        </a>
        <a href="activity.php" class="admin-card">
            <span class="admin-card-label"><i class="fas fa-history"></i> Activity Log</span>
        </a>
    </div>
    <p><a href="../dashboard.php" class="btn btn-secondary">Back to Dashboard</a></p>
</div>

<?php require_once __DIR__ . '/../includes/footer.php'; ?>
