<?php
require_once(__DIR__ . '/../json_db.php');
session_start();
header('Content-Type: application/json');

try {
    $db = $jsonDB->getPDO();
    $today = date('Y-m-d');
    
    // عدد الزوار الكلي
    $stmt = $db->query('SELECT COUNT(*) as cnt FROM visits');
    $totalVisitors = (int) $stmt->fetch(PDO::FETCH_ASSOC)['cnt'];
    
    // عدد زوار اليوم
    $stmt = $db->prepare('SELECT COUNT(*) as cnt FROM visits WHERE date = :today');
    $stmt->execute([':today' => $today]);
    $todayCount = (int) $stmt->fetch(PDO::FETCH_ASSOC)['cnt'];
    
    echo json_encode([
        'total' => $totalVisitors,
        'today' => $todayCount
    ]);
} catch (PDOException $e) {
    echo json_encode([
        'total' => 0,
        'today' => 0
    ]);
}
