<?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/age-report" style="display:flex;gap:10px;flex-wrap:wrap;align-items:end;">
        <div>
            <label class="form-label" style="font-size:12px;">العمر من</label>
            <input type="number" name="min_age" value="<?= (int) $minAge ?>" min="0" max="120" class="form-input" style="width:80px;">
        </div>
        <div>
            <label class="form-label" style="font-size:12px;">العمر إلى</label>
            <input type="number" name="max_age" value="<?= (int) $maxAge ?>" min="0" max="120" class="form-input" style="width:80px;">
        </div>
        <button type="submit" class="btn btn-outline">تصفية</button>
        <a href="/reports/age-report" class="btn btn-sm btn-outline" style="color:#6B7280;">مسح</a>
    </form>
</div>

<div class="card">
    <div style="padding:15px;border-bottom:1px solid #E5E7EB;">
        <strong>النتائج:</strong> <?= (int) $total ?> عضو بين <?= (int) $minAge ?> و <?= (int) $maxAge ?> سنة
    </div>
    <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 if (empty($members)): ?>
                <tr><td colspan="8" style="text-align:center;padding:30px;color:#6B7280;">لا توجد نتائج</td></tr>
            <?php else: ?>
                <?php foreach ($members as $m): ?>
                <tr>
                    <td><?= e($m['membership_number'] ?? '—') ?></td>
                    <td><a href="/members/<?= (int) $m['id'] ?>"><?= e($m['full_name_ar']) ?></a></td>
                    <td><?= e($m['date_of_birth']) ?></td>
                    <td><?= (int) $m['age'] ?> سنة</td>
                    <td><?= $m['gender'] === 'male' ? 'ذكر' : 'أنثى' ?></td>
                    <td><?= e($m['branch_name'] ?? '—') ?></td>
                    <td>
                        <?php
                        $statusMap = ['active' => 'نشط', 'suspended' => 'موقوف', 'dropped' => 'مسقط', 'frozen' => 'مجمد'];
                        echo e($statusMap[$m['status']] ?? $m['status']);
                        ?>
                    </td>
                    <td style="direction:ltr;text-align:right;"><?= e($m['phone_mobile'] ?? '—') ?></td>
                </tr>
                <?php endforeach; ?>
            <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>

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