<?php
// get all message by private chat id
$messages = array();
if (!empty($all_messages)) {
    foreach ($all_messages as $message) {
        array_push($messages, $message);
    }
    foreach ($all_messages as $message) : ?>
        <?php if ($message->user_id == $this->session->userdata('user_id')) { ?>
            <div class="flex justify-end">
                <div class="max-w-[75%] space-y-1">
                    <div class="rounded-2xl rounded-tr-sm bg-indigo-600 text-white px-3 py-2 text-sm">
                        <?php echo $message->message ?>
                    </div>
                    <div class="text-[10px] text-muted-foreground text-right"><?= time_ago($message->message_time); ?></div>
                </div>
            </div>
        <?php } else { ?>
            <div class="flex items-start gap-2">
                <img class="h-8 w-8 rounded-full object-cover"
                     src="<?= base_url(staffImage($message->user_id)) ?>"
                     alt="message user image"/>
                <div class="max-w-[75%] space-y-1">
                    <div class="rounded-2xl rounded-tl-sm bg-muted/60 text-foreground px-3 py-2 text-sm">
                        <?php echo $message->message ?>
                    </div>
                    <div class="text-[10px] text-muted-foreground"><?= time_ago($message->message_time); ?></div>
                </div>
            </div>
        <?php } ?>
    <?php endforeach;
}
?>
