<?= $this->extend('admin/layout/main') ?>
<?= $this->section('content') ?>
<h3 class="mb-3">الرسائل الواردة من الموقع</h3>

<div class="card p-3">
<table class="table">
    <thead><tr><th>الاسم</th><th>البريد</th><th>الهاتف</th><th>الرسالة</th><th>التاريخ</th><th><?= lang('App.actions') ?></th></tr></thead>
    <tbody>
    <?php foreach ($messages as $m): ?>
        <tr class="<?= $m['is_read'] ? '' : 'table-warning' ?>">
            <td><?= esc($m['name']) ?></td>
            <td><?= esc($m['email']) ?></td>
            <td><?= esc($m['phone']) ?></td>
            <td class="small"><?= esc(mb_strimwidth($m['message'], 0, 80, '...')) ?></td>
            <td class="small text-muted"><?= esc($m['created_at']) ?></td>
            <td>
                <?php if (!$m['is_read']): ?>
                    <form method="post" action="/admin/contact-messages/<?= $m['id'] ?>/read" class="d-inline">
                        <?= csrf_field() ?><button class="btn btn-sm btn-outline-success">تعليم كمقروءة</button>
                    </form>
                <?php endif; ?>
                <form method="post" action="/admin/contact-messages/<?= $m['id'] ?>/delete" class="d-inline" onsubmit="return confirm('?')">
                    <?= csrf_field() ?><button class="btn btn-sm btn-outline-danger"><?= lang('App.delete') ?></button>
                </form>
            </td>
        </tr>
    <?php endforeach; ?>
    <?php if (empty($messages)): ?><tr><td colspan="6" class="text-center text-muted"><?= lang('App.no_data') ?></td></tr><?php endif; ?>
    </tbody>
</table>
<?= $pager->links() ?>
</div>
<?= $this->endSection() ?>
