<?php
/**
 * admin_support_ajax.php - للتحديث التلقائي للرسائل
 */

require_once 'config.php';
checkAdminAuth();

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

if (isset($_GET['ticket_id'])) {
    $ticket_id = (int)$_GET['ticket_id'];
    
    // التحقق من وجود رسائل جديدة
    $result = $conn->query("
        SELECT COUNT(*) as new_count 
        FROM ticket_messages 
        WHERE ticket_id = $ticket_id 
          AND sender_type = 'customer' 
          AND is_read = 0
    ");
    
    $new_count = $result->fetch_assoc()['new_count'];
    
    echo json_encode([
        'new_messages' => $new_count > 0,
        'count' => $new_count
    ]);
    exit;
}

echo json_encode(['error' => 'Invalid request']);