<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>اشتراكات العضو: <?= e($member['full_name_ar']) ?><?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?><a href="/members/<?= (int) $member['id'] ?>" class="btn btn-outline">← العودة للعضو</a><?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>

<?php if ($lateFine['should_drop']): ?>
<div style="padding:15px;background:#FEF2F2;border:2px solid #DC2626;border-radius:8px;margin-bottom:20px;color:#DC2626;font-weight:600;">
    ⚠ هذا العضو متأخر <?= (int) $lateFine['years_unpaid'] ?> سنوات — يجب إسقاط العضوية
</div>
<?php elseif (!empty($lateFine['details'])): ?>
<div style="padding:15px;background:#FFF7ED;border:1px solid #FED7AA;border-radius:8px;margin-bottom:20px;">
    <strong style="color:#D97706;">غرامات تأخير: <?= money($lateFine['total_fine']) ?></strong> — <?= (int) $lateFine['years_unpaid'] ?> سنة متأخرة
</div>
<?php endif; ?>

<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 ($subscriptions as $s): ?>
<tr>
    <td style="font-weight:600;"><?= e($s['financial_year']) ?></td>
    <td><?= match($s['person_type']) { 'member' => 'عضو', 'spouse' => 'زوجة', 'child' => 'ابن', 'temporary' => 'مؤقت', default => $s['person_type'] } ?></td>
    <td style="font-size:13px;"><?= e($s['person_name'] ?? '—') ?></td>
    <td><?= money($s['base_amount']) ?></td>
    <td style="font-size:12px;"><?= money($s['development_fee']) ?></td>
    <td style="color:#DC2626;"><?= bccomp($s['fine_amount'] ?? '0', '0', 2) > 0 ? money($s['fine_amount']) : '—' ?></td>
    <td style="color:#059669;"><?= bccomp($s['paid_amount'] ?? '0', '0', 2) > 0 ? money($s['paid_amount']) : '—' ?></td>
    <td><span style="color:<?= match($s['status']) { 'paid' => '#059669', 'exempt' => '#0284C7', 'overdue' => '#DC2626', default => '#D97706' } ?>;font-weight:600;">● <?= match($s['status']) { 'paid' => 'مدفوع', 'pending' => 'معلق', 'overdue' => 'متأخر', 'exempt' => 'معفى', default => $s['status'] } ?></span></td>
    <td>
        <?php if (in_array($s['status'], ['pending', 'overdue'])): ?>
        <div style="display:flex;gap:5px;">
            <form method="POST" action="/subscriptions/<?= (int) $s['id'] ?>/pay" style="display:inline;"><?= csrf_field() ?><input type="hidden" name="payment_method" value="cash"><button type="submit" class="btn btn-sm btn-primary" onclick="return confirm('تسجيل دفع الاشتراك؟')">دفع</button></form>
            <form method="POST" action="/subscriptions/<?= (int) $s['id'] ?>/exempt" style="display:inline;"><?= csrf_field() ?><input type="hidden" name="exemption_reason" value="قرار مجلس"><button type="submit" class="btn btn-sm btn-outline" onclick="return confirm('إعفاء من الاشتراك؟')">إعفاء</button></form>
        </div>
        <?php else: ?>—<?php endif; ?>
    </td>
</tr>
<?php endforeach; ?>
<?php if (empty($subscriptions)): ?><tr><td colspan="9" style="text-align:center;padding:30px;color:#6B7280;">لا توجد اشتراكات</td></tr><?php endif; ?>
</tbody></table></div></div>
<?php $__template->endSection(); ?>