<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>سجل الرسائل النصية<?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<div class="card" style="margin-bottom:20px;padding:15px;">
    <form method="GET" action="/notifications/log" style="display:flex;gap:10px;flex-wrap:wrap;align-items:end;">
        <div><label class="form-label" style="font-size:12px;">بحث</label><input type="text" name="q" value="<?= e($filters['search'] ?? '') ?>" class="form-input" style="min-width:200px;" placeholder="رقم الهاتف، نص الرسالة..."></div>
        <div><label class="form-label" style="font-size:12px;">الحالة</label><select name="status" class="form-select"><option value="">الكل</option><option value="sent" <?= ($filters['status'] ?? '') === 'sent' ? 'selected' : '' ?>>مرسل</option><option value="queued" <?= ($filters['status'] ?? '') === 'queued' ? 'selected' : '' ?>>في الانتظار</option><option value="failed" <?= ($filters['status'] ?? '') === 'failed' ? 'selected' : '' ?>>فشل</option></select></div>
        <div><label class="form-label" style="font-size:12px;">من</label><input type="date" name="date_from" value="<?= e($filters['date_from'] ?? '') ?>" class="form-input"></div>
        <div><label class="form-label" style="font-size:12px;">إلى</label><input type="date" name="date_to" value="<?= e($filters['date_to'] ?? '') ?>" class="form-input"></div>
        <button type="submit" class="btn btn-outline">بحث</button>
    </form>
</div>
<div class="card"><div class="table-responsive"><table class="data-table"><thead><tr><th>التاريخ</th><th>العضو</th><th>الهاتف</th><th>الرسالة</th><th>الحالة</th></tr></thead><tbody>
<?php foreach ($rows as $r): ?>
<tr>
    <td style="font-size:12px;white-space:nowrap;"><?= e($r['created_at']) ?></td>
    <td style="font-size:13px;"><?= e($r['member_name'] ?? '—') ?></td>
    <td style="direction:ltr;text-align:right;font-size:13px;"><?= e($r['phone_number']) ?></td>
    <td style="font-size:12px;max-width:300px;overflow:hidden;text-overflow:ellipsis;"><?= e(mb_substr($r['message_text'], 0, 80)) ?></td>
    <td><span style="color:<?= match($r['status']) { 'sent' => '#059669', 'queued' => '#D97706', 'failed' => '#DC2626', default => '#6B7280' } ?>;font-weight:600;">● <?= match($r['status']) { 'sent' => 'مرسل', 'queued' => 'انتظار', 'failed' => 'فشل', 'delivered' => 'مُستلم', default => $r['status'] } ?></span></td>
</tr>
<?php endforeach; ?>
<?php if (empty($rows)): ?><tr><td colspan="5" style="text-align:center;padding:40px;color:#6B7280;">لا توجد رسائل</td></tr><?php endif; ?>
</tbody></table></div></div>
<?php $__template->endSection(); ?>