<?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><?= (int) ($c['age_years'] ?? 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 if ($c['is_frozen'] ?? false): ?>
                    <span style="color:#DC2626;font-weight:600;">● مجمد</span>
                <?php else: ?>
                    <span style="color:<?= ($c['status'] ?? '') === 'active' ? '#059669' : '#DC2626' ?>;font-weight:600;">● <?= ($c['status'] ?? '') === 'active' ? 'نشط' : ($c['status'] ?? '') ?></span>
                <?php endif; ?>
            </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; ?>