<?php
/**
 * get_category_stats.php - جلب إحصائيات التصنيف
 */

include 'config.php';
checkAdminAuth();

header('Content-Type: application/json');

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;

if ($id > 0) {
    $stats = $conn->query("
        SELECT 
            COUNT(*) as total_meals,
            SUM(CASE WHEN is_active = 1 THEN 1 ELSE 0 END) as active_meals,
            SUM(has_portions) as meals_with_portions,
            MIN(price) as min_price,
            MAX(price) as max_price
        FROM meals 
        WHERE category_id = '$id'
    ")->fetch_assoc();
    
    echo json_encode($stats);
} else {
    echo json_encode(['total_meals' => 0]);
}
?>