<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>الاشتراكات السنوية<?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?>
<a href="/subscriptions/batch-generate" class="btn btn-primary">🔄 توليد اشتراكات السنة</a>
<?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<div class="card" style="margin-bottom:20px;padding:15px;">
    <form method="GET" action="/subscriptions" 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><input type="text" name="year" value="<?= e($filters['year'] ?? '') ?>" placeholder="2024/2025" class="form-input" style="width:120px;direction:ltr;text-align:left;"></div>
        <div><label class="form-label" style="font-size:12px;">الحالة</label>
            <select name="status" class="form-select"><option value="">الكل</option><option value="pending" <?= ($filters['status'] ?? '') === 'pending' ? 'selected' : '' ?>>معلق</option><option value="paid" <?= ($filters['status'] ?? '') === 'paid' ? 'selected' : '' ?>>مدفوع</option><option value="overdue" <?= ($filters['status'] ?? '') === 'overdue' ? 'selected' : '' ?>>متأخر</option><option value="exempt" <?= ($filters['status'] ?? '') === 'exempt' ? 'selected' : '' ?>>معفى</option></select></div>
        <button type="submit" class="btn btn-outline">بحث</button>
        <a href="/subscriptions" 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><th>الحالة</th><th>الإجراءات</th></tr></thead><tbody>
<?php foreach ($rows as $r): ?>
<tr>
    <td><a href="/members/<?= (int) $r['member_id'] ?>" style="color:#0D7377;font-weight:600;"><?= e($r['member_name'] ?? '#' . $r['member_id']) ?></a></td>
    <td style="direction:ltr;text-align:right;"><?= e($r['financial_year']) ?></td>
    <td style="font-size:13px;"><?= e($r['person_type']) ?></td>
    <td style="font-size:13px;"><?= e($r['person_name'] ?? '—') ?></td>
    <td style="font-weight:600;"><?= money($r['total_amount']) ?></td>
    <td style="color:#059669;"><?= money($r['paid_amount']) ?></td>
    <td style="color:#DC2626;"><?= bccomp($r['fine_amount'] ?? '0', '0', 2) > 0 ? money($r['fine_amount']) : '—' ?></td>
    <td><span style="color:<?= match($r['status']) { 'paid' => '#059669', 'pending' => '#D97706', 'overdue' => '#DC2626', 'exempt' => '#0284C7', default => '#6B7280' } ?>;font-weight:600;">● <?= match($r['status']) { 'paid' => 'مدفوع', 'pending' => 'معلق', 'overdue' => 'متأخر', 'exempt' => 'معفى', default => $r['status'] } ?></span></td>
    <td>
        <?php if (in_array($r['status'], ['pending', 'overdue'])): ?>
            <a href="/payments/process/<?= (int) $r['member_id'] ?>" class="btn btn-sm btn-primary">دفع</a>
        <?php endif; ?>
    </td>
</tr>
<?php endforeach; ?>
<?php if (empty($rows)): ?><tr><td colspan="9" style="text-align:center;padding:40px;color:#6B7280;">لا توجد اشتراكات</td></tr><?php endif; ?>
</tbody></table></div></div>
<?php $__template->endSection(); ?>