<?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="/reports/subscription-status" 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="financial_year" value="<?= e($financialYear) ?>" placeholder="2024/2025" class="form-input" style="width:120px;">
        </div>
        <button type="submit" class="btn btn-outline">عرض</button>
    </form>
</div>

<div style="display:grid;grid-template-columns:repeat(auto-fill,minmax(200px,1fr));gap:15px;margin-bottom:20px;">
    <?php
    $statusLabels = ['paid' => 'مدفوع', 'pending' => 'معلق', 'overdue' => 'متأخر', 'partial' => 'جزئي'];
    $statusColors = ['paid' => '#10B981', 'pending' => '#F59E0B', 'overdue' => '#EF4444', 'partial' => '#6366F1'];
    foreach ($summary as $s):
        $label = $statusLabels[$s['status']] ?? $s['status'];
        $color = $statusColors[$s['status']] ?? '#6B7280';
    ?>
    <div class="card" style="padding:15px;border-right:4px solid <?= $color ?>;">
        <div style="font-size:13px;color:#6B7280;"><?= e($label) ?></div>
        <div style="font-size:24px;font-weight:bold;margin:5px 0;"><?= (int) $s['cnt'] ?></div>
        <div style="font-size:12px;color:#6B7280;">
            إجمالي: <?= money($s['total'] ?? '0') ?><br>
            مدفوع: <?= money($s['paid'] ?? '0') ?><br>
            غرامات: <?= money($s['fines'] ?? '0') ?>
        </div>
    </div>
    <?php endforeach; ?>
</div>

<div class="card">
    <div style="padding:15px;border-bottom:1px solid #E5E7EB;">
        <strong>أعلى 100 عضو بمبالغ متأخرة — <?= e($financialYear) ?></strong>
    </div>
    <div class="table-responsive">
        <table class="data-table">
            <thead>
                <tr>
                    <th>رقم العضوية</th>
                    <th>الاسم</th>
                    <th>الهاتف</th>
                    <th>المبلغ المستحق</th>
                </tr>
            </thead>
            <tbody>
            <?php if (empty($unpaidMembers)): ?>
                <tr><td colspan="4" style="text-align:center;padding:30px;color:#6B7280;">لا توجد مبالغ متأخرة</td></tr>
            <?php else: ?>
                <?php foreach ($unpaidMembers as $m): ?>
                <tr>
                    <td><?= e($m['membership_number'] ?? '—') ?></td>
                    <td><a href="/members/<?= (int) $m['id'] ?>"><?= e($m['full_name_ar']) ?></a></td>
                    <td style="direction:ltr;text-align:right;"><?= e($m['phone_mobile'] ?? '—') ?></td>
                    <td style="color:#EF4444;font-weight:bold;"><?= money($m['outstanding'] ?? '0') ?></td>
                </tr>
                <?php endforeach; ?>
            <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>

<?php $__template->endSection(); ?>
