<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>إدارة المستندات<?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?>
<div style="padding:8px 16px;background:#EFF6FF;border:1px solid #BFDBFE;border-radius:6px;font-size:13px;color:#0284C7;">
    💡 لرفع مستندات، اذهب لصفحة العضو واختر "📁 رفع مستندات"
</div>
<?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<div class="card" style="margin-bottom:20px;padding:15px;">
    <form method="GET" action="/documents" 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'] ?? '') ?>" placeholder="اسم العضو، اسم الملف..." class="form-input" style="min-width:200px;"></div>
        <div><label class="form-label" style="font-size:12px;">نوع المستند</label>
            <select name="document_type" class="form-select">
                <option value="">الكل</option>
                <?php foreach ($docTypes as $code => $label): ?>
                    <option value="<?= e($code) ?>" <?= ($filters['document_type'] ?? '') === $code ? 'selected' : '' ?>><?= e($label) ?></option>
                <?php endforeach; ?>
            </select>
        </div>
        <button type="submit" class="btn btn-outline">بحث</button>
        <a href="/documents" class="btn btn-sm btn-outline" style="color:#6B7280;">مسح</a>
    </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><th>بواسطة</th><th>الإجراءات</th></tr></thead><tbody>
<?php foreach ($rows as $r): ?>
<tr>
    <td><a href="/members/<?= (int) $r['member_id'] ?>" style="color:#1e3a5f;font-weight:600;"><?= e($r['member_name'] ?? '') ?></a></td>
    <td style="font-size:13px;"><?= e(\App\Modules\Documents\Models\Document::getTypeLabel($r['document_type'])) ?></td>
    <td style="font-size:12px;max-width:200px;overflow:hidden;text-overflow:ellipsis;"><?= e($r['original_filename']) ?></td>
    <td style="font-size:12px;"><?= round(($r['file_size'] ?? 0) / 1024) ?> KB</td>
    <td style="font-size:12px;"><?= e(substr($r['uploaded_at'] ?? '', 0, 16)) ?></td>
    <td style="font-size:13px;"><?= e($r['uploaded_by_name'] ?? '—') ?></td>
    <td>
        <div style="display:flex;gap:5px;">
            <a href="/documents/<?= (int) $r['id'] ?>/preview" class="btn btn-sm btn-outline" target="_blank">معاينة</a>
            <a href="/documents/<?= (int) $r['id'] ?>/download" class="btn btn-sm btn-outline">تحميل</a>
        </div>
    </td>
</tr>
<?php endforeach; ?>
<?php if (empty($rows)): ?><tr><td colspan="7" style="text-align:center;padding:40px;color:#6B7280;">لا توجد مستندات</td></tr><?php endif; ?>
</tbody></table></div></div>
<?php $__template->endSection(); ?>