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

// Simple admin check
$user_id = $_SESSION['user_id'] ?? 0;
$stmt = db()->prepare("SELECT is_admin FROM users WHERE id = ?");
$stmt->execute([$user_id]);
$u = $stmt->fetch();

if (!$u || !$u['is_admin']) {
    echo json_encode(['error' => 'Unauthorized']);
    exit;
}

// Count pending deposits and unread messages
$stmt = db()->query("SELECT COUNT(*) as cnt FROM deposits WHERE status = 'pending'");
$dep_count = $stmt->fetch()['cnt'];

$stmt = db()->query("SELECT COUNT(*) as cnt FROM chat_messages WHERE admin_id IS NULL AND is_read = 0");
$chat_count = $stmt->fetch()['cnt'];

echo json_encode([
    'success' => true,
    'new_count' => $dep_count + $chat_count,
    'deposits' => $dep_count,
    'chats' => $chat_count
]);
