<?php
$children = $children ?? [];
$memberId = $memberId ?? 0;
?>
<?php if (!empty($children)): ?>
<table class="data-table">
    <thead>
        <tr><th>#</th><th>الاسم</th><th>النوع</th><th>القرابة</th><th>تاريخ الميلاد</th><th>السن</th><th>التصنيف</th><th>رسوم</th><th>الحالة</th><th>الإجراءات</th></tr>
    </thead>
    <tbody>
        <?php foreach ($children as $c): ?>
        <tr>
            <td><?= (int) $c['child_order'] ?></td>
            <td><a href="/members/<?= (int) $memberId ?>/children/<?= (int) $c['id'] ?>" style="color:#0D7377;font-weight:600;"><?= e($c['full_name_ar']) ?></a></td>
            <td><?= $c['gender'] === 'male' ? 'ذكر' : 'أنثى' ?></td>
            <td style="font-size:13px;"><?php
                echo match ($c['relationship'] ?? '') {
                    'son' => 'ابن', 'daughter' => 'ابنة', 'stepchild' => 'ابن/ابنة زوج', default => $c['relationship'] ?? ''
                };
            ?></td>
            <td style="font-size:13px;"><?= e($c['date_of_birth']) ?></td>
            <td><?php
                $dob = $c['date_of_birth'] ?? null;
                echo $dob && strtotime($dob) > 0 ? (int) ((time() - strtotime($dob)) / 31557600) : 0;
            ?></td>
            <td style="font-size:12px;"><?php
                echo match ($c['classification'] ?? '') {
                    'included' => '<span style="color:#059669;">مشمول</span>',
                    'dependent_with_fee' => '<span style="color:#D97706;">تابع برسوم</span>',
                    'temporary' => '<span style="color:#0284C7;">مؤقت</span>',
                    'frozen' => '<span style="color:#DC2626;">مجمد</span>',
                    'separated' => '<span style="color:#6B7280;">منفصل</span>',
                    default => e($c['classification'] ?? ''),
                };
            ?></td>
            <td style="font-weight:600;"><?= money($c['addition_fee'] ?? '0') ?></td>
            <td><?php
                $st = $c['status'] ?? '';
                echo match($st) {
                    'active' => '<span style="color:#059669;font-weight:600;">● نشط</span>',
                    'separated' => '<span style="color:#6B7280;font-weight:600;">● منفصل</span>',
                    'frozen' => '<span style="color:#DC2626;font-weight:600;">● مجمد</span>',
                    'pending_payment' => '<span style="color:#D97706;font-weight:600;">● لم يتم السداد</span>',
                    default => '<span style="color:#DC2626;font-weight:600;">● ' . e($st) . '</span>',
                };
            ?></td>
            <td>
                <div style="display:flex;gap:5px;">
                    <a href="/members/<?= (int) $memberId ?>/children/<?= (int) $c['id'] ?>" class="btn btn-sm btn-outline">عرض</a>
                    <?php if (can('child.edit')): ?>
                    <a href="/members/<?= (int) $memberId ?>/children/<?= (int) $c['id'] ?>/edit" class="btn btn-sm btn-outline">تعديل</a>
                    <?php endif; ?>
                </div>
            </td>
        </tr>
        <?php endforeach; ?>
    </tbody>
</table>
<?php else: ?>
<p style="color:#6B7280;text-align:center;padding:20px;">لا يوجد أبناء مسجلون</p>
<?php endif; ?>