<?php
require_once '../config/database.php';
secureSessionStart();
requireLogin();

$conn = getConnection();
$ticket_id = isset($_GET['ticket_id']) ? intval($_GET['ticket_id']) : 0;

$query = "SELECT COUNT(*) as count 
          FROM support_messages 
          WHERE ticket_id = '$ticket_id' AND sender_type = 'user' AND is_read = 0";
$result = mysqli_query($conn, $query);
$count = mysqli_fetch_assoc($result)['count'];

echo json_encode(['success' => true, 'count' => $count]);
?>