<?= $this->extend('layout/main_layout') ?>
<?= $this->section('content') ?>
<div class="container-xxl py-5">
    <div class="container">
        <h1>Sent Messages</h1>
        <?php if (!empty($sentMessages)): ?>
            <div class="table-responsive">
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>To</th>
                            <th>Subject</th>
                            <th>Date</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($sentMessages as $message): ?>
                            <tr>
                                <td><?= esc($message['recipient_id']) ?></td>
                                <td><?= esc($message['subject']) ?></td>
                                <td><?= esc(!empty($message['created_at']) ? local_datetime($message['created_at'], 'm-d-Y H:i') : '') ?></td>
                                <td>
                                    <a href="<?= base_url('messages/view/' . $message['id']) ?>">View</a> |
                                    <a href="<?= base_url('messages/delete/' . $message['id']) ?>">Delete</a>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        <?php else: ?>
            <p>No messages found.</p>
        <?php endif; ?>
    </div>
<?= $this->endSection() ?>
