<?php
include 'config.php';

if (!isset($_GET['ticket_id'])) { exit("No Ticket ID"); }

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

while($row = mysqli_fetch_assoc($result)) {
    $class = ($row['sender_type'] == 'customer') ? 'customer' : 'admin';
    echo '<div class="msg '.$class.'">';
    if(!empty($row['image'])) {
        // تأكد من صحة مسار عرض الصور
        echo '<img src="../../admin/uploads/tickets/'.$row['image'].'" style="max-width:100%; border-radius:5px;"><br>';
    }
    echo htmlspecialchars($row['message']);
    echo '<small style="display:block; font-size:10px; color:#999; margin-top:5px;">'.date('H:i', strtotime($row['created_at'])).'</small>';
    echo '</div>';
}
?>