<?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="/transfers" style="display:flex;gap:10px;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="requested" <?= ($filters['status'] ?? '') === 'requested' ? 'selected' : '' ?>>مقدم</option><option value="approved" <?= ($filters['status'] ?? '') === 'approved' ? 'selected' : '' ?>>معتمد</option><option value="completed" <?= ($filters['status'] ?? '') === 'completed' ? 'selected' : '' ?>>مكتمل</option></select></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><th>الحالة</th><th>التاريخ</th><th>الإجراءات</th></tr></thead><tbody>
<?php foreach ($rows as $r): ?>
<tr>
    <td><?= (int) $r['id'] ?></td>
    <td><a href="/members/<?= (int) $r['source_member_id'] ?>" style="color:#0D7377;font-weight:600;"><?= e($r['member_name'] ?? '') ?></a></td>
    <td style="font-size:13px;"><?= match($r['transfer_type'] ?? '') { 'child_separation' => 'فصل ابن', 'child_mandatory_25' => 'تحويل وجوبي (25)', 'sports_conversion' => 'تحويل رياضي', 'cross_branch' => 'تحويل بين فروع', default => $r['transfer_type'] ?? '' } ?></td>
    <td style="font-weight:600;"><?= money($r['separation_fee'] ?? '0') ?></td>
    <td style="font-weight:600;color:#0D7377;"><?= e($r['new_membership_number'] ?? '—') ?></td>
    <td><span style="color:<?= match($r['status'] ?? '') { 'completed' => '#059669', 'approved' => '#0284C7', default => '#D97706' } ?>;font-weight:600;">● <?= match($r['status'] ?? '') { 'requested' => 'مقدم', 'approved' => 'معتمد', 'completed' => 'مكتمل', 'rejected' => 'مرفوض', default => $r['status'] ?? '' } ?></span></td>
    <td style="font-size:12px;"><?= e(substr($r['created_at'] ?? '', 0, 10)) ?></td>
    <td><a href="/transfers/<?= (int) $r['id'] ?>" class="btn btn-sm btn-outline">عرض</a></td>
</tr>
<?php endforeach; ?>
<?php if (empty($rows)): ?><tr><td colspan="8" style="text-align:center;padding:40px;color:#6B7280;">لا توجد طلبات تحويل</td></tr><?php endif; ?>
</tbody></table></div></div>
<?php $__template->endSection(); ?>