<?php $__template->layout('Layout.main'); ?>
<?php $__template->section('title'); ?>بيانات الابن: <?= e($child->full_name_ar) ?><?php $__template->endSection(); ?>
<?php $__template->section('page_actions'); ?>
<?php if (can('child.edit')): ?>
<a href="/members/<?= (int) $member['id'] ?>/children/<?= (int) $child->id ?>/edit" class="btn btn-outline">تعديل</a>
<?php endif; ?>
<a href="/members/<?= (int) $member['id'] ?>" class="btn btn-outline">← العودة للعضو</a>
<?php $__template->endSection(); ?>
<?php $__template->section('content'); ?>
<div style="display:grid;grid-template-columns:1fr 1fr;gap:20px;">
    <div class="card" style="padding:20px;">
        <h4 style="color:#1e3a5f;margin-bottom:15px;">البيانات الشخصية</h4>
        <table style="width:100%;font-size:14px;">
            <tr><td style="padding:6px 0;color:#6B7280;width:40%;">الاسم</td><td style="padding:6px 0;font-weight:600;"><?= e($child->full_name_ar) ?></td></tr>
            <tr><td style="padding:6px 0;color:#6B7280;">الرقم القومي</td><td style="padding:6px 0;direction:ltr;text-align:right;"><?= e($child->national_id ?: '—') ?></td></tr>
            <tr><td style="padding:6px 0;color:#6B7280;">شهادة الميلاد</td><td style="padding:6px 0;"><?= e($child->birth_certificate_number ?: '—') ?></td></tr>
            <tr><td style="padding:6px 0;color:#6B7280;">تاريخ الميلاد</td><td style="padding:6px 0;"><?= e($child->date_of_birth) ?></td></tr>
            <tr><td style="padding:6px 0;color:#6B7280;">السن</td><td style="padding:6px 0;"><?php
                $cDob = $child->date_of_birth ?? null;
                $cAgeY = 0; $cAgeM = 0;
                if ($cDob && strtotime($cDob) > 0) {
                    $d = (new \DateTime($cDob))->diff(new \DateTime());
                    $cAgeY = $d->y; $cAgeM = $d->m;
                }
                echo $cAgeY . ' سنة' . ($cAgeM ? ' و ' . $cAgeM . ' شهر' : '');
            ?></td></tr>
            <tr><td style="padding:6px 0;color:#6B7280;">النوع</td><td style="padding:6px 0;"><?= $child->gender === 'male' ? 'ذكر' : 'أنثى' ?></td></tr>
            <tr><td style="padding:6px 0;color:#6B7280;">نوع القرابة</td><td style="padding:6px 0;"><?= e($child->getRelationshipLabel()) ?></td></tr>
            <tr><td style="padding:6px 0;color:#6B7280;">الكلية / المدرسة</td><td style="padding:6px 0;"><?= e($child->school_faculty ?: '—') ?></td></tr>
        </table>
    </div>
    <div class="card" style="padding:20px;">
        <h4 style="color:#1e3a5f;margin-bottom:15px;">بيانات العضوية</h4>
        <table style="width:100%;font-size:14px;">
            <tr><td style="padding:6px 0;color:#6B7280;width:40%;">الترتيب</td><td style="padding:6px 0;font-weight:600;">#<?= (int) $child->child_order ?></td></tr>
            <tr><td style="padding:6px 0;color:#6B7280;">التصنيف</td><td style="padding:6px 0;"><?= e($child->getClassificationLabel()) ?></td></tr>
            <tr><td style="padding:6px 0;color:#6B7280;">الحالة</td><td style="padding:6px 0;color:<?= $child->status === 'active' ? '#059669' : '#DC2626' ?>;font-weight:600;">● <?= e($child->getStatusLabel()) ?></td></tr>
            <?php if ($child->is_frozen): ?>
            <tr><td style="padding:6px 0;color:#6B7280;">مجمد منذ</td><td style="padding:6px 0;color:#DC2626;"><?= e($child->frozen_at ?? '—') ?></td></tr>
            <tr><td style="padding:6px 0;color:#6B7280;">سبب التجميد</td><td style="padding:6px 0;"><?= e($child->frozen_reason ?? '—') ?></td></tr>
            <?php endif; ?>
            <tr><td style="padding:6px 0;color:#6B7280;">رسوم الإضافة</td><td style="padding:6px 0;font-weight:700;color:#1e3a5f;"><?= money($child->addition_fee) ?></td></tr>
            <tr><td style="padding:6px 0;color:#6B7280;">رقم الإيصال</td><td style="padding:6px 0;"><?= e($child->fee_receipt_number ?: '—') ?></td></tr>
        </table>

        <?php if ($child->status === 'active' && !$child->is_frozen && $cAgeY >= 25): ?>
        <?php if (can('child.freeze')): ?>
        <div style="margin-top:20px;padding:15px;background:#FEF2F2;border:1px solid #FECACA;border-radius:8px;">
            <strong style="color:#DC2626;">⚠ هذا الابن بلغ سن 25 ويجب تجميد عضويته</strong>
            <form method="POST" action="/members/<?= (int) $member['id'] ?>/children/<?= (int) $child->id ?>/freeze" style="margin-top:10px;">
                <?= csrf_field() ?>
                <input type="hidden" name="freeze_reason" value="بلوغ سن 25">
                <button type="submit" class="btn btn-sm" style="background:#DC2626;color:#fff;border:none;padding:8px 16px;border-radius:6px;cursor:pointer;">تجميد العضوية</button>
            </form>
        </div>
        <?php endif; ?>
        <?php endif; ?>

        <?php if ($child->remarks): ?>
        <div style="margin-top:15px;"><h4 style="color:#6B7280;font-size:13px;">ملاحظات</h4><p style="font-size:14px;"><?= nl2br(e($child->remarks)) ?></p></div>
        <?php endif; ?>
    </div>
</div>
<?php $__template->endSection(); ?>