<?php
session_start();
if (!isset($_SESSION['admin'])) {
    exit('Admin access required');
}

// Connect to the database
$dbFile = '../chat_history.sqlite';
$db = new SQLite3($dbFile);

// Get total counts
$totalUsers = $db->querySingle("SELECT COUNT(*) FROM users");
$totalProfiles = $db->querySingle("SELECT COUNT(*) FROM profiles");
$totalSessions = $db->querySingle("SELECT COUNT(*) FROM sessions");
?>

<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
    <div class="bg-white rounded-lg shadow-md p-6">
        <h2 class="text-xl font-semibold mb-4">Total Users</h2>
        <p class="text-4xl font-bold text-blue-600"><?php echo $totalUsers; ?></p>
    </div>
    <div class="bg-white rounded-lg shadow-md p-6">
        <h2 class="text-xl font-semibold mb-4">Total Profiles</h2>
        <p class="text-4xl font-bold text-green-600"><?php echo $totalProfiles; ?></p>
    </div>
    <div class="bg-white rounded-lg shadow-md p-6">
        <h2 class="text-xl font-semibold mb-4">Total Sessions</h2>
        <p class="text-4xl font-bold text-purple-600"><?php echo $totalSessions; ?></p>
    </div>
</div>