<?php defined('BASEPATH') or exit('No direct script access allowed'); ?>
<?php if (!empty($messages)) { ?>
    <?php foreach ($messages as $message) { ?>
        <?php if ((int) $message->user_id === (int) $this->session->userdata('user_id')) { ?>
            <div class="flex justify-end" data-message-id="<?= (int) $message->private_chat_messages_id ?>">
                <div class="max-w-[72%] space-y-1.5">
                    <div class="rounded-2xl rounded-br-md bg-primary px-3.5 py-2.5 text-sm leading-6 text-white shadow-sm">
                        <?= $message->message ?>
                    </div>
                    <div class="pr-1 text-right text-[10px] text-muted-foreground"><?= time_ago($message->message_time) ?></div>
                </div>
            </div>
        <?php } else { ?>
            <div class="flex items-start gap-3" data-message-id="<?= (int) $message->private_chat_messages_id ?>">
                <img class="mt-0.5 h-8 w-8 rounded-full object-cover ring-1 ring-border" src="<?= base_url(staffImage($message->user_id)) ?>" alt="message user image">
                <div class="max-w-[72%] space-y-1.5">
                    <div class="rounded-2xl rounded-tl-md border border-border bg-card px-3.5 py-2.5 text-sm leading-6 text-foreground shadow-sm dark:border-slate-700">
                        <p class="mb-1 text-[11px] font-semibold uppercase tracking-[0.12em] text-muted-foreground"><?= html_escape(fullname($message->user_id)) ?></p>
                        <div><?= $message->message ?></div>
                    </div>
                    <div class="text-[10px] text-muted-foreground"><?= time_ago($message->message_time) ?></div>
                </div>
            </div>
        <?php } ?>
    <?php } ?>
<?php } ?>
