<?php
include 'config.php';

$ticket_id = $_GET['ticket_id'];
$query = "SELECT * FROM support_messages WHERE ticket_id = '$ticket_id' ORDER BY created_at ASC";
$result = mysqli_query($conn, $query);

while($row = mysqli_fetch_assoc($result)) {
    $sender_class = ($row['sender_type'] == 'customer') ? 'customer' : 'admin';
    echo "<div class='msg $sender_class'>";
    
    if(!empty($row['image'])) {
        echo "<img src='uploads/tickets/{$row['image']}' class='img-msg' onclick='previewImage(this.src)'><br>";
    }
    
    echo htmlspecialchars($row['message']);
    echo "<span class='msg-time'>" . date('H:i', strtotime($row['created_at'])) . "</span>";
    echo "</div>";
}
?>